dasl-client 1.0.27__py3-none-any.whl → 1.0.28__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dasl-client might be problematic. Click here for more details.
- dasl_client/client.py +79 -15
- dasl_client/metadata.py +74 -0
- {dasl_client-1.0.27.dist-info → dasl_client-1.0.28.dist-info}/METADATA +2 -2
- {dasl_client-1.0.27.dist-info → dasl_client-1.0.28.dist-info}/RECORD +7 -6
- {dasl_client-1.0.27.dist-info → dasl_client-1.0.28.dist-info}/WHEEL +0 -0
- {dasl_client-1.0.27.dist-info → dasl_client-1.0.28.dist-info}/licenses/LICENSE +0 -0
- {dasl_client-1.0.27.dist-info → dasl_client-1.0.28.dist-info}/top_level.txt +0 -0
dasl_client/client.py
CHANGED
|
@@ -29,6 +29,7 @@ from dasl_client.auth.auth import (
|
|
|
29
29
|
DatabricksTokenAuth,
|
|
30
30
|
ServiceAccountKeyAuth,
|
|
31
31
|
)
|
|
32
|
+
from dasl_client.metadata import WorkspaceMetadata
|
|
32
33
|
from dasl_client.conn.conn import get_base_conn
|
|
33
34
|
from dasl_client.errors.errors import ConflictError, error_handler
|
|
34
35
|
from .helpers import Helpers
|
|
@@ -79,7 +80,7 @@ class Client:
|
|
|
79
80
|
service_principal_id: str,
|
|
80
81
|
service_principal_secret: str,
|
|
81
82
|
workspace_url: Optional[str] = None,
|
|
82
|
-
region: str =
|
|
83
|
+
region: Optional[str] = None,
|
|
83
84
|
dasl_host: Optional[str] = None,
|
|
84
85
|
) -> "Client":
|
|
85
86
|
"""
|
|
@@ -98,18 +99,24 @@ class Client:
|
|
|
98
99
|
being registered. If you omit this value, it will be inferred
|
|
99
100
|
if you are running within a Databricks notebook. Otherwise, an
|
|
100
101
|
exception will be raised.
|
|
101
|
-
:param region: The name of the DASL region.
|
|
102
|
+
:param region: The name of the DASL region. If not specified,
|
|
103
|
+
the client will auto-detect the region from the workspace
|
|
104
|
+
URL. For a DASL region, this includes the cloud host, e.g.
|
|
105
|
+
aws-us-east-1.
|
|
102
106
|
:param dasl_host: The URL of the DASL server. This value should
|
|
103
107
|
not generally be specified. When specified, this value
|
|
104
|
-
overrides region.
|
|
108
|
+
overrides both region and auto-detection.
|
|
105
109
|
:returns: Client for the newly created workspace.
|
|
106
110
|
"""
|
|
107
|
-
if dasl_host is None:
|
|
108
|
-
dasl_host = Regions.lookup(region)
|
|
109
|
-
|
|
110
111
|
with error_handler():
|
|
111
112
|
if workspace_url is None:
|
|
112
113
|
workspace_url = Helpers.current_workspace_url()
|
|
114
|
+
|
|
115
|
+
# Determine the DASL host to use
|
|
116
|
+
dasl_host = Client._dasl_host_from_workspace_metadata(
|
|
117
|
+
workspace_url, dasl_host, region
|
|
118
|
+
)
|
|
119
|
+
|
|
113
120
|
admin_config = AdminConfig(
|
|
114
121
|
workspace_url=workspace_url,
|
|
115
122
|
app_client_id=app_client_id,
|
|
@@ -137,7 +144,7 @@ class Client:
|
|
|
137
144
|
def for_workspace(
|
|
138
145
|
workspace_url: Optional[str] = None,
|
|
139
146
|
service_account_token: Optional[str] = None,
|
|
140
|
-
region: str =
|
|
147
|
+
region: Optional[str] = None,
|
|
141
148
|
dasl_host: Optional[str] = None,
|
|
142
149
|
) -> "Client":
|
|
143
150
|
"""
|
|
@@ -151,19 +158,24 @@ class Client:
|
|
|
151
158
|
:param service_account_token: Antimatter service account token.
|
|
152
159
|
If provided, the client will use this token for auth instead
|
|
153
160
|
of (automatic) secret-based auth.
|
|
154
|
-
:param region: The name of the DASL region.
|
|
161
|
+
:param region: The name of the DASL region. If not specified,
|
|
162
|
+
the client will auto-detect the region from the workspace
|
|
163
|
+
URL. For a DASL region, this includes the cloud host, e.g.
|
|
164
|
+
aws-us-east-1.
|
|
155
165
|
:param dasl_host: The URL of the DASL server. This value should
|
|
156
166
|
not generally be specified. When specified, this value
|
|
157
|
-
overrides region.
|
|
167
|
+
overrides both region and auto-detection.
|
|
158
168
|
:returns: Client for the existing workspace.
|
|
159
169
|
"""
|
|
160
|
-
if dasl_host is None:
|
|
161
|
-
dasl_host = Regions.lookup(region)
|
|
162
|
-
|
|
163
170
|
with error_handler():
|
|
164
171
|
if workspace_url is None:
|
|
165
172
|
workspace_url = Helpers.current_workspace_url()
|
|
166
173
|
|
|
174
|
+
# Determine the DASL host to use
|
|
175
|
+
dasl_host = Client._dasl_host_from_workspace_metadata(
|
|
176
|
+
workspace_url, dasl_host, region
|
|
177
|
+
)
|
|
178
|
+
|
|
167
179
|
if service_account_token is None:
|
|
168
180
|
return Client(
|
|
169
181
|
DatabricksSecretAuth(
|
|
@@ -188,7 +200,7 @@ class Client:
|
|
|
188
200
|
service_principal_secret: str,
|
|
189
201
|
workspace_url: Optional[str] = None,
|
|
190
202
|
service_account_token: Optional[str] = None,
|
|
191
|
-
region: str =
|
|
203
|
+
region: Optional[str] = None,
|
|
192
204
|
dasl_host: Optional[str] = None,
|
|
193
205
|
) -> "Client":
|
|
194
206
|
"""
|
|
@@ -220,10 +232,13 @@ class Client:
|
|
|
220
232
|
If provided, the client will use this token for auth instead
|
|
221
233
|
of (automatic) secret-based auth. Ignored if the workspace
|
|
222
234
|
doesn't exist.
|
|
223
|
-
:param region: The name of the DASL region.
|
|
235
|
+
:param region: The name of the DASL region. If not specified,
|
|
236
|
+
the client will auto-detect the region from the workspace
|
|
237
|
+
URL. For a DASL region, this includes the cloud host, e.g.
|
|
238
|
+
aws-us-east-1.
|
|
224
239
|
:param dasl_host: The URL of the DASL server. This value should
|
|
225
240
|
not generally be specified. When specified, this value
|
|
226
|
-
overrides region.
|
|
241
|
+
overrides both region and auto-detection.
|
|
227
242
|
:returns: Client for the newly created or existing workspace.
|
|
228
243
|
"""
|
|
229
244
|
try:
|
|
@@ -990,3 +1005,52 @@ class Client:
|
|
|
990
1005
|
"""
|
|
991
1006
|
with error_handler():
|
|
992
1007
|
return self._dbui_client().dbui_v1_query_cancel(self._workspace(), id)
|
|
1008
|
+
|
|
1009
|
+
@staticmethod
|
|
1010
|
+
def _dasl_host_from_workspace_metadata(
|
|
1011
|
+
workspace_url: str, dasl_host: Optional[str], region: Optional[str]
|
|
1012
|
+
) -> str:
|
|
1013
|
+
"""
|
|
1014
|
+
If the dasl_host is already set, it will be returned as-is. If a region
|
|
1015
|
+
is set, this will return the host that region maps to. If neither are
|
|
1016
|
+
set, this gets the DASL host from the workspace URL with a workspace
|
|
1017
|
+
metadata lookup.
|
|
1018
|
+
|
|
1019
|
+
:param workspace_url: The full base URL of the Databricks workspace
|
|
1020
|
+
being registered. If you omit this value, it will be inferred
|
|
1021
|
+
if you are running within a Databricks notebook. Otherwise, an
|
|
1022
|
+
exception will be raised.
|
|
1023
|
+
:param dasl_host: The URL of the DASL server. This value should
|
|
1024
|
+
not generally be specified. When specified, this value
|
|
1025
|
+
overrides both region and auto-detection.
|
|
1026
|
+
:param region: The name of the DASL region. If not specified,
|
|
1027
|
+
the client will auto-detect the region from the workspace
|
|
1028
|
+
URL. For a DASL region, this includes the cloud host, e.g.
|
|
1029
|
+
aws-us-east-1.
|
|
1030
|
+
:return: The DASL host to use.
|
|
1031
|
+
"""
|
|
1032
|
+
if dasl_host is None:
|
|
1033
|
+
if region is not None:
|
|
1034
|
+
# Use explicit region
|
|
1035
|
+
dasl_host = Regions.lookup(region)
|
|
1036
|
+
else:
|
|
1037
|
+
# Attempt auto-detection from workspace URL
|
|
1038
|
+
try:
|
|
1039
|
+
metadata = WorkspaceMetadata.get_workspace_metadata(workspace_url)
|
|
1040
|
+
if metadata is not None:
|
|
1041
|
+
dasl_host = metadata.api_url
|
|
1042
|
+
else:
|
|
1043
|
+
raise Exception(
|
|
1044
|
+
f"Could not determine API endpoint for workspace '{workspace_url}'. "
|
|
1045
|
+
f"The workspace may not be in a supported region. "
|
|
1046
|
+
f"Please specify 'region' or 'dasl_host' explicitly."
|
|
1047
|
+
)
|
|
1048
|
+
except Exception as e:
|
|
1049
|
+
if "Could not determine API endpoint" in str(e):
|
|
1050
|
+
raise
|
|
1051
|
+
else:
|
|
1052
|
+
raise Exception(
|
|
1053
|
+
f"Failed to auto-detect API endpoint for workspace '{workspace_url}': {e}. "
|
|
1054
|
+
f"Please specify 'region' or 'dasl_host' explicitly."
|
|
1055
|
+
)
|
|
1056
|
+
return dasl_host
|
dasl_client/metadata.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from dasl_api import ApiClient, Configuration, WorkspaceV1Api
|
|
5
|
+
from dasl_api.models import WorkspaceV1WorkspaceMetadata
|
|
6
|
+
from dasl_api.exceptions import ApiException
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class WorkspaceMetadata:
|
|
10
|
+
"""Workspace metadata lookup functionality for auto-detecting API endpoints."""
|
|
11
|
+
|
|
12
|
+
@staticmethod
|
|
13
|
+
def get_workspace_metadata(
|
|
14
|
+
workspace_url: str, dasl_host: Optional[str] = None
|
|
15
|
+
) -> Optional[WorkspaceV1WorkspaceMetadata]:
|
|
16
|
+
"""
|
|
17
|
+
Query the workspace metadata endpoint to auto-detect the correct region
|
|
18
|
+
and API endpoint for a given Databricks workspace.
|
|
19
|
+
|
|
20
|
+
:param workspace_url: The Databricks workspace URL to lookup
|
|
21
|
+
:param dasl_host: Optional DASL host to use for the lookup. If None, uses default region.
|
|
22
|
+
:returns: WorkspaceV1WorkspaceMetadata if successful, None if workspace not found
|
|
23
|
+
"""
|
|
24
|
+
if dasl_host is None:
|
|
25
|
+
# Use default region for metadata lookup
|
|
26
|
+
from .regions import Regions
|
|
27
|
+
from .helpers import Helpers
|
|
28
|
+
|
|
29
|
+
dasl_host = Regions.lookup(Helpers.default_region)
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
# Create an unauthenticated client for the public metadata endpoint
|
|
33
|
+
configuration = Configuration(host=dasl_host)
|
|
34
|
+
api_client = ApiClient(configuration)
|
|
35
|
+
workspace_api = WorkspaceV1Api(api_client)
|
|
36
|
+
|
|
37
|
+
# Base64 encode the workspace URL
|
|
38
|
+
encoded_workspace = base64.urlsafe_b64encode(
|
|
39
|
+
workspace_url.encode()
|
|
40
|
+
).decode()
|
|
41
|
+
|
|
42
|
+
# Call the metadata endpoint
|
|
43
|
+
metadata = workspace_api.workspace_v1_get_workspace_metadata(
|
|
44
|
+
databricks_workspace=encoded_workspace
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return metadata
|
|
48
|
+
|
|
49
|
+
except ApiException as e:
|
|
50
|
+
if e.status == 404:
|
|
51
|
+
# Workspace not found or not in supported region
|
|
52
|
+
return None
|
|
53
|
+
elif e.status == 400:
|
|
54
|
+
# Invalid workspace URL
|
|
55
|
+
raise ValueError(f"Invalid workspace URL: {workspace_url}")
|
|
56
|
+
else:
|
|
57
|
+
# Other API errors
|
|
58
|
+
raise Exception(f"Failed to get workspace metadata: {e}")
|
|
59
|
+
except Exception as e:
|
|
60
|
+
# Network errors, encoding errors, etc.
|
|
61
|
+
raise Exception(f"Failed to lookup workspace metadata: {e}")
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def get_endpoint_for_workspace(workspace_url: str) -> Optional[str]:
|
|
65
|
+
"""
|
|
66
|
+
Get the API endpoint URL for a workspace.
|
|
67
|
+
|
|
68
|
+
:param workspace_url: The Databricks workspace URL
|
|
69
|
+
:returns: API endpoint URL if successful, None if workspace not found
|
|
70
|
+
"""
|
|
71
|
+
metadata = WorkspaceMetadata.get_workspace_metadata(workspace_url)
|
|
72
|
+
if metadata is not None:
|
|
73
|
+
return metadata.api_url
|
|
74
|
+
return None
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dasl_client
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.28
|
|
4
4
|
Summary: The DASL client library used for interacting with the DASL workspace
|
|
5
5
|
Author-email: Antimatter Team <support@antimatter.io>
|
|
6
6
|
Requires-Python: >=3.8
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
License-File: LICENSE
|
|
9
|
-
Requires-Dist: dasl_api==0.1.
|
|
9
|
+
Requires-Dist: dasl_api==0.1.27
|
|
10
10
|
Requires-Dist: databricks-sdk>=0.41.0
|
|
11
11
|
Requires-Dist: pydantic>=2
|
|
12
12
|
Requires-Dist: typing_extensions>=4.10.0
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
dasl_client/__init__.py,sha256=MuaH74tnEHwfymHtlK6GqeMHRRWaSDfS6hSzbMrd7iQ,150
|
|
2
|
-
dasl_client/client.py,sha256=
|
|
2
|
+
dasl_client/client.py,sha256=WRQsJxMAleaGLV12O1NwKa5LrsGygNGidMuhEQZ87MA,42242
|
|
3
3
|
dasl_client/exec_rule.py,sha256=kn-Yo-9L0fjxbulyAghiIKO1SYcqv2XHZn45F8FvUzE,3599
|
|
4
4
|
dasl_client/helpers.py,sha256=kdOoNiyoVzfDHAZ5DGg5YTU4Fj9A5a8gz2RljrY8hbY,1095
|
|
5
|
+
dasl_client/metadata.py,sha256=GlPkkwfTBXSr3RnTYB8E2Y-weLnrVOBe2oYCFiwl8o0,2827
|
|
5
6
|
dasl_client/regions.json,sha256=Rvs_gslMuaod_n6LYLLrTAugtr7VNTljnFUiKf_0qNA,137
|
|
6
7
|
dasl_client/regions.py,sha256=1TIlyJ4iMLsfgeb0ShQsfsju2_NBSXnMAfjdSNMQgi8,442
|
|
7
8
|
dasl_client/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -25,8 +26,8 @@ dasl_client/types/helpers.py,sha256=gLGTvrssAKrdkQT9h80twEosld2egwhvj-zAudxWFPs,
|
|
|
25
26
|
dasl_client/types/rule.py,sha256=5zvRsqzsej5kYTFjIpP1lptb3Rtit06cxvA4sl89OMU,28734
|
|
26
27
|
dasl_client/types/types.py,sha256=DeUOfdYGOhUGEy7yKOfo0OYTXYRrs57yYgNLUbu7Tlc,8806
|
|
27
28
|
dasl_client/types/workspace_config.py,sha256=XkSmeuOA3OPpWQkx7apPcPNuD4Ai2QO3YKU-aFoOW8k,31030
|
|
28
|
-
dasl_client-1.0.
|
|
29
|
-
dasl_client-1.0.
|
|
30
|
-
dasl_client-1.0.
|
|
31
|
-
dasl_client-1.0.
|
|
32
|
-
dasl_client-1.0.
|
|
29
|
+
dasl_client-1.0.28.dist-info/licenses/LICENSE,sha256=M35UepUPyKmFkvENlkweeaMElheQqNoM5Emh8ADO-rs,4
|
|
30
|
+
dasl_client-1.0.28.dist-info/METADATA,sha256=A9J1hVHFox6Mq7cLnFB4kk-ak3vK7LUy90RSxx2Nna8,4046
|
|
31
|
+
dasl_client-1.0.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
32
|
+
dasl_client-1.0.28.dist-info/top_level.txt,sha256=kIv8ox_2oJPjGB8_yuey5vvuPCyfY8kywG138f9oSOY,12
|
|
33
|
+
dasl_client-1.0.28.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|