|
22 | 22 | from cliff import lister |
23 | 23 | from cliff import show |
24 | 24 |
|
| 25 | +from openstackclient.common import exceptions |
25 | 26 | from openstackclient.common import utils |
26 | 27 |
|
27 | 28 |
|
@@ -59,9 +60,10 @@ def take_action(self, parsed_args): |
59 | 60 | ) |
60 | 61 | user = utils.find_resource(identity_client.users, parsed_args.user) |
61 | 62 | role = identity_client.roles.add_user_role( |
62 | | - user, |
63 | | - role, |
64 | | - project) |
| 63 | + user.id, |
| 64 | + role.id, |
| 65 | + project.id, |
| 66 | + ) |
65 | 67 |
|
66 | 68 | info = {} |
67 | 69 | info.update(role._info) |
@@ -150,14 +152,23 @@ def get_parser(self, prog_name): |
150 | 152 | def take_action(self, parsed_args): |
151 | 153 | self.log.debug('take_action(%s)' % parsed_args) |
152 | 154 | identity_client = self.app.client_manager.identity |
| 155 | + auth_ref = self.app.client_manager.auth_ref |
153 | 156 |
|
154 | | - # user-only roles are not supported in KSL so we are |
155 | | - # required to have a user and project; default to the |
156 | | - # values used for authentication if not specified |
| 157 | + # Project and user are required, if not included in command args |
| 158 | + # default to the values used for authentication. For token-flow |
| 159 | + # authentication they must be included on the command line. |
157 | 160 | if not parsed_args.project: |
158 | | - parsed_args.project = identity_client.auth_tenant_id |
| 161 | + if self.app.client_manager.auth_ref: |
| 162 | + parsed_args.project = auth_ref.project_id |
| 163 | + else: |
| 164 | + msg = "Project must be specified" |
| 165 | + raise exceptions.CommandError(msg) |
159 | 166 | if not parsed_args.user: |
160 | | - parsed_args.user = identity_client.auth_user_id |
| 167 | + if self.app.client_manager.auth_ref: |
| 168 | + parsed_args.user = auth_ref.user_id |
| 169 | + else: |
| 170 | + msg = "User must be specified" |
| 171 | + raise exceptions.CommandError(msg) |
161 | 172 |
|
162 | 173 | project = utils.find_resource( |
163 | 174 | identity_client.tenants, |
|
0 commit comments