2828LOG = logging .getLogger (__name__ )
2929
3030
31+ def _format_credential (credential ):
32+ columns = (
33+ 'blob' ,
34+ 'id' ,
35+ 'project_id' ,
36+ 'type' ,
37+ 'user_id' ,
38+ )
39+ return (
40+ columns ,
41+ utils .get_item_properties (
42+ credential ,
43+ columns ,
44+ ),
45+ )
46+
47+
3148class CreateCredential (command .ShowOne ):
3249 _description = _ ("Create new credential" )
3350
@@ -60,25 +77,24 @@ def get_parser(self, prog_name):
6077 return parser
6178
6279 def take_action (self , parsed_args ):
63- identity_client = self .app .client_manager .identity
64- user_id = utils . find_resource (
65- identity_client . users , parsed_args .user
80+ identity_client = self .app .client_manager .sdk_connection . identity
81+ user_id = identity_client . find_user (
82+ parsed_args .user , ignore_missing = False
6683 ).id
6784 if parsed_args .project :
68- project = utils . find_resource (
69- identity_client . projects , parsed_args .project
85+ project = identity_client . find_project (
86+ parsed_args .project , ignore_missing = False
7087 ).id
7188 else :
7289 project = None
73- credential = identity_client .credentials . create (
90+ credential = identity_client .create_credential (
7491 user = user_id ,
7592 type = parsed_args .type ,
7693 blob = parsed_args .data ,
7794 project = project ,
7895 )
7996
80- credential ._info .pop ('links' )
81- return zip (* sorted (credential ._info .items ()))
97+ return _format_credential (credential )
8298
8399
84100class DeleteCredential (command .Command ):
@@ -95,11 +111,11 @@ def get_parser(self, prog_name):
95111 return parser
96112
97113 def take_action (self , parsed_args ):
98- identity_client = self .app .client_manager .identity
114+ identity_client = self .app .client_manager .sdk_connection . identity
99115 result = 0
100116 for i in parsed_args .credential :
101117 try :
102- identity_client .credentials . delete (i )
118+ identity_client .delete_credential (i )
103119 except Exception as e :
104120 result += 1
105121 LOG .error (
@@ -137,14 +153,17 @@ def get_parser(self, prog_name):
137153 return parser
138154
139155 def take_action (self , parsed_args ):
140- identity_client = self .app .client_manager .identity
156+ identity_client = self .app .client_manager .sdk_connection . identity
141157
142158 kwargs = {}
143159 if parsed_args .user :
144- user_id = common .find_user (
145- identity_client ,
146- parsed_args .user ,
147- parsed_args .user_domain ,
160+ domain_id = None
161+ if parsed_args .user_domain :
162+ domain_id = identity_client .find_domain (
163+ parsed_args .user_domain , ignore_missing = False
164+ )
165+ user_id = identity_client .find_user (
166+ parsed_args .user , domain_id = domain_id , ignore_missing = False
148167 ).id
149168 kwargs ["user_id" ] = user_id
150169
@@ -153,7 +172,8 @@ def take_action(self, parsed_args):
153172
154173 columns = ('ID' , 'Type' , 'User ID' , 'Blob' , 'Project ID' )
155174 column_headers = ('ID' , 'Type' , 'User ID' , 'Data' , 'Project ID' )
156- data = self .app .client_manager .identity .credentials .list (** kwargs )
175+ data = identity_client .credentials (** kwargs )
176+
157177 return (
158178 column_headers ,
159179 (
@@ -206,20 +226,20 @@ def get_parser(self, prog_name):
206226 return parser
207227
208228 def take_action (self , parsed_args ):
209- identity_client = self .app .client_manager .identity
229+ identity_client = self .app .client_manager .sdk_connection . identity
210230
211- user_id = utils . find_resource (
212- identity_client . users , parsed_args .user
231+ user_id = identity_client . find_user (
232+ parsed_args .user , ignore_missing = False
213233 ).id
214234
215235 if parsed_args .project :
216- project = utils . find_resource (
217- identity_client . projects , parsed_args .project
236+ project = identity_client . find_project (
237+ parsed_args .project , ignore_missing = False
218238 ).id
219239 else :
220240 project = None
221241
222- identity_client .credentials . update (
242+ identity_client .update_credential (
223243 parsed_args .credential ,
224244 user = user_id ,
225245 type = parsed_args .type ,
@@ -241,10 +261,7 @@ def get_parser(self, prog_name):
241261 return parser
242262
243263 def take_action (self , parsed_args ):
244- identity_client = self .app .client_manager .identity
245- credential = utils .find_resource (
246- identity_client .credentials , parsed_args .credential
247- )
264+ identity_client = self .app .client_manager .sdk_connection .identity
265+ credential = identity_client .get_credential (parsed_args .credential )
248266
249- credential ._info .pop ('links' )
250- return zip (* sorted (credential ._info .items ()))
267+ return _format_credential (credential )
0 commit comments