Skip to content

Commit 39752b8

Browse files
committed
Merge branch 'm-kovalsky/warehouseconstring'
2 parents ce5b2e1 + af18470 commit 39752b8

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/sempy_labs/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
delete_warehouse,
101101
get_warehouse_columns,
102102
get_warehouse_tables,
103+
get_warehouse_connection_string,
103104
)
104105
from ._data_pipelines import (
105106
list_data_pipelines,
@@ -599,4 +600,5 @@
599600
"get_item_definition",
600601
"get_workspace_network_communication_policy",
601602
"set_workspace_network_communication_policy",
603+
"get_warehouse_connection_string",
602604
]

src/sempy_labs/_warehouses.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ._helper_functions import (
2+
resolve_item_id,
23
resolve_workspace_name_and_id,
34
_base_api,
45
_create_dataframe,
@@ -232,3 +233,57 @@ def get_warehouse_columns(
232233
)
233234

234235
return df
236+
237+
238+
@log
239+
def get_warehouse_connection_string(
240+
warehouse: str | UUID,
241+
workspace: Optional[str | UUID] = None,
242+
guest_tenant_id: Optional[UUID] = None,
243+
private_link_type: Optional[str] = None,
244+
) -> str:
245+
"""
246+
Returns the SQL connection string of the specified warehouse.
247+
248+
Parameters
249+
----------
250+
warehouse : str | uuid.UUID
251+
Name or ID of the Fabric warehouse.
252+
workspace : str | uuid.UUID, default=None
253+
The Fabric workspace name or ID.
254+
Defaults to None which resolves to the workspace of the attached lakehouse
255+
or if no lakehouse attached, resolves to the workspace of the notebook.
256+
guest_tenant_id : uuid.UUID, default=None
257+
The guest tenant ID if the end user's tenant is different from the warehouse tenant.
258+
private_link_type : str, default=None
259+
Indicates the type of private link this connection string uses. Must be either 'Workspace' or 'None' or left as None.
260+
261+
Returns
262+
-------
263+
str
264+
Returns the SQL connection string of the specified warehouse.
265+
"""
266+
workspace_id = resolve_workspace_id(workspace)
267+
warehouse_id = resolve_item_id(
268+
item=warehouse, type="Warehouse", workspace=workspace
269+
)
270+
271+
url = f"/v1/workspaces/{workspace_id}/warehouses/{warehouse_id}/connectionString"
272+
273+
if private_link_type is not None and private_link_type not in ["Workspace", "None"]:
274+
raise ValueError(
275+
f"{icons.red_dot} private_link_type must be 'Workspace' or 'None' or left as None."
276+
)
277+
278+
if guest_tenant_id or private_link_type:
279+
params = []
280+
if guest_tenant_id:
281+
params.append(f"guestTenantId={guest_tenant_id}")
282+
if private_link_type:
283+
params.append(f"privateLinkType={private_link_type}")
284+
param_str = "?" + "&".join(params)
285+
url += param_str
286+
287+
response = _base_api(request=url, client="fabric_sp")
288+
289+
return response.json().get("connectionString")

0 commit comments

Comments
 (0)