11from .future import DSSFuture
2- import json
2+ import json , warnings
33
44class DSSConnectionInfo (dict ):
55 """A class holding read-only information about a connection.
@@ -10,7 +10,6 @@ class DSSConnectionInfo(dict):
1010
1111 Depending on the connection kind, the credential may be available using :meth:`get_basic_credential`
1212 or :meth:`get_aws_credential`
13-
1413 """
1514 def __init__ (self , data ):
1615 """Do not call this directly, use :meth:`DSSConnection.get_info`"""
@@ -48,14 +47,12 @@ def get_aws_credential(self):
4847 return self ["resolvedAWSCredential" ]
4948
5049
51-
52-
53-
5450class DSSConnection (object ):
5551 """
56- A connection on the DSS instance
52+ A connection on the DSS instance.
5753 """
5854 def __init__ (self , client , name ):
55+ """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_connection`"""
5956 self .client = client
6057 self .name = name
6158
@@ -65,16 +62,14 @@ def __init__(self, client, name):
6562
6663 def get_location_info (self ):
6764 """Deprecated, use get_info"""
65+ warnings .warn ("DSSConnection.get_location_info is deprecated, please use get_info" , DeprecationWarning )
6866 return self .get_info ()
6967
7068 def get_info (self ):
7169 """
7270 Gets information about this connection.
7371
74- Note: this call requires either an admin API key or
75- a personal API key that corresponds to a user who
76- belongs to a group who has the rights to read connection
77- details
72+ Note: this call requires permissions to read connection details
7873
7974 :returns: a :class:`DSSConnectionInfo` containing connection information
8075 """
@@ -88,21 +83,13 @@ def get_info(self):
8883 def delete (self ):
8984 """
9085 Delete the connection
91-
92- Note: this call requires an API key with admin rights
9386 """
9487 return self .client ._perform_empty (
9588 "DELETE" , "/admin/connections/%s" % self .name )
96-
97-
98- ########################################################
99- # User description
100- ########################################################
101-
89+
10290 def get_definition (self ):
10391 """
10492 Get the connection's definition (type, name, params, usage restrictions)
105- Note: this call requires an API key with admin rights
10693
10794 :returns: The connection definition, as a dict.
10895
@@ -116,7 +103,6 @@ def get_definition(self):
116103 def set_definition (self , description ):
117104 """
118105 Set the connection's definition.
119- Note: this call requires an API key with admin rights
120106
121107 You should only :meth:`set_definition` using an object that you obtained through :meth:`get_definition`,
122108 not create a new dict.
@@ -134,10 +120,9 @@ def set_definition(self, description):
134120 def sync_root_acls (self ):
135121 """
136122 Resync root permissions on this connection path. This is only useful for HDFS connections
137- when DSS is in multi-user-security mode.
138- Note: this call requires an API key with admin rights
139-
140- :returns: a :class:`~dataikuapi.dss.future.DSSFuture` handle to the task of resynchronizing the permissions
123+ when DSS has User Isolation activated with "DSS-managed HDFS ACL"
124+
125+ :returns: a :class:`~dataikuapi.dss.future.DSSFuture` handle to the task of resynchronizing the permissions
141126 """
142127 future_response = self .client ._perform_json (
143128 "POST" , "/admin/connections/%s/sync" % self .name ,
@@ -147,10 +132,9 @@ def sync_root_acls(self):
147132 def sync_datasets_acls (self ):
148133 """
149134 Resync permissions on datasets in this connection path. This is only useful for HDFS connections
150- when DSS is in multi-user-security mode.
151- Note: this call requires an API key with admin rights
135+ when DSS has User Isolation activated with "DSS-managed HDFS ACL"
152136
153- :returns: a :class:`~dataikuapi.dss.future.DSSFuture` handle to the task of resynchronizing the permissions
137+ :returns: a :class:`~dataikuapi.dss.future.DSSFuture` handle to the task of resynchronizing the permissions
154138 """
155139 future_response = self .client ._perform_json (
156140 "POST" , "/admin/connections/%s/sync" % self .name ,
@@ -164,42 +148,44 @@ class DSSUser(object):
164148 Do not create this directly, use :meth:`dataikuapi.DSSClient.get_user`
165149 """
166150 def __init__ (self , client , login ):
151+ """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_user`"""
167152 self .client = client
168153 self .login = login
169154
170155 def delete (self ):
171156 """
172157 Deletes the user
173- Note: this call requires an API key with admin rights
174158 """
175159 return self .client ._perform_empty (
176160 "DELETE" , "/admin/users/%s" % self .login )
177161
178162 def get_settings (self ):
179163 """
180164 Gets the settings of the user
181-
182165 :rtype: :class:`DSSUserSettings`
183166 """
184- raw = self .client ._perform_json ("GET" , "/admin/users/%s" % self .login )
167+ raw = self .client ._perform_json ("GET" , "/admin/users/%s" % self .login )
185168 return DSSUserSettings (self .client , self .login , raw )
186169
187170 ########################################################
188- # User description
171+ # Legacy
189172 ########################################################
190173
191174 def get_definition (self ):
192175 """
176+ Deprecated, use get_settings instead
177+
193178 Get the user's definition (login, type, display name, permissions, ...)
194- Note: this call requires an API key with admin rights
195179
196180 :return: the user's definition, as a dict
197181 """
198- return self . client . _perform_json (
199- "GET" , "/admin/users/%s" % self .login )
182+ warnings . warn ( "DSSUser.get_definition is deprecated, please use get_settings" , DeprecationWarning )
183+ return self . client . _perform_json ( "GET" , "/admin/users/%s" % self .login )
200184
201185 def set_definition (self , definition ):
202186 """
187+ Deprecated, use get_settings instead
188+
203189 Set the user's definition.
204190 Note: this call requires an API key with admin rights
205191
@@ -216,11 +202,16 @@ def set_definition(self, definition):
216202
217203 :param dict definition: the definition for the user, as a dict
218204 """
219- return self .client ._perform_json (
220- "PUT" , "/admin/users/%s" % self .login ,
221- body = definition )
205+ warnings .warn ("DSSUser.set_definition is deprecated, please use get_settings" , DeprecationWarning )
206+ return self .client ._perform_json ("PUT" , "/admin/users/%s" % self .login , body = definition )
222207
223208 def get_client_as (self ):
209+ """
210+ Gets a :class:`dataikuapi.DSSClient` that has the permissions of this user.
211+
212+ This allows administrators to impersonate actions on behalf of other users, in order to perform
213+ actions on their behalf
214+ """
224215 from dataikuapi .dssclient import DSSClient
225216
226217 if self .client .api_key is not None :
@@ -241,7 +232,7 @@ def __init__(self, client):
241232
242233 def get_settings (self ):
243234 """
244- Gets your own settings
235+ Get your own settings
245236
246237 :rtype: :class:`DSSOwnUserSettings`
247238 """
@@ -250,31 +241,55 @@ def get_settings(self):
250241
251242
252243class DSSUserSettingsBase (object ):
253-
244+ """Settings for a DSS user"""
254245 def __init__ (self , settings ):
246+ """Do not call this directly, use :meth:`DSSUser.get_settings` or :meth:`DSSOwnUser.get_settings` """
255247 self .settings = settings
256248
257249 def get_raw (self ):
258250 """
259- :returns : the raw settings of the user, as a dict. Modifications made to the returned object
251+ :return : the raw settings of the user, as a dict. Modifications made to the returned object
260252 are reflected when saving
261-
262253 :rtype: dict
263254 """
264255 return self .settings
265256
257+ def add_secret (self , name , value ):
258+ """
259+ Adds a user secret.
260+ If there was already a secret with the same name, it is replaced
261+ """
262+ self .remove_secret (name )
263+ return self .settings ["secrets" ].append ({"name" : name , "value" : value , "secret" : True })
264+
265+ def remove_secret (self , name ):
266+ """Removes a user secret based on its name"""
267+ self .settings ["secrets" ] = [x for x in self .settings ["secrets" ] if x ["name" ] != name ]
268+
269+ @property
270+ def user_properties (self ):
271+ """
272+ The user properties (editable by the user) for this user. Do not set this property, modify the dict in place
273+
274+ :rtype dict
275+ """
276+ return self .settings ["userProperties" ]
277+
266278 def set_basic_connection_credential (self , connection , user , password ):
279+ """Sets per-user-credentials for a connection that takes a user/password pair"""
267280 self .settings ["credentials" ][connection ] = {
268281 "type" : "BASIC" ,
269282 "user" : user ,
270283 "password" : password
271284 }
272285
273286 def remove_connection_credential (self ,connection ):
287+ """Removes per-user-credentials for a connection"""
274288 if connection in self .settings ["credentials" ]:
275289 del self .settings ["credentials" ][connection ]
276290
277291 def set_basic_plugin_credential (self , plugin_id , param_set_id , preset_id , param_name , user , password ):
292+ """Sets per-user-credentials for a plugin preset that takes a user/password pair"""
278293 name = json .dumps (["PLUGIN" , pluginId , paramSetId , presetId , paramName ])[1 :- 1 ]
279294
280295 self .settings ["credentials" ][name ] = {
@@ -284,6 +299,7 @@ def set_basic_plugin_credential(self, plugin_id, param_set_id, preset_id, param_
284299 }
285300
286301 def set_oauth2_plugin_credential (self , plugin_id , param_set_id , preset_id , param_name , refresh_token ):
302+ """Sets per-user-credentials for a plugin preset that takes a OAuth refresh token"""
287303 name = json .dumps (["PLUGIN" , pluginId , paramSetId , presetId , paramName ])[1 :- 1 ]
288304
289305 self .settings ["credentials" ][name ] = {
@@ -292,28 +308,46 @@ def set_oauth2_plugin_credential(self, plugin_id, param_set_id, preset_id, param
292308 }
293309
294310 def remove_plugin_credential (self , plugin_id , param_set_id , preset_id , param_name ):
311+ """Removes per-user-credentials for a plugin preset"""
295312 name = json .dumps (["PLUGIN" , pluginId , paramSetId , presetId , paramName ])[1 :- 1 ]
296313
297314 if name in self .settings ["credentials" ]:
298315 del self .settings ["credentials" ][name ]
299316
300317
301318class DSSUserSettings (DSSUserSettingsBase ):
319+ """Settings for a DSS user"""
320+
302321 def __init__ (self , client , login , settings ):
322+ """Do not call this directly, use :meth:`DSSUser.get_settings`"""
303323 super (DSSUserSettings , self ).__init__ (settings )
304324 self .client = client
305325 self .login = login
306326
327+ @property
328+ def admin_properties (self ):
329+ """
330+ The user properties (not editable by the user) for this user. Do not set this property, modify the dict in place
331+
332+ :rtype dict
333+ """
334+ return self .settings ["adminProperties" ]
335+
307336 def save (self ):
337+ """Saves the settings"""
308338 self .client ._perform_json ("PUT" , "/admin/users/%s" % self .login , body = self .settings )
309339
310340
311341class DSSOwnUserSettings (DSSUserSettingsBase ):
342+ """Settings for the current DSS user"""
343+
312344 def __init__ (self , client , settings ):
345+ """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_own_user`"""
313346 super (DSSOwnUserSettings , self ).__init__ (settings )
314347 self .client = client
315348
316349 def save (self ):
350+ """Saves the settings"""
317351 self .client ._perform_empty ("PUT" , "/current-user" , body = self .settings )
318352
319353
@@ -323,6 +357,7 @@ class DSSGroup(object):
323357 Do not create this directly, use :meth:`dataikuapi.DSSClient.get_group`
324358 """
325359 def __init__ (self , client , name ):
360+ """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_group`"""
326361 self .client = client
327362 self .name = name
328363
@@ -333,20 +368,14 @@ def __init__(self, client, name):
333368 def delete (self ):
334369 """
335370 Deletes the group
336- Note: this call requires an API key with admin rights
337371 """
338372 return self .client ._perform_empty (
339373 "DELETE" , "/admin/groups/%s" % self .name )
340374
341-
342- ########################################################
343- # User description
344- ########################################################
345-
375+
346376 def get_definition (self ):
347377 """
348378 Get the group's definition (name, description, admin abilities, type, ldap name mapping)
349- Note: this call requires an API key with admin rights
350379
351380 :return: the group's definition, as a dict
352381 """
@@ -356,7 +385,6 @@ def get_definition(self):
356385 def set_definition (self , definition ):
357386 """
358387 Set the group's definition.
359- Note: this call requires an API key with admin rights
360388
361389 You should only :meth:`set_definition` using an object that you obtained through :meth:`get_definition`,
362390 not create a new dict.
@@ -368,12 +396,14 @@ def set_definition(self, definition):
368396 "PUT" , "/admin/groups/%s" % self .name ,
369397 body = definition )
370398
399+
371400class DSSGeneralSettings (object ):
372401 """
373402 The general settings of the DSS instance.
374403 Do not create this directly, use :meth:`dataikuapi.DSSClient.get_general_settings`
375404 """
376405 def __init__ (self , client ):
406+ """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_general_settings`"""
377407 self .client = client
378408 self .settings = self .client ._perform_json ("GET" , "/admin/general-settings" )
379409
@@ -387,8 +417,7 @@ def save(self):
387417 Note: this call requires an API key with admin rights
388418 """
389419 return self .client ._perform_empty ("PUT" , "/admin/general-settings" , body = self .settings )
390-
391-
420+
392421 ########################################################
393422 # Value accessors
394423 ########################################################
@@ -761,7 +790,7 @@ class DSSCluster(object):
761790 A handle to interact with a cluster on the DSS instance
762791 """
763792 def __init__ (self , client , cluster_id ):
764- """Do not call that directly, use :meth:`dataikuapi.dss. DSSClient.get_cluster`"""
793+ """Do not call that directly, use :meth:`dataikuapi.DSSClient.get_cluster`"""
765794 self .client = client
766795 self .cluster_id = cluster_id
767796
0 commit comments