Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jupyterhub-outpostspawner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
jupyterjsc
packages
jupyterhub-outpostspawner
Commits
5cd6ffb7
Commit
5cd6ffb7
authored
4 months ago
by
Tim Kreuzer
Browse files
Options
Downloads
Patches
Plain Diff
improved flavor handling for user specific flavors
parent
d3fd8638
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
outpostspawner/api_flavors_update.py
+142
-74
142 additions, 74 deletions
outpostspawner/api_flavors_update.py
with
142 additions
and
74 deletions
outpostspawner/api_flavors_update.py
+
142
−
74
View file @
5cd6ffb7
...
...
@@ -15,12 +15,78 @@ from .misc import Thread
_outpost_flavors_cache
=
{}
async
def
get_user_specific_flavors
(
log
,
user_specific_flavor_systems
=
{}):
# This function can be used in authenticator.post_auth_hook to add user specific flavors
# Systems may have user specific flavors
# If that's the case we will send a request to the outpost, to
# receive the allowed flavors for this specific user
# user_specific_flavor_systems = {
# "system_name": {
# "url": "http://outpost.svc:8000/flavors",
# "body": ... # dict containing information that should be used by the Outpost
# "headers": ... # dict used for authenticating
# "request_kwargs": ... # optional, default: request_timeout: 2
# }
# }
ret
=
_outpost_flavors_cache
tasks
=
[]
http_client
=
AsyncHTTPClient
(
force_instance
=
True
,
defaults
=
dict
(
validate_cert
=
False
)
)
system_names
=
[]
for
system_name
,
system_infos
in
user_specific_flavor_systems
.
items
():
url
=
system_infos
.
get
(
"
url
"
,
"
No Url configured
"
)
headers
=
system_infos
.
get
(
"
headers
"
,
{})
body
=
system_infos
.
get
(
"
body
"
,
{})
log
.
info
(
f
"
OutpostFlavors user specific - Retrieve flavors from
{
system_name
}
/
{
url
}
"
)
request_kwargs
=
{
"
request_timeout
"
:
2
}
request_kwargs
.
update
(
system_infos
.
get
(
"
request_kwargs
"
,
{}))
req
=
HTTPRequest
(
url
,
method
=
"
POST
"
,
headers
=
headers
,
body
=
json
.
dumps
(
body
),
**
request_kwargs
,
)
tasks
.
append
(
http_client
.
fetch
(
req
,
raise_error
=
False
))
system_names
.
append
(
system_name
)
try
:
results
=
await
asyncio
.
gather
(
*
tasks
,
return_exceptions
=
True
)
names_results
=
list
(
zip
(
system_names
,
results
))
for
name_result
in
names_results
:
try
:
if
name_result
[
1
].
code
==
200
:
log
.
debug
(
f
"
OutpostFlavors user specific -
{
name_result
[
0
]
}
successful
"
)
result_json
=
json
.
loads
(
name_result
[
1
].
body
)
ret
[
name_result
[
0
]]
=
result_json
else
:
log
.
warning
(
f
"
OutpostFlavors user specific -
{
name_result
[
0
]
}
- Answered with
{
name_result
[
1
].
code
}
(
{
name_result
[
1
]
}
)
"
)
except
:
log
.
exception
(
f
"
OutpostFlavors user specific -
{
name_result
.
get
(
0
,
'
unknown
'
)
}
Could not load result into json
"
)
except
:
log
.
exception
(
"
OutpostFlavors user specific - Could not load get flavors
"
)
return
ret
async
def
async_get_flavors
(
log
,
user
=
None
):
global
_outpost_flavors_cache
if
not
_outpost_flavors_cache
:
try
:
initial_system_names
=
os
.
environ
.
get
(
"
OUTPOST_FLAVOR_INITIAL_SYSTEM_NAMES
"
,
""
)
initial_system_urls
=
os
.
environ
.
get
(
"
OUTPOST_FLAVOR_INITIAL_SYSTEM_URLS
"
,
""
)
initial_system_names
=
os
.
environ
.
get
(
"
OUTPOST_FLAVOR_INITIAL_SYSTEM_NAMES
"
,
""
)
initial_system_urls
=
os
.
environ
.
get
(
"
OUTPOST_FLAVOR_INITIAL_SYSTEM_URLS
"
,
""
)
initial_system_tokens
=
os
.
environ
.
get
(
"
OUTPOST_FLAVOR_INITIAL_SYSTEM_TOKENS
"
,
""
)
...
...
@@ -40,7 +106,9 @@ async def async_get_flavors(log, user=None):
if
system_name
not
in
_outpost_flavors_cache
.
keys
():
initial_system_names_list
.
append
(
system_name
)
initial_system_urls_list
.
append
(
initial_system_urls_list_all
[
i
])
initial_system_tokens_list
.
append
(
initial_system_tokens_list_all
[
i
])
initial_system_tokens_list
.
append
(
initial_system_tokens_list_all
[
i
]
)
i
+=
1
# If systems are left without successful initial check, try to reach the Outpost
...
...
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