2013-08-21 13:13:45 -05:00
|
|
|
# Copyright 2012-2013 OpenStack Foundation
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
|
|
|
|
|
|
|
"""Identity v3 Consumer action implementations"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2016-05-13 17:27:12 -05:00
|
|
|
from osc_lib.command import command
|
2016-05-13 16:14:09 -05:00
|
|
|
from osc_lib import utils
|
|
|
|
import six
|
|
|
|
|
2016-06-05 10:58:48 +08:00
|
|
|
from openstackclient.i18n import _
|
2013-08-21 13:13:45 -05:00
|
|
|
|
|
|
|
|
2016-01-10 21:54:53 +09:00
|
|
|
class CreateConsumer(command.ShowOne):
|
2015-01-08 01:29:35 -05:00
|
|
|
"""Create new consumer"""
|
2013-08-21 13:13:45 -05:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(CreateConsumer, self).get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'--description',
|
2015-01-08 01:29:35 -05:00
|
|
|
metavar='<description>',
|
2016-06-05 10:58:48 +08:00
|
|
|
help=_('New consumer description'),
|
2013-08-21 13:13:45 -05:00
|
|
|
)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
identity_client = self.app.client_manager.identity
|
2013-12-09 17:50:07 -06:00
|
|
|
consumer = identity_client.oauth1.consumers.create(
|
2013-08-21 13:13:45 -05:00
|
|
|
parsed_args.description
|
|
|
|
)
|
2014-11-13 16:48:59 -05:00
|
|
|
consumer._info.pop('links', None)
|
|
|
|
return zip(*sorted(six.iteritems(consumer._info)))
|
2013-08-21 13:13:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
class DeleteConsumer(command.Command):
|
2015-01-09 19:13:03 -05:00
|
|
|
"""Delete consumer"""
|
2013-08-21 13:13:45 -05:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(DeleteConsumer, self).get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'consumer',
|
|
|
|
metavar='<consumer>',
|
2016-06-05 10:58:48 +08:00
|
|
|
help=_('Consumer to delete'),
|
2013-08-21 13:13:45 -05:00
|
|
|
)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
identity_client = self.app.client_manager.identity
|
|
|
|
consumer = utils.find_resource(
|
2013-12-09 17:50:07 -06:00
|
|
|
identity_client.oauth1.consumers, parsed_args.consumer)
|
|
|
|
identity_client.oauth1.consumers.delete(consumer.id)
|
2013-08-21 13:13:45 -05:00
|
|
|
|
|
|
|
|
2016-01-10 21:54:53 +09:00
|
|
|
class ListConsumer(command.Lister):
|
2015-01-08 01:29:35 -05:00
|
|
|
"""List consumers"""
|
2013-08-21 13:13:45 -05:00
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
columns = ('ID', 'Description')
|
2013-12-09 17:50:07 -06:00
|
|
|
data = self.app.client_manager.identity.oauth1.consumers.list()
|
2013-08-21 13:13:45 -05:00
|
|
|
return (columns,
|
|
|
|
(utils.get_item_properties(
|
|
|
|
s, columns,
|
|
|
|
formatters={},
|
|
|
|
) for s in data))
|
|
|
|
|
|
|
|
|
|
|
|
class SetConsumer(command.Command):
|
2015-01-08 01:29:35 -05:00
|
|
|
"""Set consumer properties"""
|
2013-08-21 13:13:45 -05:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(SetConsumer, self).get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'consumer',
|
|
|
|
metavar='<consumer>',
|
2016-06-05 10:58:48 +08:00
|
|
|
help=_('Consumer to modify'),
|
2013-08-21 13:13:45 -05:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--description',
|
2015-01-08 01:29:35 -05:00
|
|
|
metavar='<description>',
|
2016-06-05 10:58:48 +08:00
|
|
|
help=_('New consumer description'),
|
2013-08-21 13:13:45 -05:00
|
|
|
)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
identity_client = self.app.client_manager.identity
|
|
|
|
consumer = utils.find_resource(
|
2013-12-09 17:50:07 -06:00
|
|
|
identity_client.oauth1.consumers, parsed_args.consumer)
|
2013-08-21 13:13:45 -05:00
|
|
|
kwargs = {}
|
|
|
|
if parsed_args.description:
|
|
|
|
kwargs['description'] = parsed_args.description
|
|
|
|
|
|
|
|
if not len(kwargs):
|
2016-06-05 10:58:48 +08:00
|
|
|
sys.stdout.write(_('Consumer not updated, no arguments present\n'))
|
2013-08-21 13:13:45 -05:00
|
|
|
return
|
|
|
|
|
2013-12-09 17:50:07 -06:00
|
|
|
consumer = identity_client.oauth1.consumers.update(
|
|
|
|
consumer.id, **kwargs)
|
2013-08-21 13:13:45 -05:00
|
|
|
|
|
|
|
|
2016-01-10 21:54:53 +09:00
|
|
|
class ShowConsumer(command.ShowOne):
|
2015-01-08 01:29:35 -05:00
|
|
|
"""Display consumer details"""
|
2013-08-21 13:13:45 -05:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(ShowConsumer, self).get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'consumer',
|
|
|
|
metavar='<consumer>',
|
2016-06-05 10:58:48 +08:00
|
|
|
help=_('Consumer to display'),
|
2013-08-21 13:13:45 -05:00
|
|
|
)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
identity_client = self.app.client_manager.identity
|
|
|
|
consumer = utils.find_resource(
|
2013-12-09 17:50:07 -06:00
|
|
|
identity_client.oauth1.consumers, parsed_args.consumer)
|
2013-08-21 13:13:45 -05:00
|
|
|
|
2014-11-13 16:48:59 -05:00
|
|
|
consumer._info.pop('links', None)
|
|
|
|
return zip(*sorted(six.iteritems(consumer._info)))
|