Skip to content

Commit

Permalink
Add scitokens issuer info to the namespaces info in the namespaces JS…
Browse files Browse the repository at this point in the history
…ON (SOFTWARE-5768)
  • Loading branch information
matyasselmeci committed Nov 21, 2023
1 parent c254722 commit 6f7bafa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/stashcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,13 @@ def get_credential_generation_dict_for_namespace(ns: Namespace) -> Optional[Dict
return info


def get_scitokens_list_for_namespace(ns: Namespace) -> List[Dict]:
"""Return the list of scitokens issuer info for the .namespaces[*].scitokens attribute in the namespaces JSON"""
return [a.get_namespaces_scitokens_block()
for a in ns.authz_list
if isinstance(a, SciTokenAuth)]


def get_namespaces_info(global_data: GlobalData) -> PreJSON:
"""Return data for the /stashcache/namespaces JSON endpoint.
Expand Down Expand Up @@ -564,6 +571,7 @@ def _namespace_dict(ns: Namespace):
"caches": [],
"origins": [],
"credential_generation": get_credential_generation_dict_for_namespace(ns),
"scitokens": get_scitokens_list_for_namespace(ns),
}

for cache_name, cache_resource_obj in cache_resource_objs.items():
Expand Down
12 changes: 12 additions & 0 deletions src/webapp/data_federation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import urllib
import urllib.parse
from collections import OrderedDict
Expand Down Expand Up @@ -25,6 +26,8 @@ def get_scitokens_conf_block(self, service_name: str):
def get_grid_mapfile_line(self):
return ""

def get_namespaces_scitokens_block(self):
return {}

class NullAuth(AuthMethod):
pass
Expand Down Expand Up @@ -100,6 +103,15 @@ def get_scitokens_conf_block(self, service_name: str):

return block

def get_namespaces_scitokens_block(self):
basepath = re.split(r"\s*,\s*", self.base_path)
restrictedpath = re.split(r"\s*,\s*", self.restricted_path) if self.restricted_path else []
return {
"issuer": self.issuer,
"basepath": basepath,
"restrictedpath": restrictedpath,
}


# TODO Use a dataclass (https://docs.python.org/3.9/library/dataclasses.html)
# once we can ditch Python 3.6; the webapp no longer supports 3.6 but some of
Expand Down

0 comments on commit 6f7bafa

Please sign in to comment.