Skip to content

Commit

Permalink
fixed fabric exception, fixed issue with get_measure_dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kovalsky committed Jul 22, 2024
1 parent e7b69d6 commit 8b29370
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 277 deletions.
159 changes: 75 additions & 84 deletions src/sempy_labs/_connections.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sempy.fabric as fabric
import pandas as pd
import sempy_labs._icons as icons
from sempy.fabric.exceptions import FabricHTTPException


def create_connection_cloud(
Expand Down Expand Up @@ -56,33 +56,30 @@ def create_connection_cloud(

response = client.post("/v1/connections", json=request_body)

if response.status_code == 200:
o = response.json()
new_data = {
"Connection Id": o.get("id"),
"Connection Name": o.get("name"),
"Connectivity Type": o.get("connectivityType"),
"Connection Type": o.get("connectionDetails", {}).get("type"),
"Connection Path": o.get("connectionDetails", {}).get("path"),
"Privacy Level": o.get("privacyLevel"),
"Credential Type": o.get("credentialDetails", {}).get("credentialType"),
"Single Sign On Type": o.get("credentialDetails", {}).get(
"singleSignOnType"
),
"Connection Encryption": o.get("credentialDetails", {}).get(
"connectionEncryption"
),
"Skip Test Connection": o.get("credentialDetails", {}).get(
"skipTestConnection"
),
}
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)

df["Skip Test Connection"] = df["Skip Test Connection"].astype(bool)

return df
else:
print(f"{icons.red_dot} {response.status_code}")
if response.status_code != 200:
raise FabricHTTPException(response)
o = response.json()
new_data = {
"Connection Id": o.get("id"),
"Connection Name": o.get("name"),
"Connectivity Type": o.get("connectivityType"),
"Connection Type": o.get("connectionDetails", {}).get("type"),
"Connection Path": o.get("connectionDetails", {}).get("path"),
"Privacy Level": o.get("privacyLevel"),
"Credential Type": o.get("credentialDetails", {}).get("credentialType"),
"Single Sign On Type": o.get("credentialDetails", {}).get("singleSignOnType"),
"Connection Encryption": o.get("credentialDetails", {}).get(
"connectionEncryption"
),
"Skip Test Connection": o.get("credentialDetails", {}).get(
"skipTestConnection"
),
}
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)

df["Skip Test Connection"] = df["Skip Test Connection"].astype(bool)

return df


def create_connection_on_prem(
Expand Down Expand Up @@ -137,34 +134,31 @@ def create_connection_on_prem(

response = client.post("/v1/connections", json=request_body)

if response.status_code == 200:
o = response.json()
new_data = {
"Connection Id": o.get("id"),
"Connection Name": o.get("name"),
"Gateway ID": o.get("gatewayId"),
"Connectivity Type": o.get("connectivityType"),
"Connection Type": o.get("connectionDetails", {}).get("type"),
"Connection Path": o.get("connectionDetails", {}).get("path"),
"Privacy Level": o.get("privacyLevel"),
"Credential Type": o.get("credentialDetails", {}).get("credentialType"),
"Single Sign On Type": o.get("credentialDetails", {}).get(
"singleSignOnType"
),
"Connection Encryption": o.get("credentialDetails", {}).get(
"connectionEncryption"
),
"Skip Test Connection": o.get("credentialDetails", {}).get(
"skipTestConnection"
),
}
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)

df["Skip Test Connection"] = df["Skip Test Connection"].astype(bool)

return df
else:
print(f"{icons.red_dot} {response.status_code}")
if response.status_code != 200:
raise FabricHTTPException(response)
o = response.json()
new_data = {
"Connection Id": o.get("id"),
"Connection Name": o.get("name"),
"Gateway ID": o.get("gatewayId"),
"Connectivity Type": o.get("connectivityType"),
"Connection Type": o.get("connectionDetails", {}).get("type"),
"Connection Path": o.get("connectionDetails", {}).get("path"),
"Privacy Level": o.get("privacyLevel"),
"Credential Type": o.get("credentialDetails", {}).get("credentialType"),
"Single Sign On Type": o.get("credentialDetails", {}).get("singleSignOnType"),
"Connection Encryption": o.get("credentialDetails", {}).get(
"connectionEncryption"
),
"Skip Test Connection": o.get("credentialDetails", {}).get(
"skipTestConnection"
),
}
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)

df["Skip Test Connection"] = df["Skip Test Connection"].astype(bool)

return df


def create_connection_vnet(
Expand Down Expand Up @@ -221,31 +215,28 @@ def create_connection_vnet(

response = client.post("/v1/connections", json=request_body)

if response.status_code == 200:
o = response.json()
new_data = {
"Connection Id": o.get("id"),
"Connection Name": o.get("name"),
"Gateway ID": o.get("gatewayId"),
"Connectivity Type": o.get("connectivityType"),
"Connection Type": o.get("connectionDetails", {}).get("type"),
"Connection Path": o.get("connectionDetails", {}).get("path"),
"Privacy Level": o.get("privacyLevel"),
"Credential Type": o.get("credentialDetails", {}).get("credentialType"),
"Single Sign On Type": o.get("credentialDetails", {}).get(
"singleSignOnType"
),
"Connection Encryption": o.get("credentialDetails", {}).get(
"connectionEncryption"
),
"Skip Test Connection": o.get("credentialDetails", {}).get(
"skipTestConnection"
),
}
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)

df["Skip Test Connection"] = df["Skip Test Connection"].astype(bool)

return df
else:
print(f"{icons.red_dot} {response.status_code}")
if response.status_code != 200:
raise FabricHTTPException(response)
o = response.json()
new_data = {
"Connection Id": o.get("id"),
"Connection Name": o.get("name"),
"Gateway ID": o.get("gatewayId"),
"Connectivity Type": o.get("connectivityType"),
"Connection Type": o.get("connectionDetails", {}).get("type"),
"Connection Path": o.get("connectionDetails", {}).get("path"),
"Privacy Level": o.get("privacyLevel"),
"Credential Type": o.get("credentialDetails", {}).get("credentialType"),
"Single Sign On Type": o.get("credentialDetails", {}).get("singleSignOnType"),
"Connection Encryption": o.get("credentialDetails", {}).get(
"connectionEncryption"
),
"Skip Test Connection": o.get("credentialDetails", {}).get(
"skipTestConnection"
),
}
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)

df["Skip Test Connection"] = df["Skip Test Connection"].astype(bool)

return df
1 change: 1 addition & 0 deletions src/sempy_labs/_generate_semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from sempy_labs.lakehouse._lakehouse import lakehouse_attached
import sempy_labs._icons as icons
from sempy.fabric.exceptions import FabricHTTPException


def create_blank_semantic_model(
Expand Down
156 changes: 73 additions & 83 deletions src/sempy_labs/_list_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,18 +1083,15 @@ def update_item(
f"/v1/workspaces/{workspace_id}/{itemType}/{itemId}", json=request_body
)

if response.status_code == 200:
if description is None:
print(
f"{icons.green_dot} The '{current_name}' {item_type} within the '{workspace}' workspace has been updated to be named '{new_name}'"
)
else:
print(
f"{icons.green_dot} The '{current_name}' {item_type} within the '{workspace}' workspace has been updated to be named '{new_name}' and have a description of '{description}'"
)
if response.status_code != 200:
raise FabricHTTPException(response)
if description is None:
print(
f"{icons.green_dot} The '{current_name}' {item_type} within the '{workspace}' workspace has been updated to be named '{new_name}'"
)
else:
raise ValueError(
f"{icons.red_dot}: The '{current_name}' {item_type} within the '{workspace}' workspace was not updateds."
print(
f"{icons.green_dot} The '{current_name}' {item_type} within the '{workspace}' workspace has been updated to be named '{new_name}' and have a description of '{description}'"
)


Expand Down Expand Up @@ -1536,50 +1533,47 @@ def list_shortcuts(
response = client.get(
f"/v1/workspaces/{workspace_id}/items/{lakehouse_id}/shortcuts"
)
if response.status_code == 200:
for s in response.json()["value"]:
shortcutName = s.get("name")
shortcutPath = s.get("path")
source = list(s["target"].keys())[0]
(
sourceLakehouseName,
sourceWorkspaceName,
sourcePath,
connectionId,
location,
subpath,
) = (None, None, None, None, None, None)
if source == "oneLake":
sourceLakehouseId = s.get("target", {}).get(source, {}).get("itemId")
sourcePath = s.get("target", {}).get(source, {}).get("path")
sourceWorkspaceId = (
s.get("target", {}).get(source, {}).get("workspaceId")
)
sourceWorkspaceName = fabric.resolve_workspace_name(sourceWorkspaceId)
sourceLakehouseName = resolve_lakehouse_name(
sourceLakehouseId, sourceWorkspaceName
)
else:
connectionId = s.get("target", {}).get(source, {}).get("connectionId")
location = s.get("target", {}).get(source, {}).get("location")
subpath = s.get("target", {}).get(source, {}).get("subpath")

new_data = {
"Shortcut Name": shortcutName,
"Shortcut Path": shortcutPath,
"Source": source,
"Source Lakehouse Name": sourceLakehouseName,
"Source Workspace Name": sourceWorkspaceName,
"Source Path": sourcePath,
"Source Connection ID": connectionId,
"Source Location": location,
"Source SubPath": subpath,
}
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
if response.status_code != 200:
raise FabricHTTPException(response)
for s in response.json()["value"]:
shortcutName = s.get("name")
shortcutPath = s.get("path")
source = list(s["target"].keys())[0]
(
sourceLakehouseName,
sourceWorkspaceName,
sourcePath,
connectionId,
location,
subpath,
) = (None, None, None, None, None, None)
if source == "oneLake":
sourceLakehouseId = s.get("target", {}).get(source, {}).get("itemId")
sourcePath = s.get("target", {}).get(source, {}).get("path")
sourceWorkspaceId = s.get("target", {}).get(source, {}).get("workspaceId")
sourceWorkspaceName = fabric.resolve_workspace_name(sourceWorkspaceId)
sourceLakehouseName = resolve_lakehouse_name(
sourceLakehouseId, sourceWorkspaceName
)
else:
connectionId = s.get("target", {}).get(source, {}).get("connectionId")
location = s.get("target", {}).get(source, {}).get("location")
subpath = s.get("target", {}).get(source, {}).get("subpath")

new_data = {
"Shortcut Name": shortcutName,
"Shortcut Path": shortcutPath,
"Source": source,
"Source Lakehouse Name": sourceLakehouseName,
"Source Workspace Name": sourceWorkspaceName,
"Source Path": sourcePath,
"Source Connection ID": connectionId,
"Source Location": location,
"Source SubPath": subpath,
}
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)

print(
f"{icons.warning} This function relies on an API which is not yet official as of May 21, 2024. Once the API becomes official this function will work as expected."
)
return df


Expand Down Expand Up @@ -2109,12 +2103,11 @@ def update_spark_settings(
f"/v1/workspaces/{workspace_id}/spark/settings", json=request_body
)

if response.status_code == 200:
print(
f"{icons.green_dot} The spark settings within the '{workspace}' workspace have been updated accordingly."
)
else:
raise ValueError(f"{icons.red_dot} {response.status_code}")
if response.status_code != 200:
raise FabricHTTPException(response)
print(
f"{icons.green_dot} The spark settings within the '{workspace}' workspace have been updated accordingly."
)


def add_user_to_workspace(
Expand Down Expand Up @@ -2156,12 +2149,11 @@ def add_user_to_workspace(
f"/v1.0/myorg/groups/{workspace_id}/users", json=request_body
)

if response.status_code == 200:
print(
f"{icons.green_dot} The '{email_address}' user has been added as a{plural} '{role_name}' within the '{workspace}' workspace."
)
else:
print(f"{icons.red_dot} {response.status_code}")
if response.status_code != 200:
raise FabricHTTPException(response)
print(
f"{icons.green_dot} The '{email_address}' user has been added as a{plural} '{role_name}' within the '{workspace}' workspace."
)


def delete_user_from_workspace(email_address: str, workspace: Optional[str] = None):
Expand All @@ -2186,12 +2178,11 @@ def delete_user_from_workspace(email_address: str, workspace: Optional[str] = No
client = fabric.PowerBIRestClient()
response = client.delete(f"/v1.0/myorg/groups/{workspace_id}/users/{email_address}")

if response.status_code == 200:
print(
f"{icons.green_dot} The '{email_address}' user has been removed from accessing the '{workspace}' workspace."
)
else:
print(f"{icons.red_dot} {response.status_code}")
if response.status_code != 200:
raise FabricHTTPException(response)
print(
f"{icons.green_dot} The '{email_address}' user has been removed from accessing the '{workspace}' workspace."
)


def update_workspace_user(
Expand Down Expand Up @@ -2229,12 +2220,11 @@ def update_workspace_user(
client = fabric.PowerBIRestClient()
response = client.put(f"/v1.0/myorg/groups/{workspace_id}/users", json=request_body)

if response.status_code == 200:
print(
f"{icons.green_dot} The '{email_address}' user has been updated to a '{role_name}' within the '{workspace}' workspace."
)
else:
print(f"{icons.red_dot} {response.status_code}")
if response.status_code != 200:
raise FabricHTTPException(response)
print(
f"{icons.green_dot} The '{email_address}' user has been updated to a '{role_name}' within the '{workspace}' workspace."
)


def list_workspace_users(workspace: Optional[str] = None) -> pd.DataFrame:
Expand Down Expand Up @@ -2307,12 +2297,12 @@ def assign_workspace_to_dataflow_storage(
response = client.post(
f"/v1.0/myorg/groups/{workspace_id}/AssignToDataflowStorage", json=request_body
)
if response.status_code == 200:
print(
f"{icons.green_dot} The '{dataflow_storage_account}' dataflow storage account has been assigned to the '{workspace}' workspacce."
)
else:
print(f"{icons.red_dot} {response.status_code}")

if response.status_code != 200:
raise FabricHTTPException(response)
print(
f"{icons.green_dot} The '{dataflow_storage_account}' dataflow storage account has been assigned to the '{workspace}' workspacce."
)


def list_capacities() -> pd.DataFrame:
Expand Down
Loading

0 comments on commit 8b29370

Please sign in to comment.