Skip to content

Commit 0f36fd9

Browse files
committed
updated shortcut
1 parent 059edb5 commit 0f36fd9

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

src/sempy_labs/lakehouse/_shortcuts.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
resolve_lakehouse_name,
44
resolve_lakehouse_id,
55
resolve_workspace_name_and_id,
6+
_base_api,
67
)
78
from typing import Optional
89
import sempy_labs._icons as icons
@@ -71,37 +72,30 @@ def create_shortcut_onelake(
7172
if shortcut_name is None:
7273
shortcut_name = table_name
7374

74-
client = fabric.FabricRestClient()
75-
tablePath = f"Tables/{table_name}"
75+
table_path = f"Tables/{table_name}"
7676

77-
request_body = {
77+
payload = {
7878
"path": "Tables",
7979
"name": shortcut_name.replace(" ", ""),
8080
"target": {
8181
"oneLake": {
8282
"workspaceId": source_workspace_id,
8383
"itemId": source_lakehouse_id,
84-
"path": tablePath,
84+
"path": table_path,
8585
}
8686
},
8787
}
8888

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+
)
10599

106100

107101
def create_shortcut(

0 commit comments

Comments
 (0)