Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Feb 12, 2025
1 parent 1472435 commit aee3dff
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def get_scoped_token(
token_endpoint = f"http://{conda_store_url}/conda-store/api/v1/token/"
http = urllib3.PoolManager()

# add default role bindings
role_bindings = {
"role_bindings": {
f"{name}/*": ["viewer"],
Expand All @@ -68,16 +69,19 @@ def get_scoped_token(
}
}

# add role bindings for all the groups the user is part of
if groups is not None:
for group in groups:
group = group.replace("/", "")
role_bindings["role_bindings"][f"{group}/*"] = ["viewer"]

# if the user is an admin, they can view all namespace + environments
if admin:
role_bindings["role_bindings"]["*/*"] = ["viewer"]

encoded_body = json.dumps(role_bindings)

# generate a token with with the generated role bindings
token_response = http.request(
"POST",
str(token_endpoint),
Expand All @@ -96,7 +100,6 @@ def get_scoped_token(
# for a demo on one approach to adding test.
def get_conda_store_environments(user_info: dict):
import os

import urllib3

# Check for the environment variable `CONDA_STORE_API_PAGE_SIZE_LIMIT`. Fall
Expand All @@ -114,8 +117,10 @@ def get_conda_store_environments(user_info: dict):
groups = user_info["groups"]
name = user_info["name"]
admin = user_info["admin"]
# get token with appropriate scope for the user making the request
scoped_token = get_scoped_token(external_url, token, name, groups, admin)

# get total number of records from the endpoint
total_records = get_total_records(base_url, scoped_token)

# will contain all the environment info returned from the api
Expand Down

0 comments on commit aee3dff

Please sign in to comment.