Skip to content

Commit 6a9d6af

Browse files
fmarco76Steve Martinelli
authored andcommitted
Add support to remote_id
The federation APIs for the identity providers introduce a new parameter for every identity provider, named remote_ids, which contains a list of entity ID associated with. This parameter can be provided during the creation of the identity provider and can be updated at any time. For more information look at the blueprint: https://blueprints.launchpad.net/keystone/+spec/idp-id-registration This patch add the support to this new parameter in the command line by inserting the option "--remote-id" in the following commands: - "identity provider create" - "identity provider set" Additionally, the values can be read from a file, specified by "--remote-id-file", containing an entity id per line. Change-Id: Ie93340ee57e54128daa70d8a7bd0a9975ff7eef4 Depends-On: I12a262c55b5f6b5cc7007865edf30f14269da537 Implements: blueprint idp-id-registration
1 parent 33313ea commit 6a9d6af

4 files changed

Lines changed: 314 additions & 14 deletions

File tree

‎doc/source/command-objects/identity-provider.rst‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@ Create new identity provider
1515
.. code:: bash
1616
1717
os identity provider create
18+
[--remote-id <remote-id> [...] | --remote-id-file <file-name>]
1819
[--description <description>]
1920
[--enable | --disable]
2021
<name>
2122
23+
.. option:: --remote-id <remote-id>
24+
25+
Remote IDs to associate with the Identity Provider (repeat to provide
26+
multiple values)
27+
28+
.. option:: --remote-id-file <file-name>
29+
30+
Name of a file that contains many remote IDs to associate with the identity
31+
provider, one per line
32+
2233
.. option:: --description
2334

2435
New identity provider description
@@ -69,9 +80,20 @@ Set identity provider properties
6980
.. code:: bash
7081
7182
os identity provider set
83+
[--remote-id <remote-id> [...] | --remote-id-file <file-name>]
7284
[--enable | --disable]
7385
<identity-provider>
7486
87+
.. option:: --remote-id <remote-id>
88+
89+
Remote IDs to associate with the Identity Provider (repeat to provide
90+
multiple values)
91+
92+
.. option:: --remote-id-file <file-name>
93+
94+
Name of a file that contains many remote IDs to associate with the identity
95+
provider, one per line
96+
7597
.. option:: --enable
7698

7799
Enable the identity provider

‎openstackclient/identity/v3/identity_provider.py‎

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ def get_parser(self, prog_name):
3535
metavar='<name>',
3636
help='New identity provider name (must be unique)'
3737
)
38+
identity_remote_id_provider = parser.add_mutually_exclusive_group()
39+
identity_remote_id_provider.add_argument(
40+
'--remote-id',
41+
metavar='<remote-id>',
42+
action='append',
43+
help='Remote IDs to associate with the Identity Provider '
44+
'(repeat to provide multiple values)'
45+
)
46+
identity_remote_id_provider.add_argument(
47+
'--remote-id-file',
48+
metavar='<file-name>',
49+
help='Name of a file that contains many remote IDs to associate '
50+
'with the identity provider, one per line'
51+
)
3852
parser.add_argument(
3953
'--description',
4054
metavar='<description>',
@@ -59,8 +73,17 @@ def get_parser(self, prog_name):
5973
def take_action(self, parsed_args):
6074
self.log.debug('take_action(%s)', parsed_args)
6175
identity_client = self.app.client_manager.identity
76+
if parsed_args.remote_id_file:
77+
file_content = utils.read_blob_file_contents(
78+
parsed_args.remote_id_file)
79+
remote_ids = file_content.splitlines()
80+
remote_ids = list(map(str.strip, remote_ids))
81+
else:
82+
remote_ids = (parsed_args.remote_id
83+
if parsed_args.remote_id else None)
6284
idp = identity_client.federation.identity_providers.create(
6385
id=parsed_args.identity_provider_id,
86+
remote_ids=remote_ids,
6487
description=parsed_args.description,
6588
enabled=parsed_args.enabled)
6689

@@ -119,6 +142,20 @@ def get_parser(self, prog_name):
119142
metavar='<identity-provider>',
120143
help='Identity provider to modify',
121144
)
145+
identity_remote_id_provider = parser.add_mutually_exclusive_group()
146+
identity_remote_id_provider.add_argument(
147+
'--remote-id',
148+
metavar='<remote-id>',
149+
action='append',
150+
help='Remote IDs to associate with the Identity Provider '
151+
'(repeat to provide multiple values)'
152+
)
153+
identity_remote_id_provider.add_argument(
154+
'--remote-id-file',
155+
metavar='<file-name>',
156+
help='Name of a file that contains many remote IDs to associate '
157+
'with the identity provider, one per line'
158+
)
122159
enable_identity_provider = parser.add_mutually_exclusive_group()
123160
enable_identity_provider.add_argument(
124161
'--enable',
@@ -136,16 +173,33 @@ def take_action(self, parsed_args):
136173
self.log.debug('take_action(%s)', parsed_args)
137174
federation_client = self.app.client_manager.identity.federation
138175

139-
if parsed_args.enable is True:
140-
enabled = True
141-
elif parsed_args.disable is True:
142-
enabled = False
143-
else:
144-
self.log.error("No changes requested")
176+
# Basic argument checking
177+
if (not parsed_args.enable and not parsed_args.disable and not
178+
parsed_args.remote_id and not parsed_args.remote_id_file):
179+
self.log.error('No changes requested')
145180
return (None, None)
146181

182+
# Always set remote_ids if either is passed in
183+
if parsed_args.remote_id_file:
184+
file_content = utils.read_blob_file_contents(
185+
parsed_args.remote_id_file)
186+
remote_ids = file_content.splitlines()
187+
remote_ids = list(map(str.strip, remote_ids))
188+
elif parsed_args.remote_id:
189+
remote_ids = parsed_args.remote_id
190+
191+
# Setup keyword args for the client
192+
kwargs = {}
193+
if parsed_args.enable:
194+
kwargs['enabled'] = True
195+
if parsed_args.disable:
196+
kwargs['enabled'] = False
197+
if parsed_args.remote_id_file or parsed_args.remote_id:
198+
kwargs['remote_ids'] = remote_ids
199+
147200
identity_provider = federation_client.identity_providers.update(
148-
parsed_args.identity_provider, enabled=enabled)
201+
parsed_args.identity_provider, **kwargs)
202+
149203
identity_provider._info.pop('links', None)
150204
return zip(*sorted(six.iteritems(identity_provider._info)))
151205

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,11 @@
231231

232232
idp_id = 'test_idp'
233233
idp_description = 'super exciting IdP description'
234+
idp_remote_ids = ['entity1', 'entity2']
234235

235236
IDENTITY_PROVIDER = {
236237
'id': idp_id,
238+
'remote_ids': idp_remote_ids,
237239
'enabled': True,
238240
'description': idp_description
239241
}

0 commit comments

Comments
 (0)