Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Commits
892c32ea
Commit
892c32ea
authored
1 year ago
by
Neda Moeini
Browse files
Options
Downloads
Patches
Plain Diff
Added token to url when authetication is enabled.
parent
5dcb98a6
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!142
Added middleware to modify porecess details response and replace the callback...
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gso/api/v1/processes.py
+4
-2
4 additions, 2 deletions
gso/api/v1/processes.py
gso/middlewares.py
+24
-4
24 additions, 4 deletions
gso/middlewares.py
with
28 additions
and
6 deletions
gso/api/v1/processes.py
+
4
−
2
View file @
892c32ea
...
...
@@ -3,11 +3,13 @@
from
typing
import
Any
from
uuid
import
UUID
from
fastapi
import
APIRouter
,
HTTPException
,
status
from
fastapi
import
APIRouter
,
HTTPException
,
status
,
Depends
from
orchestrator.db
import
ProcessStepTable
from
orchestrator.schemas.base
import
OrchestratorBaseModel
router
=
APIRouter
(
prefix
=
"
/processes
"
,
tags
=
[
"
Processes
"
])
from
gso.auth.security
import
opa_security_default
router
=
APIRouter
(
prefix
=
"
/processes
"
,
tags
=
[
"
Processes
"
],
dependencies
=
[
Depends
(
opa_security_default
)])
class
CallBackResultsBaseModel
(
OrchestratorBaseModel
):
...
...
This diff is collapsed.
Click to expand it.
gso/middlewares.py
+
24
−
4
View file @
892c32ea
...
...
@@ -38,7 +38,7 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
response_body
+=
chunk
try
:
json_content
=
json
.
loads
(
response_body
)
self
.
modify_response_body
(
json_content
,
request
)
await
self
.
modify_response_body
(
json_content
,
request
)
modified_response_body
=
json
.
dumps
(
json_content
).
encode
()
headers
=
dict
(
response
.
headers
)
headers
[
"
content-length
"
]
=
str
(
len
(
modified_response_body
))
...
...
@@ -55,7 +55,26 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
return
response
@staticmethod
def
modify_response_body
(
response_body
:
dict
[
str
,
Any
],
request
:
Request
)
->
None
:
async
def
_get_token
(
request
:
Request
)
->
str
:
"""
Get the token from the request headers.
Args:
----
request (Request): The incoming HTTP request.
Returns:
-------
str: The token from the request headers in specific format.
"""
bearer_prefix
=
"
Bearer
"
authorization_header
=
request
.
headers
.
get
(
"
Authorization
"
)
if
authorization_header
:
# Remove the "Bearer " prefix from the token
token
=
authorization_header
.
replace
(
bearer_prefix
,
""
)
return
f
"
?token=
{
token
}
"
else
:
return
""
async
def
modify_response_body
(
self
,
response_body
:
dict
[
str
,
Any
],
request
:
Request
)
->
None
:
"""
Modify the response body as needed.
Args:
...
...
@@ -63,7 +82,8 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
response_body (Dict[str, Any]): The response body in dictionary format.
request (Request): The incoming HTTP request.
"""
max_output_length
=
1000
max_output_length
=
500
token
=
await
self
.
_get_token
(
request
)
try
:
for
step
in
response_body
[
"
steps
"
]:
if
step
[
"
state
"
].
get
(
"
callback_result
"
,
None
):
...
...
@@ -73,7 +93,7 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
if
callback_result
.
get
(
"
output
"
)
and
len
(
callback_result
[
"
output
"
])
>
max_output_length
:
callback_result
[
"
output
"
]
=
f
'
{
request
.
base_url
}
api/v1/processes/steps/
{
step
[
"
step_id
"
]
}
/callback-results
/
'
]
=
f
'
{
request
.
base_url
}
api/v1/processes/steps/
{
step
[
"
step_id
"
]
}
/callback-results
{
token
}
'
step
[
"
state
"
][
"
callback_result
"
]
=
callback_result
except
(
AttributeError
,
KeyError
,
TypeError
):
pass
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment