Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dinamis-sdk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CDOS-Pub
dinamis-sdk
Commits
540d585a
Commit
540d585a
authored
2 weeks ago
by
Pablo Boizeau
Browse files
Options
Downloads
Patches
Plain Diff
Move get_userinfo to connectionmethod
parent
c6407391
No related branches found
Branches containing commit
No related tags found
1 merge request
!41
Draft: Add userinfo feature and code coverage
Pipeline
#300509
passed
2 weeks ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dinamis_sdk/http.py
+13
-9
13 additions, 9 deletions
dinamis_sdk/http.py
tests/test_misc.py
+1
-1
1 addition, 1 deletion
tests/test_misc.py
with
14 additions
and
10 deletions
dinamis_sdk/http.py
+
13
−
9
View file @
540d585a
...
...
@@ -40,6 +40,14 @@ class OAuth2ConnectionMethod(BareConnectionMethod):
"""
Return the headers.
"""
return
{
"
authorization
"
:
f
"
bearer
{
self
.
oauth2_session
.
get_access_token
()
}
"
}
def
get_userinfo
(
self
):
"""
Get the userinfo endpoint.
"""
openapi_url
=
retrieve_token_endpoint
().
replace
(
"
/token
"
,
"
/userinfo
"
)
_session
=
create_session
()
headers
=
OAuth2ConnectionMethod
().
get_headers
()
return
_session
.
get
(
openapi_url
,
timeout
=
10
,
headers
=
headers
).
json
()
class
ApiKeyConnectionMethod
(
BareConnectionMethod
):
"""
API key connection method.
"""
...
...
@@ -50,6 +58,10 @@ class ApiKeyConnectionMethod(BareConnectionMethod):
"""
Return the headers.
"""
return
self
.
api_key
.
to_dict
()
def
get_userinfo
(
self
):
"""
User info method for API key. Not available.
"""
raise
NotImplementedError
(
"
No userinfo available with API key method.
"
)
class
HTTPSession
:
"""
HTTP session class.
"""
...
...
@@ -75,14 +87,6 @@ class HTTPSession:
self
.
prepare_connection_method
()
return
self
.
_method
def
get_userinfo
(
self
):
"""
Get the userinfo endpoint.
"""
openapi_url
=
retrieve_token_endpoint
().
replace
(
"
/token
"
,
"
/userinfo
"
)
_session
=
create_session
()
headers
=
OAuth2ConnectionMethod
().
get_headers
()
return
_session
.
get
(
openapi_url
,
timeout
=
10
,
headers
=
headers
).
json
()
def
prepare_connection_method
(
self
):
"""
Set the connection method.
"""
# Custom server without authentication method
...
...
@@ -125,4 +129,4 @@ def get_headers() -> dict[str, Any]:
def
get_userinfo
()
->
dict
[
str
,
str
]:
"""
Return userinfo.
"""
return
session
.
get_userinfo
()
return
OAuth2ConnectionMethod
()
.
get_userinfo
()
This diff is collapsed.
Click to expand it.
tests/test_misc.py
+
1
−
1
View file @
540d585a
...
...
@@ -5,7 +5,7 @@ import dinamis_sdk
def
test_userinfo
():
"""
Test userinfo method.
"""
dinamis_sdk
.
get_userinfo
()
print
(
dinamis_sdk
.
get_userinfo
()
)
test_userinfo
()
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