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

fix: do not assume admin privileges on keystone #138

Merged
merged 1 commit into from
Sep 28, 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
28 changes: 24 additions & 4 deletions caso/extract/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from caso import keystone_client
from caso import loading

from keystoneauth1.exceptions.catalog import EmptyCatalog
from keystoneauth1.exceptions.http import Forbidden

cli_opts = [
cfg.ListOpt(
"projects",
Expand Down Expand Up @@ -119,12 +122,20 @@
def projects(self):
"""Get list of configured projects."""
projects = CONF.projects
aux = [i.id for i in self.keystone.projects.list(tags=CONF.caso_tag)]
aux = []
try:
aux = [i.id for i in self.keystone.projects.list(tags=CONF.caso_tag)]
except Forbidden as e:
LOG.warning(f"Unable to get projects from Keystone, ignoring - {e}")

Check warning on line 129 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L128-L129

Added lines #L128 - L129 were not covered by tests
return set(projects + aux)

def _get_keystone_client(self):
def _get_keystone_client(self, project=None, system_scope="all"):
"""Get a Keystone Client to get the projects that we will use."""
client = keystone_client.get_client(CONF, system_scope="all")
if project:
system_scope = None
client = keystone_client.get_client(

Check warning on line 136 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L135-L136

Added lines #L135 - L136 were not covered by tests
CONF, project=project, system_scope=system_scope
)
return client

def get_lastrun(self, project):
Expand Down Expand Up @@ -197,7 +208,16 @@

def get_project_vo(self, project_id):
"""Get the VO where the project should be mapped."""
project = self.keystone.projects.get(project_id)
try:
project = self.keystone.projects.get(project_id)
except (EmptyCatalog, Forbidden):

Check warning on line 213 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L213

Added line #L213 was not covered by tests
# we may need scoping here, retrying
LOG.warning(

Check warning on line 215 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L215

Added line #L215 was not covered by tests
f"Scoping the keystone client to the current project {project_id}"
)
self.keystone = self._get_keystone_client(project_id)
project = self.keystone.projects.get(project_id)

Check warning on line 219 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L218-L219

Added lines #L218 - L219 were not covered by tests

project.get()
vo = project.to_dict().get(CONF.vo_property, None)
if vo is None:
Expand Down
4 changes: 3 additions & 1 deletion caso/extract/openstack/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@

def _get_keystone_client(self):
"""Get a Keystone Client for the configured project in the object."""
client = keystone_client.get_client(CONF, system_scope="all")
client = keystone_client.get_client(

Check warning on line 95 in caso/extract/openstack/base.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/openstack/base.py#L95

Added line #L95 was not covered by tests
CONF, project=self.project, system_scope="all"
)
return client

def _get_cinder_client(self):
Expand Down
Loading