diff options
Diffstat (limited to 'openstackclient/identity')
| -rw-r--r-- | openstackclient/identity/common.py | 21 | ||||
| -rw-r--r-- | openstackclient/identity/v3/project.py | 18 |
2 files changed, 27 insertions, 12 deletions
diff --git a/openstackclient/identity/common.py b/openstackclient/identity/common.py index 6aeaa3c3..48dc0c89 100644 --- a/openstackclient/identity/common.py +++ b/openstackclient/identity/common.py @@ -16,6 +16,7 @@ """Common identity code""" from keystoneclient import exceptions as identity_exc +from keystoneclient.v3 import domains from openstackclient.common import exceptions from openstackclient.common import utils @@ -36,3 +37,23 @@ def find_service(identity_client, name_type_or_id): msg = ("No service with a type, name or ID of '%s' exists." % name_type_or_id) raise exceptions.CommandError(msg) + + +def find_domain(identity_client, name_or_id): + """Find a domain. + + If the user does not have permssions to access the v3 domain API, + assume that domain given is the id rather than the name. This + method is used by the project list command, so errors access the + domain will be ignored and if the user has access to the project + API, everything will work fine. + + Closes bugs #1317478 and #1317485. + """ + try: + dom = utils.find_resource(identity_client.domains, name_or_id) + if dom is not None: + return dom + except identity_exc.Forbidden: + pass + return domains.Domain(None, {'id': name_or_id}) diff --git a/openstackclient/identity/v3/project.py b/openstackclient/identity/v3/project.py index 00a98d19..fa935f0b 100644 --- a/openstackclient/identity/v3/project.py +++ b/openstackclient/identity/v3/project.py @@ -24,6 +24,7 @@ from cliff import show from openstackclient.common import parseractions from openstackclient.common import utils +from openstackclient.identity import common class CreateProject(show.ShowOne): @@ -73,10 +74,7 @@ class CreateProject(show.ShowOne): identity_client = self.app.client_manager.identity if parsed_args.domain: - domain = utils.find_resource( - identity_client.domains, - parsed_args.domain, - ).id + domain = common.find_domain(identity_client, parsed_args.domain).id else: domain = None @@ -156,10 +154,8 @@ class ListProject(lister.Lister): columns = ('ID', 'Name') kwargs = {} if parsed_args.domain: - kwargs['domain'] = utils.find_resource( - identity_client.domains, - parsed_args.domain, - ).id + domain = common.find_domain(identity_client, parsed_args.domain) + kwargs['domain'] = domain.id data = identity_client.projects.list(**kwargs) return (columns, (utils.get_item_properties( @@ -236,10 +232,8 @@ class SetProject(command.Command): if parsed_args.name: kwargs['name'] = parsed_args.name if parsed_args.domain: - kwargs['domain'] = utils.find_resource( - identity_client.domains, - parsed_args.domain, - ).id + domain = common.find_domain(identity_client, parsed_args.domain) + kwargs['domain'] = domain.id if parsed_args.description: kwargs['description'] = parsed_args.description if parsed_args.enable: |
