Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple VOs in a single tenant #329

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions cloud-info/cloud_info_catchall/share_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ def __init__(self, config, secret):
def build_share(self, project, access_token):
return {"auth": {"project_id": project["id"]}}

def get_project_vo(self, project):
def get_project_vos(self, project):
if not project.get("enabled", False):
logging.warning(
f"Discarding project {project['name']} as it is not enabled"
)
return None
return []
vo = project.get("egi.VO", None)
if not vo:
vo = project.get("VO", None)
if not vo:
logging.warning(
f"Discarding project {project['name']} as it does not have VO property"
)
return vo
return []
return vo.split(",")

def get_token_shares(self):
access_token = self.get_token()
Expand All @@ -47,10 +48,8 @@ def get_token_shares(self):
return shares
projects = fedcli.get_projects_from_single_site(self.auth_url, token)
for p in projects:
vo = self.get_project_vo(p)
if not vo:
continue
shares[vo] = self.build_share(p, access_token)
for vo in self.get_project_vos(p):
shares[vo.strip()] = self.build_share(p, access_token)
self.config_shares(shares, access_token)
return shares

Expand Down
12 changes: 8 additions & 4 deletions cloud-info/cloud_info_catchall/test_share_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_get_project_vo_disabled(self):
"name": "foo.eu",
"VO": "foo",
}
self.assertEqual(self.discoverer.get_project_vo(p), None)
self.assertEqual(self.discoverer.get_project_vos(p), [])

def test_get_project_vo_egi_property(self):
p = {
Expand All @@ -40,22 +40,26 @@ def test_get_project_vo_egi_property(self):
"VO": "bar",
"egi.VO": "foo",
}
self.assertEqual(self.discoverer.get_project_vo(p), "foo")
self.assertEqual(self.discoverer.get_project_vos(p), ["foo"])

def test_get_project_vo_property(self):
p = {
"enabled": True,
"name": "foo.eu",
"VO": "bar",
}
self.assertEqual(self.discoverer.get_project_vo(p), "bar")
self.assertEqual(self.discoverer.get_project_vos(p), ["bar"])

def test_get_project_no_vo_property(self):
p = {
"enabled": True,
"name": "foo.eu",
}
self.assertEqual(self.discoverer.get_project_vo(p), None)
self.assertEqual(self.discoverer.get_project_vos(p), [])

def test_get_project_multiple_vo_property(self):
p = {"enabled": True, "name": "foo.eu", "egi.VO": "foo,bar"}
self.assertEqual(self.discoverer.get_project_vos(p), ["foo", "bar"])

@patch("fedcloudclient.endpoint.get_projects_from_single_site")
@patch("fedcloudclient.endpoint.retrieve_unscoped_token")
Expand Down