Skip to content

Commit 8f166af

Browse files
authored
Merge pull request #161 from dataiku/chore/dss10-clarify-get-variable-apis
Chore/dss10 clarify get variable apis
2 parents acdcd4c + 3a3788c commit 8f166af

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

dataikuapi/dss/admin.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,28 @@ def get_raw(self):
12081208
"""
12091209
return self.status
12101210

1211+
1212+
class DSSInstanceVariables(dict):
1213+
"""
1214+
Dict containing the instance variables. The variables can be modified directly in the dict and persisted using its :meth:`save` method.
1215+
1216+
Do not create this directly, use :meth:`dataikuapi.DSSClient.get_global_variables`
1217+
"""
1218+
1219+
def __init__(self, client, variables):
1220+
super(dict, self).__init__()
1221+
self.update(variables)
1222+
self.client = client
1223+
1224+
def save(self):
1225+
"""
1226+
Save the changes made to the instance variables.
1227+
1228+
Note: this call requires an API key with admin rights.
1229+
"""
1230+
return self.client._perform_empty("PUT", "/admin/variables/", body=self)
1231+
1232+
12111233
class DSSGlobalUsageSummary(object):
12121234
"""
12131235
The summary of the usage of the DSS instance.

dataikuapi/dssclient.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import json
1+
import json, warnings
22

33
from requests import Session
44
from requests import exceptions
@@ -10,7 +10,7 @@
1010
from .dss.project import DSSProject
1111
from .dss.app import DSSApp
1212
from .dss.plugin import DSSPlugin
13-
from .dss.admin import DSSUser, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSGlobalUsageSummary
13+
from .dss.admin import DSSUser, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSGlobalUsageSummary, DSSInstanceVariables
1414
from .dss.meaning import DSSMeaning
1515
from .dss.sqlquery import DSSSQLQuery
1616
from .dss.discussion import DSSObjectDiscussions
@@ -48,7 +48,7 @@ def __init__(self, host, api_key=None, internal_ticket = None, extra_headers = N
4848
########################################################
4949
# Futures
5050
########################################################
51-
51+
5252
def list_futures(self, as_objects=False, all_users=False):
5353
"""
5454
List the currently-running long tasks (a.k.a futures)
@@ -775,18 +775,27 @@ def get_global_usage_summary(self, with_per_project=False):
775775
########################################################
776776

777777
def get_variables(self):
778+
"""
779+
Deprecated. Use :meth:`get_global_variables`
780+
"""
781+
warnings.warn("get_variables is deprecated, please use get_global_variables", DeprecationWarning)
782+
return self.get_global_variables()
783+
784+
def get_global_variables(self):
778785
"""
779786
Get the DSS instance's variables, as a Python dictionary
780787
781788
This call requires an API key with admin rights
782-
783-
:returns: a Python dictionary of the instance-level variables
789+
790+
:returns: A :class:`dataikuapi.dss.admin.DSSInstanceVariables` handle
784791
"""
785-
return self._perform_json(
786-
"GET", "/admin/variables/")
792+
variables = self._perform_json("GET", "/admin/variables/")
793+
return DSSInstanceVariables(self, variables)
787794

788795
def set_variables(self, variables):
789796
"""
797+
Deprecated. Use :meth:`get_global_variables` and :meth:`dataikuapi.dss.admin.DSSInstanceVariables.save`
798+
790799
Updates the DSS instance's variables
791800
792801
This call requires an API key with admin rights
@@ -797,8 +806,24 @@ def set_variables(self, variables):
797806
:param dict variables: the new dictionary of all variables of the instance
798807
799808
"""
800-
return self._perform_empty(
801-
"PUT", "/admin/variables/", body=variables)
809+
warnings.warn("set_variables is deprecated, please use get_global_variables().save()", DeprecationWarning)
810+
return DSSInstanceVariables(self, variables).save()
811+
812+
def get_resolved_variables(self, project_key=None, typed=False):
813+
"""
814+
Get a dictionary of resolved variables of the project.
815+
816+
:param str project_key: the project key, defaults to the current project if any
817+
:param bool typed: if True, the variable values will be typed in the returned dict, defaults to False
818+
:returns: a dictionary with instance and project variables merged
819+
"""
820+
import dataiku
821+
return self._perform_json(
822+
"GET",
823+
"/projects/%s/variables-resolved" % (dataiku.default_project_key() if project_key is None else project_key),
824+
params={
825+
"typed": "true" if typed else "false"
826+
})
802827

803828

804829
########################################################
@@ -960,7 +985,7 @@ def get_auth_info_from_browser_headers(self, headers_dict, with_secrets=False):
960985
"""
961986
return self._perform_json("POST", "/auth/info-from-browser-headers",
962987
params={"withSecrets": with_secrets}, body=headers_dict)
963-
988+
964989
def get_ticket_from_browser_headers(self, headers_dict):
965990
"""
966991
Returns a ticket for the DSS user authenticated by the dictionary of

0 commit comments

Comments
 (0)