@@ -156,8 +156,8 @@ def sync_datasets_acls(self):
156156 "POST" , "/admin/connections/%s/sync" % self .name ,
157157 body = {'root' :True })
158158 return DSSFuture (self .client , future_response .get ('jobId' , None ), future_response )
159-
160-
159+
160+
161161class DSSUser (object ):
162162 """
163163 A handle for a user on the DSS instance.
@@ -167,10 +167,6 @@ def __init__(self, client, login):
167167 self .client = client
168168 self .login = login
169169
170- ########################################################
171- # User deletion
172- ########################################################
173-
174170 def delete (self ):
175171 """
176172 Deletes the user
@@ -179,6 +175,15 @@ def delete(self):
179175 return self .client ._perform_empty (
180176 "DELETE" , "/admin/users/%s" % self .login )
181177
178+ def get_settings (self ):
179+ """
180+ Gets the settings of the user
181+
182+ :rtype: :class:`DSSUserSettings`
183+ """
184+ raw = self .client ._perform_json ("GET" , "/admin/users/%s" % self .login )
185+ return DSSUserSettings (self .client , self .login , raw )
186+
182187 ########################################################
183188 # User description
184189 ########################################################
@@ -214,7 +219,104 @@ def set_definition(self, definition):
214219 return self .client ._perform_json (
215220 "PUT" , "/admin/users/%s" % self .login ,
216221 body = definition )
217-
222+
223+ def get_client_as (self ):
224+ from dataikuapi .dssclient import DSSClient
225+
226+ if self .client .api_key is not None :
227+ return DSSClient (self .client .host , self .client .api_key , extra_headers = {"X-DKU-ProxyUser" : self .login })
228+ elif self .client .internal_ticket is not None :
229+ return DSSClient (self .client .host , internal_ticket = self .client .internal_ticket ,
230+ extra_headers = {"X-DKU-ProxyUser" : self .login })
231+ else :
232+ raise ValueError ("Don't know how to proxy this client" )
233+
234+ class DSSOwnUser (object ):
235+ """
236+ A handle to interact with your own user
237+ Do not create this directly, use :meth:`dataikuapi.DSSClient.get_own_user`
238+ """
239+ def __init__ (self , client ):
240+ self .client = client
241+
242+ def get_settings (self ):
243+ """
244+ Gets your own settings
245+
246+ :rtype: :class:`DSSOwnUserSettings`
247+ """
248+ raw = self .client ._perform_json ("GET" , "/current-user" )
249+ return DSSOwnUserSettings (self .client , raw )
250+
251+
252+ class DSSUserSettingsBase (object ):
253+
254+ def __init__ (self , settings ):
255+ self .settings = settings
256+
257+ def get_raw (self ):
258+ """
259+ :returns: the raw settings of the user, as a dict. Modifications made to the returned object
260+ are reflected when saving
261+
262+ :rtype: dict
263+ """
264+ return self .settings
265+
266+ def set_basic_connection_credential (self , connection , user , password ):
267+ self .settings ["credentials" ][connection ] = {
268+ "type" : "BASIC" ,
269+ "user" : user ,
270+ "password" : password
271+ }
272+
273+ def remove_connection_credential (self ,connection ):
274+ if connection in self .settings ["credentials" ]:
275+ del self .settings ["credentials" ][connection ]
276+
277+ def set_basic_plugin_credential (self , plugin_id , param_set_id , preset_id , param_name , user , password ):
278+ name = json .dumps (["PLUGIN" , pluginId , paramSetId , presetId , paramName ])[1 :- 1 ]
279+
280+ self .settings ["credentials" ][name ] = {
281+ "type" : "BASIC" ,
282+ "user" : user ,
283+ "password" : password
284+ }
285+
286+ def set_oauth2_plugin_credential (self , plugin_id , param_set_id , preset_id , param_name , refresh_token ):
287+ name = json .dumps (["PLUGIN" , pluginId , paramSetId , presetId , paramName ])[1 :- 1 ]
288+
289+ self .settings ["credentials" ][name ] = {
290+ "type" : "OAUTH_REFRESH_TOKEN" ,
291+ "refreshToken" : refresh_token
292+ }
293+
294+ def remove_plugin_credential (self , plugin_id , param_set_id , preset_id , param_name ):
295+ name = json .dumps (["PLUGIN" , pluginId , paramSetId , presetId , paramName ])[1 :- 1 ]
296+
297+ if name in self .settings ["credentials" ]:
298+ del self .settings ["credentials" ][name ]
299+
300+
301+ class DSSUserSettings (DSSUserSettingsBase ):
302+ def __init__ (self , client , login , settings ):
303+ super (DSSUserSettings , self ).__init__ (settings )
304+ self .client = client
305+ self .login = login
306+
307+ def save (self ):
308+ self .client ._perform_json ("PUT" , "/admin/users/%s" % self .login , body = self .settings )
309+
310+
311+ class DSSOwnUserSettings (DSSUserSettingsBase ):
312+ def __init__ (self , client , settings ):
313+ super (DSSOwnUserSettings , self ).__init__ (settings )
314+ self .client = client
315+
316+ def save (self ):
317+ self .client ._perform_empty ("PUT" , "/current-user" , body = self .settings )
318+
319+
218320class DSSGroup (object ):
219321 """
220322 A group on the DSS instance.
0 commit comments