Skip to content

Commit 2dff286

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Identity: Migrate 'federation protocol' commands to SDK"
2 parents e607ee2 + d135994 commit 2dff286

2 files changed

Lines changed: 136 additions & 128 deletions

File tree

openstackclient/identity/v3/federation_protocol.py

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
LOG = logging.getLogger(__name__)
2727

2828

29+
def _format_protocol(protocol):
30+
columns = ('name', 'idp_id', 'mapping_id')
31+
column_headers = ('id', 'identity_provider', 'mapping')
32+
return (
33+
column_headers,
34+
utils.get_item_properties(protocol, columns),
35+
)
36+
37+
2938
class CreateProtocol(command.ShowOne):
3039
_description = _("Create new federation protocol")
3140

@@ -58,21 +67,15 @@ def get_parser(self, prog_name):
5867
return parser
5968

6069
def take_action(self, parsed_args):
61-
identity_client = self.app.client_manager.identity
62-
protocol = identity_client.federation.protocols.create(
63-
protocol_id=parsed_args.federation_protocol,
64-
identity_provider=parsed_args.identity_provider,
65-
mapping=parsed_args.mapping,
70+
identity_client = self.app.client_manager.sdk_connection.identity
71+
72+
protocol = identity_client.create_federation_protocol(
73+
name=parsed_args.federation_protocol,
74+
idp_id=parsed_args.identity_provider,
75+
mapping_id=parsed_args.mapping,
6676
)
67-
info = dict(protocol._info)
68-
# NOTE(marek-denis): Identity provider is not included in a response
69-
# from Keystone, however it should be listed to the user. Add it
70-
# manually to the output list, simply reusing value provided by the
71-
# user.
72-
info['identity_provider'] = parsed_args.identity_provider
73-
info['mapping'] = info.pop('mapping_id')
74-
info.pop('links', None)
75-
return zip(*sorted(info.items()))
77+
78+
return _format_protocol(protocol)
7679

7780

7881
class DeleteProtocol(command.Command):
@@ -99,12 +102,15 @@ def get_parser(self, prog_name):
99102
return parser
100103

101104
def take_action(self, parsed_args):
102-
identity_client = self.app.client_manager.identity
105+
identity_client = self.app.client_manager.sdk_connection.identity
106+
103107
result = 0
104108
for i in parsed_args.federation_protocol:
105109
try:
106-
identity_client.federation.protocols.delete(
107-
parsed_args.identity_provider, i
110+
identity_client.delete_federation_protocol(
111+
idp_id=parsed_args.identity_provider,
112+
protocol=i,
113+
ignore_missing=False,
108114
)
109115
except Exception as e:
110116
result += 1
@@ -140,9 +146,9 @@ def get_parser(self, prog_name):
140146
return parser
141147

142148
def take_action(self, parsed_args):
143-
identity_client = self.app.client_manager.identity
149+
identity_client = self.app.client_manager.sdk_connection.identity
144150

145-
protocols = identity_client.federation.protocols.list(
151+
protocols = identity_client.federation_protocols(
146152
parsed_args.identity_provider
147153
)
148154
columns = ('id', 'mapping')
@@ -181,21 +187,16 @@ def get_parser(self, prog_name):
181187
return parser
182188

183189
def take_action(self, parsed_args):
184-
identity_client = self.app.client_manager.identity
190+
identity_client = self.app.client_manager.sdk_connection.identity
185191

186-
protocol = identity_client.federation.protocols.update(
187-
parsed_args.identity_provider,
188-
parsed_args.federation_protocol,
189-
parsed_args.mapping,
190-
)
191-
info = dict(protocol._info)
192-
# NOTE(marek-denis): Identity provider is not included in a response
193-
# from Keystone, however it should be listed to the user. Add it
194-
# manually to the output list, simply reusing value provided by the
195-
# user.
196-
info['identity_provider'] = parsed_args.identity_provider
197-
info['mapping'] = info.pop('mapping_id')
198-
return zip(*sorted(info.items()))
192+
kwargs = {'idp_id': parsed_args.identity_provider}
193+
if parsed_args.federation_protocol:
194+
kwargs['name'] = parsed_args.federation_protocol
195+
if parsed_args.mapping:
196+
kwargs['mapping_id'] = parsed_args.mapping
197+
198+
protocol = identity_client.update_federation_protocol(**kwargs)
199+
return _format_protocol(protocol)
199200

200201

201202
class ShowProtocol(command.ShowOne):
@@ -220,12 +221,10 @@ def get_parser(self, prog_name):
220221
return parser
221222

222223
def take_action(self, parsed_args):
223-
identity_client = self.app.client_manager.identity
224+
identity_client = self.app.client_manager.sdk_connection.identity
224225

225-
protocol = identity_client.federation.protocols.get(
226-
parsed_args.identity_provider, parsed_args.federation_protocol
226+
protocol = identity_client.get_federation_protocol(
227+
idp_id=parsed_args.identity_provider,
228+
protocol=parsed_args.federation_protocol,
227229
)
228-
info = dict(protocol._info)
229-
info['mapping'] = info.pop('mapping_id')
230-
info.pop('links', None)
231-
return zip(*sorted(info.items()))
230+
return _format_protocol(protocol)

0 commit comments

Comments
 (0)