From 686a26973809eaba3deb9aed63daddba3bb0521e Mon Sep 17 00:00:00 2001 From: lin-hua-cheng Date: Tue, 9 Feb 2016 16:49:11 -0800 Subject: [PATCH] Add "token revoke" for identity v3 Change-Id: Ie631600d02942fe6ce035f31af46abe44e543631 Closes-bug: #1543226 --- doc/source/command-objects/token.rst | 2 -- openstackclient/identity/v3/token.py | 19 +++++++++++++++++ openstackclient/tests/identity/v3/fakes.py | 2 ++ .../tests/identity/v3/test_token.py | 21 +++++++++++++++++++ .../notes/bug-1543226-7d885ecaa3715415.yaml | 5 +++++ setup.cfg | 1 + 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/bug-1543226-7d885ecaa3715415.yaml diff --git a/doc/source/command-objects/token.rst b/doc/source/command-objects/token.rst index 22260f0dec..5e7c7b2686 100644 --- a/doc/source/command-objects/token.rst +++ b/doc/source/command-objects/token.rst @@ -17,8 +17,6 @@ Issue new token token revoke ------------ -*Identity version 2 only.* - Revoke existing token .. program:: token revoke diff --git a/openstackclient/identity/v3/token.py b/openstackclient/identity/v3/token.py index 588c5218ff..9ebd17995a 100644 --- a/openstackclient/identity/v3/token.py +++ b/openstackclient/identity/v3/token.py @@ -173,3 +173,22 @@ class IssueToken(command.ShowOne): if 'tenant_id' in token: token['project_id'] = token.pop('tenant_id') return zip(*sorted(six.iteritems(token))) + + +class RevokeToken(command.Command): + """Revoke existing token""" + + def get_parser(self, prog_name): + parser = super(RevokeToken, self).get_parser(prog_name) + parser.add_argument( + 'token', + metavar='', + help='Token to be deleted', + ) + return parser + + def take_action(self, parsed_args): + identity_client = self.app.client_manager.identity + + identity_client.tokens.revoke_token(parsed_args.token) + return diff --git a/openstackclient/tests/identity/v3/fakes.py b/openstackclient/tests/identity/v3/fakes.py index 9fe341ed6a..d0a2ef53d2 100644 --- a/openstackclient/tests/identity/v3/fakes.py +++ b/openstackclient/tests/identity/v3/fakes.py @@ -420,6 +420,8 @@ class FakeIdentityv3Client(object): self.session = mock.Mock() self.session.auth.auth_ref.service_catalog.resource_class = \ fakes.FakeResource(None, {}) + self.tokens = mock.Mock() + self.tokens.resource_class = fakes.FakeResource(None, {}) self.trusts = mock.Mock() self.trusts.resource_class = fakes.FakeResource(None, {}) self.users = mock.Mock() diff --git a/openstackclient/tests/identity/v3/test_token.py b/openstackclient/tests/identity/v3/test_token.py index 6ad4845da7..192d71ee12 100644 --- a/openstackclient/tests/identity/v3/test_token.py +++ b/openstackclient/tests/identity/v3/test_token.py @@ -80,3 +80,24 @@ class TestTokenIssue(TestToken): identity_fakes.user_id, ) self.assertEqual(datalist, data) + + +class TestTokenRevoke(TestToken): + + TOKEN = 'fob' + + def setUp(self): + super(TestTokenRevoke, self).setUp() + self.tokens_mock = self.app.client_manager.identity.tokens + self.tokens_mock.reset_mock() + self.tokens_mock.revoke_token.return_value = True + self.cmd = token.RevokeToken(self.app, None) + + def test_token_revoke(self): + arglist = [self.TOKEN] + verifylist = [('token', self.TOKEN)] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.tokens_mock.revoke_token.assert_called_with(self.TOKEN) diff --git a/releasenotes/notes/bug-1543226-7d885ecaa3715415.yaml b/releasenotes/notes/bug-1543226-7d885ecaa3715415.yaml new file mode 100644 index 0000000000..c7778d0e1a --- /dev/null +++ b/releasenotes/notes/bug-1543226-7d885ecaa3715415.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``token revoke`` command for Identity v3 + [Bug `1543226 `_] diff --git a/setup.cfg b/setup.cfg index 4cf9622ceb..8bcb99dede 100644 --- a/setup.cfg +++ b/setup.cfg @@ -295,6 +295,7 @@ openstack.identity.v3 = service_provider_show = openstackclient.identity.v3.service_provider:ShowServiceProvider token_issue = openstackclient.identity.v3.token:IssueToken + token_revoke = openstackclient.identity.v3.token:RevokeToken trust_create = openstackclient.identity.v3.trust:CreateTrust trust_delete = openstackclient.identity.v3.trust:DeleteTrust