identity: Fix 'trust' commands to work with SDK
Closes-Bug: #2102039 Change-Id: I632937e06683cc76e78390a4e6f3de4e3c4f1f87
This commit is contained in:
parent
966aede8ab
commit
1458330d3b
openstackclient
@ -123,37 +123,67 @@ class CreateTrust(command.ShowOne):
|
|||||||
# pointless, and trusts are immutable, so let's enforce it at the
|
# pointless, and trusts are immutable, so let's enforce it at the
|
||||||
# client level.
|
# client level.
|
||||||
try:
|
try:
|
||||||
trustor_id = identity_client.find_user(
|
if parsed_args.trustor_domain:
|
||||||
parsed_args.trustor, parsed_args.trustor_domain
|
trustor_domain_id = identity_client.find_domain(
|
||||||
).id
|
parsed_args.trustor_domain, ignore_missing=False
|
||||||
kwargs['trustor_id'] = trustor_id
|
).id
|
||||||
|
trustor_id = identity_client.find_user(
|
||||||
|
parsed_args.trustor,
|
||||||
|
ignore_missing=False,
|
||||||
|
domain_id=trustor_domain_id,
|
||||||
|
).id
|
||||||
|
else:
|
||||||
|
trustor_id = identity_client.find_user(
|
||||||
|
parsed_args.trustor, ignore_missing=False
|
||||||
|
).id
|
||||||
|
kwargs['trustor_user_id'] = trustor_id
|
||||||
except sdk_exceptions.ForbiddenException:
|
except sdk_exceptions.ForbiddenException:
|
||||||
kwargs['trustor_id'] = parsed_args.trustor
|
kwargs['trustor_user_id'] = parsed_args.trustor
|
||||||
|
|
||||||
try:
|
try:
|
||||||
trustee_id = identity_client.find_user(
|
if parsed_args.trustee_domain:
|
||||||
parsed_args.trustee, parsed_args.trustee_domain
|
trustee_domain_id = identity_client.find_domain(
|
||||||
).id
|
parsed_args.trustee_domain, ignore_missing=False
|
||||||
kwargs['trustee_id'] = trustee_id
|
).id
|
||||||
|
trustee_id = identity_client.find_user(
|
||||||
|
parsed_args.trustee,
|
||||||
|
ignore_missing=False,
|
||||||
|
domain_id=trustee_domain_id,
|
||||||
|
).id
|
||||||
|
else:
|
||||||
|
trustee_id = identity_client.find_user(
|
||||||
|
parsed_args.trustee, ignore_missing=False
|
||||||
|
).id
|
||||||
|
kwargs['trustee_user_id'] = trustee_id
|
||||||
except sdk_exceptions.ForbiddenException:
|
except sdk_exceptions.ForbiddenException:
|
||||||
kwargs['trustee_id'] = parsed_args.trustee
|
kwargs['trustee_user_id'] = parsed_args.trustee
|
||||||
|
|
||||||
try:
|
try:
|
||||||
project_id = identity_client.find_project(
|
if parsed_args.project_domain:
|
||||||
parsed_args.project, parsed_args.project_domain
|
project_domain_id = identity_client.find_domain(
|
||||||
).id
|
parsed_args.project_domain, ignore_missing=False
|
||||||
|
).id
|
||||||
|
project_id = identity_client.find_project(
|
||||||
|
parsed_args.project,
|
||||||
|
ignore_missing=False,
|
||||||
|
domain_id=project_domain_id,
|
||||||
|
).id
|
||||||
|
else:
|
||||||
|
project_id = identity_client.find_project(
|
||||||
|
parsed_args.project, ignore_missing=False
|
||||||
|
).id
|
||||||
kwargs['project_id'] = project_id
|
kwargs['project_id'] = project_id
|
||||||
except sdk_exceptions.ForbiddenException:
|
except sdk_exceptions.ForbiddenException:
|
||||||
kwargs['project_id'] = parsed_args.project
|
kwargs['project_id'] = parsed_args.project
|
||||||
|
|
||||||
role_ids = []
|
roles = []
|
||||||
for role in parsed_args.roles:
|
for role in parsed_args.roles:
|
||||||
try:
|
try:
|
||||||
role_id = identity_client.find_role(role).id
|
role_id = identity_client.find_role(role).id
|
||||||
except sdk_exceptions.ForbiddenException:
|
except sdk_exceptions.ForbiddenException:
|
||||||
role_id = role
|
role_id = role
|
||||||
role_ids.append(role_id)
|
roles.append({"id": role_id})
|
||||||
kwargs['roles'] = role_ids
|
kwargs['roles'] = roles
|
||||||
|
|
||||||
if parsed_args.expiration:
|
if parsed_args.expiration:
|
||||||
expires_at = datetime.datetime.strptime(
|
expires_at = datetime.datetime.strptime(
|
||||||
@ -161,8 +191,7 @@ class CreateTrust(command.ShowOne):
|
|||||||
)
|
)
|
||||||
kwargs['expires_at'] = expires_at
|
kwargs['expires_at'] = expires_at
|
||||||
|
|
||||||
if parsed_args.is_impersonation:
|
kwargs['impersonation'] = bool(parsed_args.is_impersonation)
|
||||||
kwargs['is_impersonation'] = parsed_args.is_impersonation
|
|
||||||
|
|
||||||
trust = identity_client.create_trust(**kwargs)
|
trust = identity_client.create_trust(**kwargs)
|
||||||
|
|
||||||
@ -289,9 +318,19 @@ class ListTrust(command.Lister):
|
|||||||
trustor = None
|
trustor = None
|
||||||
if parsed_args.trustor:
|
if parsed_args.trustor:
|
||||||
try:
|
try:
|
||||||
trustor_id = identity_client.find_user(
|
if parsed_args.trustor_domain:
|
||||||
parsed_args.trustor, parsed_args.trustor_domain
|
trustor_domain_id = identity_client.find_domain(
|
||||||
).id
|
parsed_args.trustor_domain, ignore_missing=False
|
||||||
|
).id
|
||||||
|
trustor_id = identity_client.find_user(
|
||||||
|
parsed_args.trustor,
|
||||||
|
ignore_missing=False,
|
||||||
|
domain_id=trustor_domain_id,
|
||||||
|
).id
|
||||||
|
else:
|
||||||
|
trustor_id = identity_client.find_user(
|
||||||
|
parsed_args.trustor, ignore_missing=False
|
||||||
|
).id
|
||||||
trustor = trustor_id
|
trustor = trustor_id
|
||||||
except sdk_exceptions.ForbiddenException:
|
except sdk_exceptions.ForbiddenException:
|
||||||
trustor = parsed_args.trustor
|
trustor = parsed_args.trustor
|
||||||
@ -299,9 +338,19 @@ class ListTrust(command.Lister):
|
|||||||
trustee = None
|
trustee = None
|
||||||
if parsed_args.trustee:
|
if parsed_args.trustee:
|
||||||
try:
|
try:
|
||||||
trustee_id = identity_client.find_user(
|
if parsed_args.trustee_domain:
|
||||||
parsed_args.trustee, parsed_args.trustee_domain
|
trustee_domain_id = identity_client.find_domain(
|
||||||
).id
|
parsed_args.trustee_domain, ignore_missing=False
|
||||||
|
).id
|
||||||
|
trustee_id = identity_client.find_user(
|
||||||
|
parsed_args.trustee,
|
||||||
|
ignore_missing=False,
|
||||||
|
domain_id=trustee_domain_id,
|
||||||
|
).id
|
||||||
|
else:
|
||||||
|
trustee_id = identity_client.find_user(
|
||||||
|
parsed_args.trustee, ignore_missing=False
|
||||||
|
).id
|
||||||
trustee = trustee_id
|
trustee = trustee_id
|
||||||
except sdk_exceptions.ForbiddenException:
|
except sdk_exceptions.ForbiddenException:
|
||||||
trustee = parsed_args.trustee
|
trustee = parsed_args.trustee
|
||||||
|
@ -70,12 +70,15 @@ class TestTrustCreate(identity_fakes.TestIdentityv3):
|
|||||||
# Set expected values
|
# Set expected values
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'project_id': self.project.id,
|
'project_id': self.project.id,
|
||||||
'roles': [self.role.id],
|
'roles': [{'id': self.role.id}],
|
||||||
|
'impersonation': False,
|
||||||
}
|
}
|
||||||
# TrustManager.create(trustee_id, trustor_id, impersonation=,
|
# TrustManager.create(trustee_id, trustor_id, impersonation=,
|
||||||
# project=, role_names=, expires_at=)
|
# project=, role_names=, expires_at=)
|
||||||
self.identity_sdk_client.create_trust.assert_called_with(
|
self.identity_sdk_client.create_trust.assert_called_with(
|
||||||
trustor_id=self.user.id, trustee_id=self.user.id, **kwargs
|
trustor_user_id=self.user.id,
|
||||||
|
trustee_user_id=self.user.id,
|
||||||
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
collist = (
|
collist = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user