Skip to content

Commit a243b1a

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add list and delete authorizations for oauth commands"
2 parents ce72256 + 6146213 commit a243b1a

2 files changed

Lines changed: 94 additions & 7 deletions

File tree

openstackclient/identity/v3/oauth.py

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
class AuthenticateAccessToken(show.ShowOne):
29-
"""Authenticate access token - receive keystone token"""
29+
"""Authenticate access token to receive keystone token"""
3030

3131
api = 'identity'
3232
log = logging.getLogger(__name__ + '.AuthenticateAccessToken')
@@ -233,6 +233,36 @@ def take_action(self, parsed_args):
233233
return
234234

235235

236+
class DeleteUserAuthorization(command.Command):
237+
"""Delete user authorization command"""
238+
239+
log = logging.getLogger(__name__ + '.DeleteUserAuthorization')
240+
241+
def get_parser(self, prog_name):
242+
parser = super(DeleteUserAuthorization, self).get_parser(prog_name)
243+
parser.add_argument(
244+
'user',
245+
metavar='<user>',
246+
help='Name or Id of user',
247+
)
248+
parser.add_argument(
249+
'access_id',
250+
metavar='<access-id>',
251+
help='Access Id to be deleted',
252+
)
253+
return parser
254+
255+
def take_action(self, parsed_args):
256+
self.log.debug('take_action(%s)' % parsed_args)
257+
258+
identity_client = self.app.client_manager.identity
259+
user = utils.find_resource(
260+
identity_client.users, parsed_args.user).id
261+
identity_client.oauth.delete_authorization(user,
262+
parsed_args.access_id)
263+
return
264+
265+
236266
class ListConsumer(lister.Lister):
237267
"""List consumer command"""
238268

@@ -249,6 +279,37 @@ def take_action(self, parsed_args):
249279
) for s in data))
250280

251281

282+
class ListUserAuthorizations(lister.Lister):
283+
"""List user authorizations command"""
284+
285+
log = logging.getLogger(__name__ + '.ListUserAuthorizations')
286+
287+
def get_parser(self, prog_name):
288+
parser = super(ListUserAuthorizations, self).get_parser(prog_name)
289+
parser.add_argument(
290+
'user',
291+
metavar='<user>',
292+
help='Name or Id of user',
293+
)
294+
return parser
295+
296+
def take_action(self, parsed_args):
297+
self.log.debug('take_action(%s)' % parsed_args)
298+
299+
identity_client = self.app.client_manager.identity
300+
user = utils.find_resource(
301+
identity_client.users, parsed_args.user).id
302+
303+
columns = ('Access Key', 'Consumer Key', 'Issued At',
304+
'Project Id', 'User Id', 'Requested Roles')
305+
data = identity_client.oauth.list_authorizations(user)
306+
return (columns,
307+
(utils.get_item_properties(
308+
s, columns,
309+
formatters={},
310+
) for s in data))
311+
312+
252313
class SetConsumer(command.Command):
253314
"""Set consumer command"""
254315

@@ -284,6 +345,30 @@ def take_action(self, parsed_args):
284345
return
285346

286347

348+
class ShowAuthorizationPin(show.ShowOne):
349+
"""Show Authorization pin command"""
350+
351+
log = logging.getLogger(__name__ + '.ShowAuthorizationPin')
352+
353+
def get_parser(self, prog_name):
354+
parser = super(ShowAuthorizationPin, self).get_parser(prog_name)
355+
parser.add_argument(
356+
'request_id',
357+
metavar='<request-id>',
358+
help='Show pin for request token',
359+
)
360+
return parser
361+
362+
def take_action(self, parsed_args):
363+
self.log.debug('take_action(%s)' % parsed_args)
364+
identity_client = self.app.client_manager.identity
365+
data = identity_client.oauth.get_authorization_pin(
366+
parsed_args.request_id)
367+
info = {}
368+
info.update(data._info)
369+
return zip(*sorted(info.iteritems()))
370+
371+
287372
class ShowConsumer(show.ShowOne):
288373
"""Show consumer command"""
289374

setup.cfg

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ openstack.identity.v2_0 =
7272
user_show = openstackclient.identity.v2_0.user:ShowUser
7373

7474
openstack.identity.v3 =
75-
access_token_authenticate = openstackclient.identity.v3.oauth:AuthenticateAccessToken
76-
access_token_create = openstackclient.identity.v3.oauth:CreateAccessToken
77-
7875
consumer_create = openstackclient.identity.v3.oauth:CreateConsumer
7976
consumer_delete = openstackclient.identity.v3.oauth:DeleteConsumer
8077
consumer_list = openstackclient.identity.v3.oauth:ListConsumer
@@ -108,6 +105,14 @@ openstack.identity.v3 =
108105
group_set = openstackclient.identity.v3.group:SetGroup
109106
group_show = openstackclient.identity.v3.group:ShowGroup
110107

108+
oauth_access_token_authenticate = openstackclient.identity.v3.oauth:AuthenticateAccessToken
109+
oauth_access_token_create = openstackclient.identity.v3.oauth:CreateAccessToken
110+
oauth_request_token_authorize = openstackclient.identity.v3.oauth:AuthorizeRequestToken
111+
oauth_request_token_create = openstackclient.identity.v3.oauth:CreateRequestToken
112+
oauth_authorization_delete = openstackclient.identity.v3.oauth:DeleteUserAuthorization
113+
oauth_authorization_list = openstackclient.identity.v3.oauth:ListUserAuthorizations
114+
oauth_authorization_show = openstackclient.identity.v3.oauth:ShowAuthorizationPin
115+
111116
policy_create = openstackclient.identity.v3.policy:CreatePolicy
112117
policy_delete = openstackclient.identity.v3.policy:DeletePolicy
113118
policy_list = openstackclient.identity.v3.policy:ListPolicy
@@ -120,9 +125,6 @@ openstack.identity.v3 =
120125
project_set = openstackclient.identity.v3.project:SetProject
121126
project_show = openstackclient.identity.v3.project:ShowProject
122127

123-
request_token_authorize = openstackclient.identity.v3.oauth:AuthorizeRequestToken
124-
request_token_create = openstackclient.identity.v3.oauth:CreateRequestToken
125-
126128
role_add = openstackclient.identity.v3.role:AddRole
127129
role_create = openstackclient.identity.v3.role:CreateRole
128130
role_delete = openstackclient.identity.v3.role:DeleteRole

0 commit comments

Comments
 (0)