From 6146213e327729a2a48a09de35087ca2be9786e5 Mon Sep 17 00:00:00 2001 From: Steve Martinelli Date: Tue, 16 Jul 2013 13:52:59 -0500 Subject: [PATCH] Add list and delete authorizations for oauth commands * List user authorizations * Delete user authorization * Grouped the commands with oauth prefix Change-Id: I032ffa25181aad0fb4689f69cdca5a7adc6e29f1 --- openstackclient/identity/v3/oauth.py | 87 +++++++++++++++++++++++++++- setup.cfg | 14 +++-- 2 files changed, 94 insertions(+), 7 deletions(-) diff --git a/openstackclient/identity/v3/oauth.py b/openstackclient/identity/v3/oauth.py index b8f01e6458..bcbbdf7e09 100644 --- a/openstackclient/identity/v3/oauth.py +++ b/openstackclient/identity/v3/oauth.py @@ -26,7 +26,7 @@ from openstackclient.common import utils class AuthenticateAccessToken(show.ShowOne): - """Authenticate access token - receive keystone token""" + """Authenticate access token to receive keystone token""" api = 'identity' log = logging.getLogger(__name__ + '.AuthenticateAccessToken') @@ -233,6 +233,36 @@ class DeleteConsumer(command.Command): return +class DeleteUserAuthorization(command.Command): + """Delete user authorization command""" + + log = logging.getLogger(__name__ + '.DeleteUserAuthorization') + + def get_parser(self, prog_name): + parser = super(DeleteUserAuthorization, self).get_parser(prog_name) + parser.add_argument( + 'user', + metavar='', + help='Name or Id of user', + ) + parser.add_argument( + 'access_id', + metavar='', + help='Access Id to be deleted', + ) + return parser + + def take_action(self, parsed_args): + self.log.debug('take_action(%s)' % parsed_args) + + identity_client = self.app.client_manager.identity + user = utils.find_resource( + identity_client.users, parsed_args.user).id + identity_client.oauth.delete_authorization(user, + parsed_args.access_id) + return + + class ListConsumer(lister.Lister): """List consumer command""" @@ -249,6 +279,37 @@ class ListConsumer(lister.Lister): ) for s in data)) +class ListUserAuthorizations(lister.Lister): + """List user authorizations command""" + + log = logging.getLogger(__name__ + '.ListUserAuthorizations') + + def get_parser(self, prog_name): + parser = super(ListUserAuthorizations, self).get_parser(prog_name) + parser.add_argument( + 'user', + metavar='', + help='Name or Id of user', + ) + return parser + + def take_action(self, parsed_args): + self.log.debug('take_action(%s)' % parsed_args) + + identity_client = self.app.client_manager.identity + user = utils.find_resource( + identity_client.users, parsed_args.user).id + + columns = ('Access Key', 'Consumer Key', 'Issued At', + 'Project Id', 'User Id', 'Requested Roles') + data = identity_client.oauth.list_authorizations(user) + return (columns, + (utils.get_item_properties( + s, columns, + formatters={}, + ) for s in data)) + + class SetConsumer(command.Command): """Set consumer command""" @@ -284,6 +345,30 @@ class SetConsumer(command.Command): return +class ShowAuthorizationPin(show.ShowOne): + """Show Authorization pin command""" + + log = logging.getLogger(__name__ + '.ShowAuthorizationPin') + + def get_parser(self, prog_name): + parser = super(ShowAuthorizationPin, self).get_parser(prog_name) + parser.add_argument( + 'request_id', + metavar='', + help='Show pin for request token', + ) + return parser + + def take_action(self, parsed_args): + self.log.debug('take_action(%s)' % parsed_args) + identity_client = self.app.client_manager.identity + data = identity_client.oauth.get_authorization_pin( + parsed_args.request_id) + info = {} + info.update(data._info) + return zip(*sorted(info.iteritems())) + + class ShowConsumer(show.ShowOne): """Show consumer command""" diff --git a/setup.cfg b/setup.cfg index 2aae47df48..7447dbc50c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -69,9 +69,6 @@ openstack.identity.v2_0 = user_show = openstackclient.identity.v2_0.user:ShowUser openstack.identity.v3 = - access_token_authenticate = openstackclient.identity.v3.oauth:AuthenticateAccessToken - access_token_create = openstackclient.identity.v3.oauth:CreateAccessToken - consumer_create = openstackclient.identity.v3.oauth:CreateConsumer consumer_delete = openstackclient.identity.v3.oauth:DeleteConsumer consumer_list = openstackclient.identity.v3.oauth:ListConsumer @@ -105,6 +102,14 @@ openstack.identity.v3 = group_set = openstackclient.identity.v3.group:SetGroup group_show = openstackclient.identity.v3.group:ShowGroup + oauth_access_token_authenticate = openstackclient.identity.v3.oauth:AuthenticateAccessToken + oauth_access_token_create = openstackclient.identity.v3.oauth:CreateAccessToken + oauth_request_token_authorize = openstackclient.identity.v3.oauth:AuthorizeRequestToken + oauth_request_token_create = openstackclient.identity.v3.oauth:CreateRequestToken + oauth_authorization_delete = openstackclient.identity.v3.oauth:DeleteUserAuthorization + oauth_authorization_list = openstackclient.identity.v3.oauth:ListUserAuthorizations + oauth_authorization_show = openstackclient.identity.v3.oauth:ShowAuthorizationPin + policy_create = openstackclient.identity.v3.policy:CreatePolicy policy_delete = openstackclient.identity.v3.policy:DeletePolicy policy_list = openstackclient.identity.v3.policy:ListPolicy @@ -117,9 +122,6 @@ openstack.identity.v3 = project_set = openstackclient.identity.v3.project:SetProject project_show = openstackclient.identity.v3.project:ShowProject - request_token_authorize = openstackclient.identity.v3.oauth:AuthorizeRequestToken - request_token_create = openstackclient.identity.v3.oauth:CreateRequestToken - role_add = openstackclient.identity.v3.role:AddRole role_create = openstackclient.identity.v3.role:CreateRole role_delete = openstackclient.identity.v3.role:DeleteRole