@@ -148,155 +148,11 @@ def take_action(self, parsed_args):
148148class ListRole (command .Lister ):
149149 _description = _ ("List roles" )
150150
151- def get_parser (self , prog_name ):
152- parser = super (ListRole , self ).get_parser (prog_name )
153- parser .add_argument (
154- '--project' ,
155- metavar = '<project>' ,
156- help = _ ('Filter roles by <project> (name or ID)' ),
157- )
158- parser .add_argument (
159- '--user' ,
160- metavar = '<user>' ,
161- help = _ ('Filter roles by <user> (name or ID)' ),
162- )
163- return parser
164-
165151 def take_action (self , parsed_args ):
166-
167- def _deprecated ():
168- # NOTE(henry-nash): Deprecated as of Newton, so we should remove
169- # this in the 'P' release.
170- self .log .warning (_ ('Listing assignments using role list is '
171- 'deprecated as of the Newton release. Use role '
172- 'assignment list --user <user-name> --project '
173- '<project-name> --names instead.' ))
174-
175152 identity_client = self .app .client_manager .identity
176- auth_ref = self .app .client_manager .auth_ref
177-
178- # No user or project specified, list all roles in the system
179- if not parsed_args .user and not parsed_args .project :
180- columns = ('ID' , 'Name' )
181- data = identity_client .roles .list ()
182- elif parsed_args .user and parsed_args .project :
183- user = utils .find_resource (
184- identity_client .users ,
185- parsed_args .user ,
186- )
187- project = utils .find_resource (
188- identity_client .projects ,
189- parsed_args .project ,
190- )
191- _deprecated ()
192- data = identity_client .roles .roles_for_user (user .id , project .id )
193-
194- elif parsed_args .user :
195- user = utils .find_resource (
196- identity_client .users ,
197- parsed_args .user ,
198- )
199- if self .app .client_manager .auth_ref :
200- project = utils .find_resource (
201- identity_client .projects ,
202- auth_ref .project_id
203- )
204- else :
205- msg = _ ("Project must be specified" )
206- raise exceptions .CommandError (msg )
207- _deprecated ()
208- data = identity_client .roles .roles_for_user (user .id , project .id )
209- elif parsed_args .project :
210- project = utils .find_resource (
211- identity_client .projects ,
212- parsed_args .project ,
213- )
214- if self .app .client_manager .auth_ref :
215- user = utils .find_resource (
216- identity_client .users ,
217- auth_ref .user_id
218- )
219- else :
220- msg = _ ("User must be specified" )
221- raise exceptions .CommandError (msg )
222- _deprecated ()
223- data = identity_client .roles .roles_for_user (user .id , project .id )
224-
225- if parsed_args .user or parsed_args .project :
226- columns = ('ID' , 'Name' , 'Project' , 'User' )
227- for user_role in data :
228- user_role .user = user .name
229- user_role .project = project .name
230-
231- return (columns ,
232- (utils .get_item_properties (
233- s , columns ,
234- formatters = {},
235- ) for s in data ))
236-
237-
238- class ListUserRole (command .Lister ):
239- _description = _ ("List user-role assignments" )
240-
241- def get_parser (self , prog_name ):
242- parser = super (ListUserRole , self ).get_parser (prog_name )
243- parser .add_argument (
244- 'user' ,
245- metavar = '<user>' ,
246- nargs = '?' ,
247- help = _ ('User to list (name or ID)' ),
248- )
249- parser .add_argument (
250- '--project' ,
251- metavar = '<project>' ,
252- help = _ ('Filter users by <project> (name or ID)' ),
253- )
254- return parser
255-
256- def take_action (self , parsed_args ):
257- identity_client = self .app .client_manager .identity
258- auth_ref = self .app .client_manager .auth_ref
259-
260- # Project and user are required, if not included in command args
261- # default to the values used for authentication. For token-flow
262- # authentication they must be included on the command line.
263- if (not parsed_args .project and
264- self .app .client_manager .auth_ref .project_id ):
265- parsed_args .project = auth_ref .project_id
266- if not parsed_args .project :
267- msg = _ ("Project must be specified" )
268- raise exceptions .CommandError (msg )
269-
270- if (not parsed_args .user and
271- self .app .client_manager .auth_ref .user_id ):
272- parsed_args .user = auth_ref .user_id
273- if not parsed_args .user :
274- msg = _ ("User must be specified" )
275- raise exceptions .CommandError (msg )
276-
277- self .log .warning (_ ('Listing assignments using user role list is '
278- 'deprecated as of the Newton release. Use role '
279- 'assignment list --user <user-name> --project '
280- '<project-name> --names instead.' ))
281- project = utils .find_resource (
282- identity_client .tenants ,
283- parsed_args .project ,
284- )
285- user = utils .find_resource (identity_client .users , parsed_args .user )
286-
287- data = identity_client .roles .roles_for_user (user .id , project .id )
288-
289- columns = (
290- 'ID' ,
291- 'Name' ,
292- 'Project' ,
293- 'User' ,
294- )
295153
296- # Add the names to the output even though they will be constant
297- for role in data :
298- role .user = user .name
299- role .project = project .name
154+ columns = ('ID' , 'Name' )
155+ data = identity_client .roles .list ()
300156
301157 return (columns ,
302158 (utils .get_item_properties (
0 commit comments