|
1 | 1 | from ._helper_functions import ( |
| 2 | + resolve_item_id, |
2 | 3 | resolve_workspace_name_and_id, |
3 | 4 | _base_api, |
4 | 5 | _create_dataframe, |
@@ -232,3 +233,57 @@ def get_warehouse_columns( |
232 | 233 | ) |
233 | 234 |
|
234 | 235 | 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