Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
balancer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b538c179
authored
Mar 23, 2023
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete and terraform supp
parent
1bbd6872
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
balancer/util.py
+16
-4
main.py
+11
-2
No files found.
balancer/util.py
View file @
b538c179
...
...
@@ -6,19 +6,27 @@ import json
def
proxy_datacenters
(
serverpath
:
str
,
username
,
method
=
"GET"
,
body
=
""
,
balancer_fun
=
rr_get
serverpath
:
str
,
username
,
method
=
"GET"
,
body
=
""
,
balancer_fun
=
rr_get
,
datacenter
=
None
,
):
if
"datacenter"
in
body
:
server
=
body
[
"datacenter"
]
elif
datacenter
:
server
=
datacenter
else
:
server
=
balancer_fun
()
token
=
get_datacenter_token
(
username
,
server
)
print
(
token
)
url
=
f
"{server}/{serverpath}"
t_resp
=
requests
.
request
(
json
=
body
,
method
=
method
,
url
=
url
,
allow_redirects
=
Fals
e
,
allow_redirects
=
Tru
e
,
verify
=
False
,
headers
=
{
"Authorization"
:
token
},
)
...
...
@@ -27,6 +35,10 @@ def proxy_datacenters(
status_code
=
t_resp
.
status_code
,
detail
=
"Remote server error"
)
obj
=
json
.
loads
(
t_resp
.
content
)
obj
[
0
][
"datacenter"
]
=
server
response
=
ORJSONResponse
(
obj
[
0
],
status_code
=
t_resp
.
status_code
)
if
type
(
obj
)
is
list
:
for
o
in
obj
:
o
[
"datacenter"
]
=
server
else
:
obj
[
"datacenter"
]
=
server
response
=
ORJSONResponse
(
obj
,
status_code
=
t_resp
.
status_code
)
return
response
main.py
View file @
b538c179
...
...
@@ -46,8 +46,17 @@ async def user_login(user: UserLoginSchema = Body(...)):
@app.get
(
"/lb/{server_path:path}"
)
def
proxy_get
(
server_path
:
str
=
"/"
,
username
=
Depends
(
get_current_user
),
body
=
Body
()):
return
proxy_datacenters
(
server_path
,
username
,
body
=
body
)
def
proxy_get
(
server_path
:
str
=
"/"
,
username
=
Depends
(
get_current_user
),
datacenter
:
str
=
""
):
return
proxy_datacenters
(
server_path
,
username
,
body
=
""
,
datacenter
=
datacenter
)
@app.delete
(
"/lb/{server_path:path}"
)
def
proxy_delete
(
server_path
:
str
=
"/"
,
username
=
Depends
(
get_current_user
),
body
=
Body
()
):
return
proxy_datacenters
(
server_path
,
username
,
body
=
body
,
method
=
"DELETE"
)
@app.post
(
"/lb/rr/{server_path:path}"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment