|
3 | 3 | resolve_lakehouse_name,
|
4 | 4 | resolve_lakehouse_id,
|
5 | 5 | resolve_workspace_name_and_id,
|
| 6 | + _base_api, |
6 | 7 | )
|
7 | 8 | from typing import Optional
|
8 | 9 | import sempy_labs._icons as icons
|
@@ -71,37 +72,30 @@ def create_shortcut_onelake(
|
71 | 72 | if shortcut_name is None:
|
72 | 73 | shortcut_name = table_name
|
73 | 74 |
|
74 |
| - client = fabric.FabricRestClient() |
75 |
| - tablePath = f"Tables/{table_name}" |
| 75 | + table_path = f"Tables/{table_name}" |
76 | 76 |
|
77 |
| - request_body = { |
| 77 | + payload = { |
78 | 78 | "path": "Tables",
|
79 | 79 | "name": shortcut_name.replace(" ", ""),
|
80 | 80 | "target": {
|
81 | 81 | "oneLake": {
|
82 | 82 | "workspaceId": source_workspace_id,
|
83 | 83 | "itemId": source_lakehouse_id,
|
84 |
| - "path": tablePath, |
| 84 | + "path": table_path, |
85 | 85 | }
|
86 | 86 | },
|
87 | 87 | }
|
88 | 88 |
|
89 |
| - try: |
90 |
| - response = client.post( |
91 |
| - f"/v1/workspaces/{destination_workspace_id}/items/{destination_lakehouse_id}/shortcuts", |
92 |
| - json=request_body, |
93 |
| - ) |
94 |
| - if response.status_code == 201: |
95 |
| - print( |
96 |
| - f"{icons.green_dot} The shortcut '{shortcut_name}' was created in the '{destination_lakehouse_name}' lakehouse within" |
97 |
| - f" the '{destination_workspace_name} workspace. It is based on the '{table_name}' table in the '{source_lakehouse_name}' lakehouse within the '{source_workspace_name}' workspace." |
98 |
| - ) |
99 |
| - else: |
100 |
| - print(response.status_code) |
101 |
| - except Exception as e: |
102 |
| - raise ValueError( |
103 |
| - f"{icons.red_dot} Failed to create a shortcut for the '{table_name}' table." |
104 |
| - ) from e |
| 89 | + _base_api( |
| 90 | + request=f"/v1/workspaces/{destination_workspace_id}/items/{destination_lakehouse_id}/shortcuts", |
| 91 | + payload=payload, |
| 92 | + status_codes=201, |
| 93 | + method="post", |
| 94 | + ) |
| 95 | + |
| 96 | + print( |
| 97 | + f"{icons.green_dot} The shortcut '{shortcut_name}' was created in the '{destination_lakehouse_name}' lakehouse within the '{destination_workspace_name} workspace. It is based on the '{table_name}' table in the '{source_lakehouse_name}' lakehouse within the '{source_workspace_name}' workspace." |
| 98 | + ) |
105 | 99 |
|
106 | 100 |
|
107 | 101 | def create_shortcut(
|
|
0 commit comments