diff --git a/databricks_cli/sdk/api_client.py b/databricks_cli/sdk/api_client.py index eebd9581..b1c1026b 100644 --- a/databricks_cli/sdk/api_client.py +++ b/databricks_cli/sdk/api_client.py @@ -50,6 +50,7 @@ from urllib3 import exceptions from urllib3.util.retry import Retry +from databricks_cli.sdk.version import UC_API_VERSION from databricks_cli.version import version as databricks_cli_version class TlsV1HttpAdapter(HTTPAdapter): @@ -152,9 +153,15 @@ def get_url(self, path, version=None): return self.url + version + path elif self.jobs_api_version and path and path.startswith('/jobs'): return self.url + self.jobs_api_version + path + elif path and _is_uc_path(path): + return self.url + UC_API_VERSION + path return self.url + self.api_version + path +def _is_uc_path(path): + return path.startswith('/unity-catalog') or path.startswith('/lineage-tracking') + + def _translate_boolean_to_query_param(value): assert not isinstance(value, list), 'GET parameters cannot pass list of objects' if isinstance(value, bool): diff --git a/databricks_cli/sdk/version.py b/databricks_cli/sdk/version.py index b5eb50ec..a9bfa366 100644 --- a/databricks_cli/sdk/version.py +++ b/databricks_cli/sdk/version.py @@ -23,5 +23,7 @@ API_VERSION = '2.0' +UC_API_VERSION = '2.1' + # Available API versions API_VERSIONS = ['2.0', '2.1'] diff --git a/examples/unity_catalog/replace-permissions1.json b/examples/unity_catalog/replace-permissions1.json deleted file mode 100644 index 4268031f..00000000 --- a/examples/unity_catalog/replace-permissions1.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "privilege_assignments": [ - { - "privileges": [ - "SELECT", - "USAGE" - ], - "principal": "foo@bar.com" - }, - { - "privileges": [ - "OWN", - "MODIFY" - ], - "principal": "some_group" - } - ] -} diff --git a/tests/sdk/test_api_client.py b/tests/sdk/test_api_client.py index d65a3f16..163d0c2c 100644 --- a/tests/sdk/test_api_client.py +++ b/tests/sdk/test_api_client.py @@ -108,6 +108,12 @@ def test_get_url(): assert client.get_url('/endpoint') == 'https://databricks.com/api/2.0/endpoint' assert client.get_url('/jobs/list') == 'https://databricks.com/api/2.1/jobs/list' assert client.get_url('/jobs/list', '3.0') == 'https://databricks.com/api/3.0/jobs/list' + # Check that UC APIs use '2.1' + assert client.get_url('/unity-catalog/catalogs') == \ + 'https://databricks.com/api/2.1/unity-catalog/catalogs' + # Can override version for UC API + assert client.get_url('/unity-catalog/catalogs', '2.0') == \ + 'https://databricks.com/api/2.0/unity-catalog/catalogs' def test_api_client_url_parsing():