forked from dataiku/dataiku-api-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.py
More file actions
2767 lines (2097 loc) · 90.9 KB
/
Copy pathadmin.py
File metadata and controls
2767 lines (2097 loc) · 90.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from .future import DSSFuture
import json, warnings
from datetime import datetime
from ..utils import _timestamp_ms_to_zoned_datetime
class DSSConnectionListItem(dict):
"""
An item in a list of connections.
.. important::
Do not instantiate directly, use :meth:`dataikuapi.DSSClient.list_connections` instead.
"""
def __init__(self, client, data):
super(DSSConnectionListItem, self).__init__(data)
self.client = client
def to_connection(self):
"""
Gets a handle corresponding to this item
:rtype: :class:`DSSConnection`
"""
return DSSConnection(self.client, self["name"])
@property
def name(self):
"""
Get the identifier of the connection.
:rtype: string
"""
return self["id"]
@property
def type(self):
"""
Get the type of the connection.
:return: a DSS connection type, like PostgreSQL, EC2, Azure, ...
:rtype: string
"""
return self["label"]
class DSSConnectionInfo(dict):
"""
A class holding read-only information about a connection.
.. important::
Do not instantiate directly, use :meth:`DSSConnection.get_info` instead.
The main use case of this class is to retrieve the decrypted credentials for a connection,
if allowed by the connection permissions.
Depending on the connection kind, the credential may be available using :meth:`get_basic_credential`
or :meth:`get_aws_credential`.
"""
def __init__(self, data):
super(DSSConnectionInfo, self).__init__(data)
def get_type(self):
"""
Get the type of the connection
:return: a connection type, for example Azure, Snowflake, GCS, ...
:rtype: string
"""
return self["type"]
def get_credential_mode(self):
"""
Get the credential mode of the connection
:return: a connection mode
:rtype: string
"""
return self["credentialsMode"]
def get_params(self):
"""
Get the parameters of the connection, as a dict
:return: the parameters, as a dict. Each connection type has different sets of fields.
:rtype: dict
"""
return self["params"]
def get_resolved_params(self):
"""
Get the resolved parameters of the connection, as a dict. May be null depending on the connection type.
:return: the resolved parameters, as a dict. Each connection type has different sets of fields.
:rtype: dict
"""
return self["resolvedParams"]
def get_basic_credential(self):
"""
Get the basic credential (user/password pair) for this connection, if available
:return: the credential, as a dict containing "user" and "password"
:rtype: dict
"""
if not "resolvedBasicCredential" in self:
raise ValueError("No basic credential available")
return self["resolvedBasicCredential"]
def get_aws_credential(self):
"""
Get the AWS credential for this connection, if available.
The AWS credential can either be a keypair or a STS token triplet.
:return: the credential, as a dict containing "accessKey", "secretKey", and "sessionToken" (only in the case of STS token)
:rtype: dict
"""
if not "resolvedAWSCredential" in self:
raise ValueError("No AWS credential available")
return self["resolvedAWSCredential"]
def get_oauth2_credential(self):
"""
Get the OAUTH2 credential for this connection, if available.
:return: the credential, as a dict containing "accessToken"
:rtype: dict
"""
if not "resolvedOAuth2Credential" in self:
raise ValueError("No OAUTH2 credential available")
return self["resolvedOAuth2Credential"]
class DSSConnection(object):
"""
A connection on the DSS instance.
.. important::
Do not instantiate directly, use :meth:`dataikuapi.DSSClient.get_connection` instead.
"""
def __init__(self, client, name):
self.client = client
self.name = name
########################################################
# Location info
########################################################
def get_location_info(self):
"""
Get information about this connection.
.. caution::
Deprecated, use :meth:`~get_info()`
"""
warnings.warn("DSSConnection.get_location_info is deprecated, please use get_info", DeprecationWarning)
return self.get_info()
def get_info(self, contextual_project_key=None):
"""
Get information about this connection.
.. note::
This call requires permissions to read connection details
:param string contextual_project_key: (optional) project key to use to resolve variables
:return: an object containing connection information
:rtype: :class:`DSSConnectionInfo`
"""
additional_params = { "contextualProjectKey": contextual_project_key } if contextual_project_key is not None else None
return DSSConnectionInfo(self.client._perform_json(
"GET", "/connections/%s/info" % self.name, params=additional_params))
########################################################
# Connection deletion
########################################################
def delete(self):
"""
Delete the connection
"""
return self.client._perform_empty(
"DELETE", "/admin/connections/%s" % self.name)
def get_settings(self):
"""
Get the settings of the connection.
You must use :meth:`~DSSConnectionSettings.save()` on the returned object to make your changes effective
on the connection.
Usage example
.. code-block:: python
# make details of a connection accessible to some groups
connection = client.get_connection("my_connection_name")
settings = connection.get_settings()
readability = settings.details_readability
readability.set_readability(False, "group1", "group2")
settings.save()
:return: the settings of the connection
:rtype: :class:`DSSConnectionSettings`
"""
settings = self.client._perform_json(
"GET", "/admin/connections/%s" % self.name)
return DSSConnectionSettings(self, settings)
def get_definition(self):
"""
Get the connection's raw definition.
.. caution::
Deprecated, use :meth:`get_settings()` instead.
The exact structure of the returned dict is not documented and depends on the connection
type. Create connections using the DSS UI and call :meth:`get_definition` to see the
fields that are in it.
.. note::
This method returns a dict with passwords and secrets in their encrypted form. If you need
credentials, consider using :meth:`get_info()` and :meth:`dataikuapi.dss.admin.DSSConnectionInfo.get_basic_credential()`.
:return: a connection definition, as a dict. See :meth:`DSSConnectionSettings.get_raw()`
:rtype: dict
"""
return self.client._perform_json(
"GET", "/admin/connections/%s" % self.name)
def set_definition(self, definition):
"""
Set the connection's definition.
.. caution::
Deprecated, use :meth:`get_settings()` then :meth:`DSSConnectionSettings.save()` instead.
.. important::
You should only :meth:`set_definition` using an object that you obtained through :meth:`get_definition`,
not create a new dict.
Usage example
.. code-block:: python
# make details of a connection accessible to some groups
connection = client.get_connection("my_connection_name")
definition = connection.get_definition()
definition['detailsReadability']['readableBy'] = 'ALLOWED'
definition['detailsReadability']['allowedGroups'] = ['group1', 'group2']
connection.set_definition(definition)
:param dict definition: the definition for the connection, as a dict.
"""
return self.client._perform_json(
"PUT", "/admin/connections/%s" % self.name,
body = definition)
########################################################
# Security
########################################################
def sync_root_acls(self):
"""
Resync root permissions on this connection path.
This is only useful for HDFS connections when DSS has User Isolation activated with "DSS-managed HDFS ACL"
:return: a handle to the task of resynchronizing the permissions
:rtype: :class:`~dataikuapi.dss.future.DSSFuture`
"""
future_response = self.client._perform_json(
"POST", "/admin/connections/%s/sync" % self.name,
body = {'root':True})
return DSSFuture(self.client, future_response.get('jobId', None), future_response)
def sync_datasets_acls(self):
"""
Resync permissions on datasets in this connection path.
This is only useful for HDFS connections when DSS has User Isolation activated with "DSS-managed HDFS ACL"
:return: a handle to the task of resynchronizing the permissions
:rtype: :class:`~dataikuapi.dss.future.DSSFuture`
"""
future_response = self.client._perform_json(
"POST", "/admin/connections/%s/sync" % self.name,
body = {'root':True})
return DSSFuture(self.client, future_response.get('jobId', None), future_response)
class DSSConnectionSettings(object):
"""
Settings of a DSS connection.
.. important::
Do not instantiate directly, use :meth:`DSSConnection.get_settings` instead.
Use :meth:`save` to save your changes
"""
def __init__(self, connection, settings):
self.connection = connection
self.settings = settings
def get_raw(self):
"""
Get the raw settings of the connection.
:return: a connection definition, as a dict. Notable fields are:
* **type** : type of the connection (for example PostgreSQL, Azure, ...)
* **params** : dict of the parameters specific to the connection type
:rtype: dict
"""
return self.settings
@property
def type(self):
"""
Get the type of the connection.
:return: a DSS connection type, like PostgreSQL, EC2, Azure, ...
:rtype: string
"""
return self.settings['type']
@property
def allow_managed_datasets(self):
"""
Whether managed datasets can use the connection.
:rtype: boolean
"""
return self.settings['allowManagedDatasets']
@allow_managed_datasets.setter
def allow_managed_datasets(self, new_value):
self.settings["allowManagedDatasets"] = new_value
@property
def allow_managed_folders(self):
"""
Whether managed datasets can use the connection.
:rtype: boolean
"""
return self.settings['allowManagedFolders']
@allow_managed_folders.setter
def allow_managed_folders(self, new_value):
self.settings["allowManagedFolders"] = new_value
@property
def allow_knowledge_banks(self):
"""
Whether Knowledge Banks can use the connection.
:rtype: boolean
"""
return self.settings['allowKnowledgeBanks']
@allow_knowledge_banks.setter
def allow_knowledge_banks(self, new_value):
self.settings["allowKnowledgeBanks"] = new_value
@property
def allow_write(self):
"""
Whether data can be written to this connection.
If not, the connection is read-only from DSS point of view.
:rtype: boolean
"""
return self.settings['allowWrite']
@allow_write.setter
def allow_write(self, new_value):
self.settings["allowWrite"] = new_value
@property
def details_readability(self):
"""
Get the access control to connection details.
:return: an handle on the access control definition.
:rtype: :class:`DSSConnectionDetailsReadability`
"""
return DSSConnectionDetailsReadability(self.settings["detailsReadability"])
@property
def usable_by(self):
"""
Get the mode of access control.
This controls usage of the connection, that is, reading and/or writing data
from/to the connection.
:return: one ALL (anybody) or ALLOWED (ie. only users from groups in :meth:`usable_by_allowed_groups()`)
:rtype: string
"""
return self.settings["usableBy"]
@property
def usable_by_allowed_groups(self):
"""
Get the groups allowed to use the connection
Only applies if :meth:`usable_by()` is ALLOWED.
:return: a list of group names
:rtype: list[string]
"""
return self.settings["allowedGroups"]
def set_usability(self, all, *groups):
"""
Set who can use the connection.
:param boolean all: if True, anybody can use the connection
:param \*string groups: a list of groups that can use the connection
"""
if all:
self.settings["usableBy"] = 'ALL'
else:
self.settings["usableBy"] = 'ALLOWED'
self.settings["allowedGroups"] = groups
def save(self):
"""
Save the changes to the connection's settings
"""
self.connection.client._perform_json(
"PUT", "/admin/connections/%s" % self.connection.name,
body = self.settings)
class DSSConnectionDetailsReadability(object):
"""
Handle on settings for access to connection details.
Connection details mostly cover credentials, and giving access to the
credentials is necessary to some workloads. Typically, having Spark processes
access data directly implies giving credentials to these Spark processes,
which in turn implies that the user can access the connection's details.
"""
def __init__(self, data):
self._data = data
@property
def readable_by(self):
"""
Get the mode of access control.
:return: one of NONE (nobody), ALL (anybody) or ALLOWED (ie. only users from groups in :meth:`allowed_groups()`)
:rtype: string
"""
return self._data["readableBy"]
@property
def allowed_groups(self):
"""
Get the groups allowed to access connection details.
Only applies if :meth:`readable_by()` is ALLOWED.
:return: a list of group names
:rtype: list[string]
"""
return self._data["allowedGroups"]
def set_readability(self, all, *groups):
"""
Set who can get details from the connection.
To make the details readable by nobody, pass all=False and no group.
:param boolean all: if True, anybody can use the connection
:param \*string groups: a list of groups that can use the connection
"""
if all:
self._data["readableBy"] = 'ALL'
elif groups is None or len(groups) == 0:
self._data["readableBy"] = 'NONE'
else:
self._data["readableBy"] = 'ALLOWED'
self._data["allowedGroups"] = groups
class DSSUser(object):
"""
A handle for a user on the DSS instance.
.. important::
Do not instantiate directly, use :meth:`dataikuapi.DSSClient.get_user` instead.
"""
def __init__(self, client, login):
self.client = client
self.login = login
def delete(self):
"""
Deletes the user
"""
return self.client._perform_empty(
"DELETE", "/admin/users/%s" % self.login)
def get_settings(self):
"""
Get the settings of the user.
You must use :meth:`~DSSUserSettings.save()` on the returned object to make your changes effective
on the user.
Usage example
.. code-block:: python
# disable some user
user = client.get_user('the_user_login')
settings = user.get_settings()
settings.enabled = False
settings.save()
:return: the settings of the user
:rtype: :class:`DSSUserSettings`
"""
raw = self.client._perform_json("GET", "/admin/users/%s" % self.login)
return DSSUserSettings(self.client, self.login, raw)
def get_activity(self):
"""
Gets the activity of the user.
:return: the user's activity
:rtype: :class:`DSSUserActivity`
"""
activity = self.client._perform_json("GET", "/admin/users/%s/activity" % self.login)
return DSSUserActivity(self.client, self.login, activity)
########################################################
# Supplier interaction
########################################################
def start_resync_from_supplier(self):
"""
Starts a resync of the user from an external supplier (LDAP, Azure AD or custom auth)
:return: a :class:`dataikuapi.dss.future.DSSFuture` representing the sync process
:rtype: :class:`dataikuapi.dss.future.DSSFuture`
"""
future_resp = self.client._perform_json("POST", "/admin/users/%s/actions/resync" % self.login)
return DSSFuture.from_resp(self.client, future_resp)
########################################################
# Legacy
########################################################
def get_definition(self):
"""
Get the definition of the user
.. caution::
Deprecated, use :meth:`get_settings` instead
:return: the user's definition, as a dict. Notable fields are
* **login** : identifier of the user, can't be modified
* **enabled** : whether the user can log into DSS
* **groups** : list of group names this user belongs to
:rtype: dict
"""
warnings.warn("DSSUser.get_definition is deprecated, please use get_settings", DeprecationWarning)
return self.client._perform_json("GET", "/admin/users/%s" % self.login)
def set_definition(self, definition):
"""
Set the user's definition.
.. caution::
Deprecated, use :meth:`dataikuapi.dss.admin.DSSUserSettings.save()` instead
.. important::
You should only use :meth:`set_definition` with an object that you obtained through :meth:`get_definition`,
not create a new dict.
.. note::
This call requires an API key with admin rights
The fields that may be changed in a user definition are:
* email
* displayName
* enabled
* groups
* userProfile
* password (not returned by :meth:`get_definition()` but can be set)
* userProperties
* adminProperties
* secrets
* credentials
:param dict definition: the definition for the user, as a dict
"""
warnings.warn("DSSUser.set_definition is deprecated, please use get_settings", DeprecationWarning)
return self.client._perform_json("PUT", "/admin/users/%s" % self.login, body = definition)
def get_client_as(self):
"""
Get an API client that has the permissions of this user.
This allows administrators to impersonate actions on behalf of other users, in order to perform
actions on their behalf.
:return: a client through which calls will be run as the user
:rtype: :class:`dataikuapi.DSSClient`
"""
from dataikuapi.dssclient import DSSClient
if self.client.api_key is not None:
return DSSClient(self.client.host, self.client.api_key, extra_headers={"X-DKU-ProxyUser": self.login}, no_check_certificate=not self.client._session.verify)
elif self.client.internal_ticket is not None:
verify = self.client._session.verify
no_check_certificate = verify if isinstance(verify, str) else not verify
return DSSClient(self.client.host, internal_ticket = self.client.internal_ticket,
extra_headers={"X-DKU-ProxyUser": self.login}, no_check_certificate=no_check_certificate)
else:
raise ValueError("Don't know how to proxy this client")
class DSSOwnUser(object):
"""
A handle to interact with your own user
.. important::
Do not instantiate directly, use :meth:`dataikuapi.DSSClient.get_own_user` instead.
"""
def __init__(self, client):
self.client = client
def get_settings(self):
"""
Get your own settings
You must use :meth:`~DSSOwnUserSettings.save()` on the returned object to make your changes effective
on the user.
:rtype: :class:`DSSOwnUserSettings`
"""
raw = self.client._perform_json("GET", "/current-user")
return DSSOwnUserSettings(self.client, raw)
class DSSUserSettingsBase(object):
"""
Settings for a DSS user.
.. important::
Do not instantiate directly, use :meth:`DSSUser.get_settings` or :meth:`DSSOwnUser.get_settings` instead.
"""
def __init__(self, settings):
self.settings = settings
def get_raw(self):
"""
Get the raw settings of the user.
Modifications made to the returned object are reflected when saving.
:return: the dict of the settings (not a copy). Notable fields are:
* **login** : identifier of the user, can't be modified
* **enabled** : whether the user can log into DSS
* **groups** : list of group names this user belongs to
* **trialStatus**: The trial status of the user, with the following keys:
- exists: True if this user is or was on trial
- expired: True if the trial period has expired
- valid: True if the trial is valid (for ex, has not expired and the license allows it)
- expiresOn: Date (ms since epoch) when the trial will expire
- grantedOn: Date (ms since epoch) when the trial was granted
:rtype: dict
"""
return self.settings
def add_secret(self, name, value):
"""
Add a user secret.
If there was already a secret with the same name, it is replaced
:param string name: name of the secret
:param string value: name of the value
"""
self.remove_secret(name)
return self.settings["secrets"].append({"name": name, "value": value, "secret": True})
def remove_secret(self, name):
"""
Remove a user secret based on its name
If no secret of the given name exists, the method does nothing.
:param string name: name of the secret
"""
self.settings["secrets"] = [x for x in self.settings["secrets"] if x["name"] != name]
@property
def user_properties(self):
"""
Get the user properties for this user.
.. important::
Do not set this property, modify the dict in place
User properties can be seen and modified by the user themselves. A contrario admin
properties are for administrators' eyes only.
:rtype: dict
"""
return self.settings["userProperties"]
def set_basic_connection_credential(self, connection, login, password):
"""
Set per-user-credentials for a connection that takes a user/password pair.
:param string connection: name of the connection
:param string login: login of the credentials
:param string password: password of the credentials
"""
self.settings["credentials"][connection] = {
"type": "BASIC",
"user": login,
"password": password
}
def remove_connection_credential(self,connection):
"""
Remove per-user-credentials for a connection
If no credentials for the givent connection exists, this method does nothing
:param string connection: name of the connection
"""
if connection in self.settings["credentials"]:
del self.settings["credentials"][connection]
def set_basic_plugin_credential(self, plugin_id, param_set_id, preset_id, param_name, login, password):
"""
Set per-user-credentials for a plugin preset that takes a user/password pair
:param string plugin_id: identifier of the plugin
:param string param_set_id: identifier of the parameter set to which the preset belongs
:param string preset_id: identifier of the preset
:param string param_name: name of the credentials parameter in the preset
:param string login: login of the credentials
:param string password: password of the credentials
"""
name = json.dumps(["PLUGIN", plugin_id, param_set_id, preset_id, param_name])[1:-1]
self.settings["credentials"][name] = {
"type": "BASIC",
"user": login,
"password": password
}
def set_oauth2_plugin_credential(self, plugin_id, param_set_id, preset_id, param_name, refresh_token):
"""
Set per-user-credentials for a plugin preset that takes a OAuth refresh token
:param string plugin_id: identifier of the plugin
:param string param_set_id: identifier of the parameter set to which the preset belongs
:param string preset_id: identifier of the preset
:param string param_name: name of the credentials parameter in the preset
:param string refresh_token: value of the refresh token
"""
name = json.dumps(["PLUGIN", plugin_id, param_set_id, preset_id, param_name])[1:-1]
self.settings["credentials"][name] = {
"type": "OAUTH_REFRESH_TOKEN",
"refreshToken": refresh_token
}
def remove_plugin_credential(self, plugin_id, param_set_id, preset_id, param_name):
"""
Remove per-user-credentials for a plugin preset
:param string plugin_id: identifier of the plugin
:param string param_set_id: identifier of the parameter set to which the preset belongs
:param string preset_id: identifier of the preset
:param string param_name: name of the credentials parameter in the preset
"""
name = json.dumps(["PLUGIN", plugin_id, param_set_id, preset_id, param_name])[1:-1]
if name in self.settings["credentials"]:
del self.settings["credentials"][name]
class DSSUserPreferences(object):
"""
Preferences for a DSS user.
.. important::
Do not instantiate directly, use :meth:`DSSUserSettings.preferences` instead.
"""
def __init__(self, preferences):
self.preferences = preferences
@property
def ui_language(self):
"""
Get or set the language used in the Web User Interface for this user. Valid values are "en" (English) and "ja" (Japanese)
:rtype: str
"""
return self.preferences['uiLanguage']
@ui_language.setter
def ui_language(self, new_value):
self.preferences["uiLanguage"] = new_value
class DSSUserSettings(DSSUserSettingsBase):
"""
Settings for a DSS user.
.. important::
Do not instantiate directly, use :meth:`DSSUser.get_settings` instead.
"""
def __init__(self, client, login, settings):
super(DSSUserSettings, self).__init__(settings)
self.client = client
self.login = login
@property
def admin_properties(self):
"""
Get the admin properties for this user.
.. important::
Do not set this property, modify the dict in place
Admin properties can be seen and modified only by administrators, not by the user themselves.
:rtype: dict
"""
return self.settings["adminProperties"]
@property
def enabled(self):
"""
Whether this user is enabled.
:rtype: boolean
"""
return self.settings["enabled"]
@enabled.setter
def enabled(self, new_value):
self.settings["enabled"] = new_value
@property
def creation_date(self):
"""
Get the timestamp of when the user was created
:return: the creation date
:rtype: :class:`datetime.datetime` or None
"""
timestamp = self.settings["creationDate"] if "creationDate" in self.settings else None
return _timestamp_ms_to_zoned_datetime(timestamp)
@property
def preferences(self):
"""
Get the preferences for this user
:return: user preferences
:rtype: :class:`DSSUserPreferences`
"""
return DSSUserPreferences(self.settings["preferences"])
def save(self):
"""
Saves the settings
"""
self.client._perform_json("PUT", "/admin/users/%s" % self.login, body = self.settings)
class DSSOwnUserSettings(DSSUserSettingsBase):
"""
Settings for the current DSS user.
.. important::
Do not instantiate directly, use :meth:`DSSOwnUser.get_settings()` instead.
"""
def __init__(self, client, settings):
super(DSSOwnUserSettings, self).__init__(settings)
self.client = client
def save(self):
"""
Saves the settings
"""
self.client._perform_empty("PUT", "/current-user", body = self.settings)
class DSSUserActivity(object):
"""
Activity for a DSS user.
.. important::
Do not instantiate directly, use :meth:`DSSUser.get_activity` or :meth:`dataikuapi.DSSClient.list_users_activity()` instead.
"""
def __init__(self, client, login, activity):
self.client = client
self.login = login
self.activity = activity
def get_raw(self):
"""
Get the raw activity of the user as a dict.
:return: the raw activity. Fields are
* **login** : the login of the user for this activity
* **lastSuccessfulLogin** : timestamp in milliseconds of the last time the user logged into DSS
* **lastFailedLogin** : timestamp in milliseconds of the last time DSS recorded a login failure for this user
* **lastSessionActivity** : timestamp in milliseconds of the last time the user opened a tab
:rtype: dict
"""
return self.activity
@property
def last_successful_login(self):
"""
Get the last successful login of the user
Returns None if there was no successful login for this user.
:return: the last successful login
:rtype: :class:`datetime.datetime` or None
"""
timestamp = self.activity["lastSuccessfulLogin"]
return _timestamp_ms_to_zoned_datetime(timestamp)
@property
def last_failed_login(self):
"""
Get the last failed login of the user
Returns None if there were no failed login for this user.
:return: the last failed login
:rtype: :class:`datetime.datetime` or None
"""
timestamp = self.activity["lastFailedLogin"]
return _timestamp_ms_to_zoned_datetime(timestamp)
@property
def last_session_activity(self):
"""
Get the last session activity of the user
The last session activity is the last time the user opened a new DSS tab or
refreshed his session.
Returns None if there is no session activity yet.
:return: the last session activity
:rtype: :class:`datetime.datetime` or None
"""
timestamp = self.activity["lastSessionActivity"]
return _timestamp_ms_to_zoned_datetime(timestamp)