-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from mrjsj/refactor/removed-sempy-dependency
refactor: remove sempy dependency
- Loading branch information
Showing
7 changed files
with
115 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from .workspace import get_workspaces, get_workspace | ||
from .lakehouse import get_workspace_lakehouse_tables, get_workspace_lakehouses | ||
from .auth import get_fabric_bearer_token, get_onelake_access_token | ||
|
||
__all__ = ( | ||
"get_workspace", | ||
"get_workspaces", | ||
"get_workspace_lakehouses", | ||
"get_workspace_lakehouse_tables", | ||
"get_onelake_access_token", | ||
"get_fabric_bearer_token" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from azure.identity import DefaultAzureCredential | ||
|
||
|
||
def get_onelake_access_token(): | ||
audience = "https://storage.azure.com" | ||
try: | ||
import notebookutils | ||
|
||
token = notebookutils.credentials.getToken(audience) | ||
except ModuleNotFoundError: | ||
token = DefaultAzureCredential().get_token(f"{audience}/.default").token | ||
|
||
return token | ||
|
||
|
||
def get_fabric_bearer_token(): | ||
audience = "https://analysis.windows.net/powerbi/api" | ||
try: | ||
import notebookutils | ||
|
||
token = notebookutils.credentials.getToken(audience) | ||
except ModuleNotFoundError: | ||
token = DefaultAzureCredential().get_token(f"{audience}/.default").token | ||
|
||
return token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import requests | ||
from msfabricutils.core.auth import get_fabric_bearer_token | ||
|
||
|
||
def get_paginated(endpoint: str, data_key: str) -> list[dict]: | ||
base_url = "https://api.fabric.microsoft.com/v1" | ||
token = get_fabric_bearer_token() | ||
headers = {"Authorization": f"Bearer {token}"} | ||
|
||
responses = [] | ||
continuation_token = None | ||
while True: | ||
params = {"continuationToken": continuation_token} if continuation_token else {} | ||
|
||
response = requests.get(f"{base_url}/{endpoint}", headers=headers, params=params) | ||
response.raise_for_status() | ||
data: dict = response.json() | ||
|
||
responses.extend(data.get(data_key)) | ||
|
||
continuation_token = data.get("continuationToken") | ||
if not continuation_token: | ||
break | ||
|
||
return responses | ||
|
||
|
||
def get_page(endpoint: str) -> list[dict]: | ||
base_url = "https://api.fabric.microsoft.com/v1" | ||
token = get_fabric_bearer_token() | ||
headers = {"Authorization": f"Bearer {token}"} | ||
params = {} | ||
|
||
response = requests.get(f"{base_url}/{endpoint}", headers=headers, params=params) | ||
response.raise_for_status() | ||
|
||
return response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from msfabricutils.core.generic import get_paginated | ||
|
||
|
||
def get_workspace_lakehouses(workspace_id: str): | ||
endpoint = f"workspaces/{workspace_id}/lakehouses" | ||
data_key = "value" | ||
|
||
return get_paginated(endpoint, data_key) | ||
|
||
|
||
def get_workspace_lakehouse_tables(workspace_id: str, lakehouse_id: str): | ||
endpoint = f"workspaces/{workspace_id}/lakehouses/{lakehouse_id}/tables" | ||
data_key = "data" | ||
|
||
return get_paginated(endpoint, data_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from msfabricutils.core.generic import get_paginated, get_page | ||
|
||
|
||
def get_workspaces(): | ||
endpoint = "workspaces" | ||
data_key = "value" | ||
|
||
return get_paginated(endpoint, data_key) | ||
|
||
|
||
def get_workspace(workspace_id: str): | ||
endpoint = f"workspaces/{workspace_id}" | ||
|
||
return get_page(endpoint) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters