Skip to content

Commit 8554fd2

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "CRUD operations for federated protocols"
2 parents d878687 + 14c61a0 commit 8554fd2

4 files changed

Lines changed: 397 additions & 0 deletions

File tree

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
14+
15+
"""Identity v3 Protocols actions implementations"""
16+
17+
import logging
18+
import six
19+
20+
from cliff import command
21+
from cliff import lister
22+
from cliff import show
23+
24+
from openstackclient.common import utils
25+
26+
27+
class CreateProtocol(show.ShowOne):
28+
"""Create new Federation Protocol tied to an Identity Provider"""
29+
30+
log = logging.getLogger(__name__ + 'CreateProtocol')
31+
32+
def get_parser(self, prog_name):
33+
parser = super(CreateProtocol, self).get_parser(prog_name)
34+
parser.add_argument(
35+
'federation_protocol',
36+
metavar='<name>',
37+
help='Protocol (must be unique per Identity Provider')
38+
parser.add_argument(
39+
'--identity-provider',
40+
metavar='<identity-provider>',
41+
help=('Identity Provider you want to add the Protocol to '
42+
'(must already exist)'), required=True)
43+
parser.add_argument(
44+
'--mapping',
45+
metavar='<mapping>', required=True,
46+
help='Mapping you want to be used (must already exist)')
47+
48+
return parser
49+
50+
def take_action(self, parsed_args):
51+
self.log.debug('take_action(%s)', parsed_args)
52+
identity_client = self.app.client_manager.identity
53+
protocol = identity_client.federation.protocols.create(
54+
protocol_id=parsed_args.federation_protocol,
55+
identity_provider=parsed_args.identity_provider,
56+
mapping=parsed_args.mapping)
57+
info = dict(protocol._info)
58+
# NOTE(marek-denis): Identity provider is not included in a response
59+
# from Keystone, however it should be listed to the user. Add it
60+
# manually to the output list, simply reusing value provided by the
61+
# user.
62+
info['identity_provider'] = parsed_args.identity_provider
63+
info['mapping'] = info.pop('mapping_id')
64+
return zip(*sorted(six.iteritems(info)))
65+
66+
67+
class DeleteProtocol(command.Command):
68+
"""Delete Federation Protocol tied to a Identity Provider"""
69+
70+
log = logging.getLogger(__name__ + '.DeleteProtocol')
71+
72+
def get_parser(self, prog_name):
73+
parser = super(DeleteProtocol, self).get_parser(prog_name)
74+
parser.add_argument(
75+
'federation_protocol',
76+
metavar='<name>',
77+
help='Protocol (must be unique per Identity Provider')
78+
parser.add_argument(
79+
'--identity-provider',
80+
metavar='<identity-provider>', required=True,
81+
help='Identity Provider the Protocol is tied to')
82+
83+
return parser
84+
85+
def take_action(self, parsed_args):
86+
self.log.debug('take_action(%s)', parsed_args)
87+
identity_client = self.app.client_manager.identity
88+
identity_client.federation.protocols.delete(
89+
parsed_args.identity_provider, parsed_args.federation_protocol)
90+
return
91+
92+
93+
class ListProtocols(lister.Lister):
94+
"""List Protocols tied to an Identity Provider"""
95+
96+
log = logging.getLogger(__name__ + '.ListProtocols')
97+
98+
def get_parser(self, prog_name):
99+
parser = super(ListProtocols, self).get_parser(prog_name)
100+
parser.add_argument(
101+
'--identity-provider',
102+
metavar='<identity-provider>', required=True,
103+
help='Identity Provider the Protocol is tied to')
104+
105+
return parser
106+
107+
def take_action(self, parsed_args):
108+
identity_client = self.app.client_manager.identity
109+
110+
protocols = identity_client.federation.protocols.list(
111+
parsed_args.identity_provider)
112+
columns = ('id', 'mapping')
113+
response_attributes = ('id', 'mapping_id')
114+
items = [utils.get_item_properties(s, response_attributes)
115+
for s in protocols]
116+
return (columns, items)
117+
118+
119+
class SetProtocol(command.Command):
120+
"""Set Protocol tied to an Identity Provider"""
121+
122+
log = logging.getLogger(__name__ + '.SetProtocol')
123+
124+
def get_parser(self, prog_name):
125+
parser = super(SetProtocol, self).get_parser(prog_name)
126+
parser.add_argument(
127+
'federation_protocol',
128+
metavar='<name>',
129+
help='Protocol (must be unique per Identity Provider')
130+
parser.add_argument(
131+
'--identity-provider',
132+
metavar='<identity-provider>', required=True,
133+
help=('Identity Provider you want to add the Protocol to '
134+
'(must already exist)'))
135+
parser.add_argument(
136+
'--mapping',
137+
metavar='<mapping>', required=True,
138+
help='Mapping you want to be used (must already exist)')
139+
return parser
140+
141+
def take_action(self, parsed_args):
142+
identity_client = self.app.client_manager.identity
143+
144+
protocol = identity_client.federation.protocols.update(
145+
parsed_args.identity_provider, parsed_args.federation_protocol,
146+
parsed_args.mapping)
147+
info = dict(protocol._info)
148+
# NOTE(marek-denis): Identity provider is not included in a response
149+
# from Keystone, however it should be listed to the user. Add it
150+
# manually to the output list, simply reusing value provided by the
151+
# user.
152+
info['identity_provider'] = parsed_args.identity_provider
153+
info['mapping'] = info.pop('mapping_id')
154+
return zip(*sorted(six.iteritems(info)))
155+
156+
157+
class ShowProtocol(show.ShowOne):
158+
"""Show Protocol tied to an Identity Provider"""
159+
160+
log = logging.getLogger(__name__ + '.ShowProtocol')
161+
162+
def get_parser(self, prog_name):
163+
parser = super(ShowProtocol, self).get_parser(prog_name)
164+
parser.add_argument(
165+
'federation_protocol',
166+
metavar='<name>',
167+
help='Protocol (must be unique per Identity Provider')
168+
parser.add_argument(
169+
'--identity-provider',
170+
metavar='<identity-provider>', required=True,
171+
help=('Identity Provider you want to add the Protocol to '
172+
'(must already exist)'))
173+
return parser
174+
175+
def take_action(self, parsed_args):
176+
identity_client = self.app.client_manager.identity
177+
178+
protocol = identity_client.federation.protocols.get(
179+
parsed_args.identity_provider, parsed_args.federation_protocol)
180+
info = dict(protocol._info)
181+
info['mapping'] = info.pop('mapping_id')
182+
return zip(*sorted(six.iteritems(info)))

‎openstackclient/tests/identity/v3/fakes.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,28 @@
190190
'description': idp_description
191191
}
192192

193+
protocol_id = 'protocol'
194+
195+
mapping_id = 'test_mapping'
196+
mapping_id_updated = 'prod_mapping'
197+
198+
PROTOCOL_ID_MAPPING = {
199+
'id': protocol_id,
200+
'mapping': mapping_id
201+
}
202+
203+
PROTOCOL_OUTPUT = {
204+
'id': protocol_id,
205+
'mapping_id': mapping_id,
206+
'identity_provider': idp_id
207+
}
208+
209+
PROTOCOL_OUTPUT_UPDATED = {
210+
'id': protocol_id,
211+
'mapping_id': mapping_id_updated,
212+
'identity_provider': idp_id
213+
}
214+
193215
# Assignments
194216

195217
ASSIGNMENT_WITH_PROJECT_ID_AND_USER_ID = {
@@ -285,6 +307,8 @@ def __init__(self, **kwargs):
285307
self.identity_providers.resource_class = fakes.FakeResource(None, {})
286308
self.mappings = mock.Mock()
287309
self.mappings.resource_class = fakes.FakeResource(None, {})
310+
self.protocols = mock.Mock()
311+
self.protocols.resource_class = fakes.FakeResource(None, {})
288312

289313

290314
class FakeFederatedClient(FakeIdentityv3Client):

0 commit comments

Comments
 (0)