Skip to content

Commit 6e8d269

Browse files
committed
updated shortcut functions
1 parent 4cbe2c9 commit 6e8d269

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

src/sempy_labs/lakehouse/_shortcuts.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ def create_shortcut_adls(
103103
Parameters
104104
----------
105105
shortcut_name : str
106+
The name of the shortcut.
106107
location : str
108+
Specifies the location of the target ADLS container. The URI must be in the format https://[account-name].dfs.core.windows.net where [account-name] is the name of the target ADLS account.
107109
subpath : str
110+
111+
Specifies the container and subfolder within the ADLS account where the target folder is located. Must be of the format [container]/[subfolder] where [container] is the name of the container that holds the files and folders; [subfolder] is the name of the subfolder within the container (optional). For example: /mycontainer/mysubfolder.
108112
connection: Union[str, UUID]
109113
A string representing the connection that is bound with the shortcut. This can either be the connection Id or the connection name.
110114
path : str, default="Tables"
@@ -145,8 +149,11 @@ def create_shortcut_amazons3(
145149
Parameters
146150
----------
147151
shortcut_name : str
152+
The name of the shortcut.
148153
location : str
154+
HTTP URL that points to the target bucket in S3. The URL should be in the format https://[bucket-name].s3.[region-code].amazonaws.com, where "bucket-name" is the name of the S3 bucket you want to point to, and "region-code" is the code for the region where the bucket is located. For example: https://my-s3-bucket.s3.us-west-2.amazonaws.com.
149155
subpath : str
156+
Specifies a target folder or subfolder within the S3 bucket.
150157
connection: Union[str, UUID]
151158
A string representing the connection that is bound with the shortcut. This can either be the connection Id or the connection name.
152159
path : str, default="Tables"
@@ -172,13 +179,108 @@ def create_shortcut_amazons3(
172179
)
173180

174181

182+
def create_shortcut_google_cloud(
183+
shortcut_name: str,
184+
location: str,
185+
subpath: str,
186+
connection: Union[str, UUID],
187+
path: str = "Tables",
188+
lakehouse: Optional[str] = None,
189+
workspace: Optional[str] = None,
190+
):
191+
"""
192+
Creates a `shortcut <https://learn.microsoft.com/fabric/onelake/onelake-shortcuts>`_ to a Google Cloud Storage source.
193+
194+
Parameters
195+
----------
196+
shortcut_name : str
197+
The name of the shortcut.
198+
location : str
199+
HTTP URL that points to the target bucket in GCS. The URL should be in the format https://[bucket-name].storage.googleapis.com, where [bucket-name] is the name of the bucket you want to point to. For example: https://my-gcs-bucket.storage.googleapis.com.
200+
subpath : str
201+
Specifies a target folder or subfolder within the GCS bucket. For example: /folder
202+
connection: Union[str, UUID]
203+
A string representing the connection that is bound with the shortcut. This can either be the connection Id or the connection name.
204+
path : str, default="Tables"
205+
A string representing the full path where the shortcut is created, including either "Files" or "Tables".
206+
lakehouse : str, default=None
207+
The Fabric lakehouse in which the shortcut will be created.
208+
Defaults to None which resolves to the default lakehouse attached to the notebook.
209+
workspace : str, default=None
210+
The name of the Fabric workspace in which the shortcut will be created.
211+
Defaults to None which resolves to the workspace of the attached lakehouse
212+
or if no lakehouse attached, resolves to the workspace of the notebook.
213+
"""
214+
215+
_create_shortcut_base(
216+
shortcut_name=shortcut_name,
217+
location=location,
218+
subpath=subpath,
219+
source="googleCloudStorage",
220+
connection=connection,
221+
path=path,
222+
lakehouse=lakehouse,
223+
workspace=workspace,
224+
)
225+
226+
227+
def create_shortcut_s3_compatible(
228+
shortcut_name: str,
229+
location: str,
230+
subpath: str,
231+
bucket: str,
232+
connection: Union[str, UUID],
233+
path: str = "Tables",
234+
lakehouse: Optional[str] = None,
235+
workspace: Optional[str] = None,
236+
):
237+
"""
238+
Creates a `shortcut <https://learn.microsoft.com/fabric/onelake/onelake-shortcuts>`_ to an S3 Compatible source.
239+
240+
Parameters
241+
----------
242+
shortcut_name : str
243+
The name of the shortcut.
244+
location : str
245+
HTTP URL of the S3 compatible endpoint. This endpoint must be able to receive ListBuckets S3 API calls. The URL must be in the non-bucket specific format; no bucket should be specified here. For example: https://s3endpoint.contoso.com.
246+
subpath : str
247+
Specifies a target folder or subfolder within the S3 compatible bucket. For example: /folder
248+
bucket : str
249+
Specifies the target bucket within the S3 compatible location.
250+
connection: Union[str, UUID]
251+
A string representing the connection that is bound with the shortcut. This can either be the connection Id or the connection name.
252+
path : str, default="Tables"
253+
A string representing the full path where the shortcut is created, including either "Files" or "Tables".
254+
lakehouse : str, default=None
255+
The Fabric lakehouse in which the shortcut will be created.
256+
Defaults to None which resolves to the default lakehouse attached to the notebook.
257+
workspace : str, default=None
258+
The name of the Fabric workspace in which the shortcut will be created.
259+
Defaults to None which resolves to the workspace of the attached lakehouse
260+
or if no lakehouse attached, resolves to the workspace of the notebook.
261+
"""
262+
263+
_create_shortcut_base(
264+
shortcut_name=shortcut_name,
265+
location=location,
266+
subpath=subpath,
267+
source="s3Compatible",
268+
connection=connection,
269+
path=path,
270+
bucket=bucket,
271+
lakehouse=lakehouse,
272+
workspace=workspace,
273+
)
274+
275+
175276
def _create_shortcut_base(
176277
shortcut_name: str,
177278
location: str,
178279
subpath: str,
179280
source: str,
180281
connection: Union[str, UUID],
181282
path: str = "Tables",
283+
bucket: Optional[str] = None,
182284
lakehouse: Optional[str] = None,
183285
workspace: Optional[str] = None,
184286
):
@@ -230,6 +332,11 @@ def _create_shortcut_base(
230332
},
231333
}
232334

335+
if bucket is not None:
336+
request_body['target'][source] = {
337+
"bucket": bucket
338+
}
339+
233340
response = client.post(
234341
f"/v1/workspaces/{workspace_id}/items/{lakehouse_id}/shortcuts",
235342
json=request_body,

0 commit comments

Comments
 (0)