Skip to content

Commit d455044

Browse files
kozhukalovstephenfin
authored andcommitted
identity: Fix 'trust' commands to work with SDK
Closes-Bug: #2102039 Change-Id: I632937e06683cc76e78390a4e6f3de4e3c4f1f87 (cherry picked from commit 1458330)
1 parent 9e623da commit d455044

File tree

2 files changed

+78
-26
lines changed

2 files changed

+78
-26
lines changed

openstackclient/identity/v3/trust.py

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,46 +123,75 @@ def take_action(self, parsed_args):
123123
# pointless, and trusts are immutable, so let's enforce it at the
124124
# client level.
125125
try:
126-
trustor_id = identity_client.find_user(
127-
parsed_args.trustor, parsed_args.trustor_domain
128-
).id
129-
kwargs['trustor_id'] = trustor_id
126+
if parsed_args.trustor_domain:
127+
trustor_domain_id = identity_client.find_domain(
128+
parsed_args.trustor_domain, ignore_missing=False
129+
).id
130+
trustor_id = identity_client.find_user(
131+
parsed_args.trustor,
132+
ignore_missing=False,
133+
domain_id=trustor_domain_id,
134+
).id
135+
else:
136+
trustor_id = identity_client.find_user(
137+
parsed_args.trustor, ignore_missing=False
138+
).id
139+
kwargs['trustor_user_id'] = trustor_id
130140
except sdk_exceptions.ForbiddenException:
131-
kwargs['trustor_id'] = parsed_args.trustor
141+
kwargs['trustor_user_id'] = parsed_args.trustor
132142

133143
try:
134-
trustee_id = identity_client.find_user(
135-
parsed_args.trustee, parsed_args.trustee_domain
136-
).id
137-
kwargs['trustee_id'] = trustee_id
144+
if parsed_args.trustee_domain:
145+
trustee_domain_id = identity_client.find_domain(
146+
parsed_args.trustee_domain, ignore_missing=False
147+
).id
148+
trustee_id = identity_client.find_user(
149+
parsed_args.trustee,
150+
ignore_missing=False,
151+
domain_id=trustee_domain_id,
152+
).id
153+
else:
154+
trustee_id = identity_client.find_user(
155+
parsed_args.trustee, ignore_missing=False
156+
).id
157+
kwargs['trustee_user_id'] = trustee_id
138158
except sdk_exceptions.ForbiddenException:
139-
kwargs['trustee_id'] = parsed_args.trustee
159+
kwargs['trustee_user_id'] = parsed_args.trustee
140160

141161
try:
142-
project_id = identity_client.find_project(
143-
parsed_args.project, parsed_args.project_domain
144-
).id
162+
if parsed_args.project_domain:
163+
project_domain_id = identity_client.find_domain(
164+
parsed_args.project_domain, ignore_missing=False
165+
).id
166+
project_id = identity_client.find_project(
167+
parsed_args.project,
168+
ignore_missing=False,
169+
domain_id=project_domain_id,
170+
).id
171+
else:
172+
project_id = identity_client.find_project(
173+
parsed_args.project, ignore_missing=False
174+
).id
145175
kwargs['project_id'] = project_id
146176
except sdk_exceptions.ForbiddenException:
147177
kwargs['project_id'] = parsed_args.project
148178

149-
role_ids = []
179+
roles = []
150180
for role in parsed_args.roles:
151181
try:
152182
role_id = identity_client.find_role(role).id
153183
except sdk_exceptions.ForbiddenException:
154184
role_id = role
155-
role_ids.append(role_id)
156-
kwargs['roles'] = role_ids
185+
roles.append({"id": role_id})
186+
kwargs['roles'] = roles
157187

158188
if parsed_args.expiration:
159189
expires_at = datetime.datetime.strptime(
160190
parsed_args.expiration, '%Y-%m-%dT%H:%M:%S'
161191
)
162192
kwargs['expires_at'] = expires_at
163193

164-
if parsed_args.is_impersonation:
165-
kwargs['is_impersonation'] = parsed_args.is_impersonation
194+
kwargs['impersonation'] = bool(parsed_args.is_impersonation)
166195

167196
trust = identity_client.create_trust(**kwargs)
168197

@@ -289,19 +318,39 @@ def take_action(self, parsed_args):
289318
trustor = None
290319
if parsed_args.trustor:
291320
try:
292-
trustor_id = identity_client.find_user(
293-
parsed_args.trustor, parsed_args.trustor_domain
294-
).id
321+
if parsed_args.trustor_domain:
322+
trustor_domain_id = identity_client.find_domain(
323+
parsed_args.trustor_domain, ignore_missing=False
324+
).id
325+
trustor_id = identity_client.find_user(
326+
parsed_args.trustor,
327+
ignore_missing=False,
328+
domain_id=trustor_domain_id,
329+
).id
330+
else:
331+
trustor_id = identity_client.find_user(
332+
parsed_args.trustor, ignore_missing=False
333+
).id
295334
trustor = trustor_id
296335
except sdk_exceptions.ForbiddenException:
297336
trustor = parsed_args.trustor
298337

299338
trustee = None
300339
if parsed_args.trustee:
301340
try:
302-
trustee_id = identity_client.find_user(
303-
parsed_args.trustee, parsed_args.trustee_domain
304-
).id
341+
if parsed_args.trustee_domain:
342+
trustee_domain_id = identity_client.find_domain(
343+
parsed_args.trustee_domain, ignore_missing=False
344+
).id
345+
trustee_id = identity_client.find_user(
346+
parsed_args.trustee,
347+
ignore_missing=False,
348+
domain_id=trustee_domain_id,
349+
).id
350+
else:
351+
trustee_id = identity_client.find_user(
352+
parsed_args.trustee, ignore_missing=False
353+
).id
305354
trustee = trustee_id
306355
except sdk_exceptions.ForbiddenException:
307356
trustee = parsed_args.trustee

openstackclient/tests/unit/identity/v3/test_trust.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@ def test_trust_create_basic(self):
7070
# Set expected values
7171
kwargs = {
7272
'project_id': self.project.id,
73-
'roles': [self.role.id],
73+
'roles': [{'id': self.role.id}],
74+
'impersonation': False,
7475
}
7576
# TrustManager.create(trustee_id, trustor_id, impersonation=,
7677
# project=, role_names=, expires_at=)
7778
self.identity_sdk_client.create_trust.assert_called_with(
78-
trustor_id=self.user.id, trustee_id=self.user.id, **kwargs
79+
trustor_user_id=self.user.id,
80+
trustee_user_id=self.user.id,
81+
**kwargs,
7982
)
8083

8184
collist = (

0 commit comments

Comments
 (0)