@@ -1083,18 +1083,15 @@ def update_item(
10831083 f"/v1/workspaces/{ workspace_id } /{ itemType } /{ itemId } " , json = request_body
10841084 )
10851085
1086- if response .status_code == 200 :
1087- if description is None :
1088- print (
1089- f"{ icons .green_dot } The '{ current_name } ' { item_type } within the '{ workspace } ' workspace has been updated to be named '{ new_name } '"
1090- )
1091- else :
1092- print (
1093- 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 } '"
1094- )
1086+ if response .status_code != 200 :
1087+ raise FabricHTTPException (response )
1088+ if description is None :
1089+ print (
1090+ f"{ icons .green_dot } The '{ current_name } ' { item_type } within the '{ workspace } ' workspace has been updated to be named '{ new_name } '"
1091+ )
10951092 else :
1096- raise ValueError (
1097- f"{ icons .red_dot } : The '{ current_name } ' { item_type } within the '{ workspace } ' workspace was not updateds. "
1093+ print (
1094+ 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 } ' "
10981095 )
10991096
11001097
@@ -1536,50 +1533,47 @@ def list_shortcuts(
15361533 response = client .get (
15371534 f"/v1/workspaces/{ workspace_id } /items/{ lakehouse_id } /shortcuts"
15381535 )
1539- if response .status_code == 200 :
1540- for s in response .json ()["value" ]:
1541- shortcutName = s .get ("name" )
1542- shortcutPath = s .get ("path" )
1543- source = list (s ["target" ].keys ())[0 ]
1544- (
1545- sourceLakehouseName ,
1546- sourceWorkspaceName ,
1547- sourcePath ,
1548- connectionId ,
1549- location ,
1550- subpath ,
1551- ) = (None , None , None , None , None , None )
1552- if source == "oneLake" :
1553- sourceLakehouseId = s .get ("target" , {}).get (source , {}).get ("itemId" )
1554- sourcePath = s .get ("target" , {}).get (source , {}).get ("path" )
1555- sourceWorkspaceId = (
1556- s .get ("target" , {}).get (source , {}).get ("workspaceId" )
1557- )
1558- sourceWorkspaceName = fabric .resolve_workspace_name (sourceWorkspaceId )
1559- sourceLakehouseName = resolve_lakehouse_name (
1560- sourceLakehouseId , sourceWorkspaceName
1561- )
1562- else :
1563- connectionId = s .get ("target" , {}).get (source , {}).get ("connectionId" )
1564- location = s .get ("target" , {}).get (source , {}).get ("location" )
1565- subpath = s .get ("target" , {}).get (source , {}).get ("subpath" )
15661536
1567- new_data = {
1568- "Shortcut Name" : shortcutName ,
1569- "Shortcut Path" : shortcutPath ,
1570- "Source" : source ,
1571- "Source Lakehouse Name" : sourceLakehouseName ,
1572- "Source Workspace Name" : sourceWorkspaceName ,
1573- "Source Path" : sourcePath ,
1574- "Source Connection ID" : connectionId ,
1575- "Source Location" : location ,
1576- "Source SubPath" : subpath ,
1577- }
1578- df = pd .concat ([df , pd .DataFrame (new_data , index = [0 ])], ignore_index = True )
1537+ if response .status_code != 200 :
1538+ raise FabricHTTPException (response )
1539+ for s in response .json ()["value" ]:
1540+ shortcutName = s .get ("name" )
1541+ shortcutPath = s .get ("path" )
1542+ source = list (s ["target" ].keys ())[0 ]
1543+ (
1544+ sourceLakehouseName ,
1545+ sourceWorkspaceName ,
1546+ sourcePath ,
1547+ connectionId ,
1548+ location ,
1549+ subpath ,
1550+ ) = (None , None , None , None , None , None )
1551+ if source == "oneLake" :
1552+ sourceLakehouseId = s .get ("target" , {}).get (source , {}).get ("itemId" )
1553+ sourcePath = s .get ("target" , {}).get (source , {}).get ("path" )
1554+ sourceWorkspaceId = s .get ("target" , {}).get (source , {}).get ("workspaceId" )
1555+ sourceWorkspaceName = fabric .resolve_workspace_name (sourceWorkspaceId )
1556+ sourceLakehouseName = resolve_lakehouse_name (
1557+ sourceLakehouseId , sourceWorkspaceName
1558+ )
1559+ else :
1560+ connectionId = s .get ("target" , {}).get (source , {}).get ("connectionId" )
1561+ location = s .get ("target" , {}).get (source , {}).get ("location" )
1562+ subpath = s .get ("target" , {}).get (source , {}).get ("subpath" )
1563+
1564+ new_data = {
1565+ "Shortcut Name" : shortcutName ,
1566+ "Shortcut Path" : shortcutPath ,
1567+ "Source" : source ,
1568+ "Source Lakehouse Name" : sourceLakehouseName ,
1569+ "Source Workspace Name" : sourceWorkspaceName ,
1570+ "Source Path" : sourcePath ,
1571+ "Source Connection ID" : connectionId ,
1572+ "Source Location" : location ,
1573+ "Source SubPath" : subpath ,
1574+ }
1575+ df = pd .concat ([df , pd .DataFrame (new_data , index = [0 ])], ignore_index = True )
15791576
1580- print (
1581- 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."
1582- )
15831577 return df
15841578
15851579
@@ -2109,12 +2103,11 @@ def update_spark_settings(
21092103 f"/v1/workspaces/{ workspace_id } /spark/settings" , json = request_body
21102104 )
21112105
2112- if response .status_code == 200 :
2113- print (
2114- f"{ icons .green_dot } The spark settings within the '{ workspace } ' workspace have been updated accordingly."
2115- )
2116- else :
2117- raise ValueError (f"{ icons .red_dot } { response .status_code } " )
2106+ if response .status_code != 200 :
2107+ raise FabricHTTPException (response )
2108+ print (
2109+ f"{ icons .green_dot } The spark settings within the '{ workspace } ' workspace have been updated accordingly."
2110+ )
21182111
21192112
21202113def add_user_to_workspace (
@@ -2156,12 +2149,11 @@ def add_user_to_workspace(
21562149 f"/v1.0/myorg/groups/{ workspace_id } /users" , json = request_body
21572150 )
21582151
2159- if response .status_code == 200 :
2160- print (
2161- f"{ icons .green_dot } The '{ email_address } ' user has been added as a{ plural } '{ role_name } ' within the '{ workspace } ' workspace."
2162- )
2163- else :
2164- print (f"{ icons .red_dot } { response .status_code } " )
2152+ if response .status_code != 200 :
2153+ raise FabricHTTPException (response )
2154+ print (
2155+ f"{ icons .green_dot } The '{ email_address } ' user has been added as a{ plural } '{ role_name } ' within the '{ workspace } ' workspace."
2156+ )
21652157
21662158
21672159def delete_user_from_workspace (email_address : str , workspace : Optional [str ] = None ):
@@ -2186,12 +2178,11 @@ def delete_user_from_workspace(email_address: str, workspace: Optional[str] = No
21862178 client = fabric .PowerBIRestClient ()
21872179 response = client .delete (f"/v1.0/myorg/groups/{ workspace_id } /users/{ email_address } " )
21882180
2189- if response .status_code == 200 :
2190- print (
2191- f"{ icons .green_dot } The '{ email_address } ' user has been removed from accessing the '{ workspace } ' workspace."
2192- )
2193- else :
2194- print (f"{ icons .red_dot } { response .status_code } " )
2181+ if response .status_code != 200 :
2182+ raise FabricHTTPException (response )
2183+ print (
2184+ f"{ icons .green_dot } The '{ email_address } ' user has been removed from accessing the '{ workspace } ' workspace."
2185+ )
21952186
21962187
21972188def update_workspace_user (
@@ -2229,12 +2220,11 @@ def update_workspace_user(
22292220 client = fabric .PowerBIRestClient ()
22302221 response = client .put (f"/v1.0/myorg/groups/{ workspace_id } /users" , json = request_body )
22312222
2232- if response .status_code == 200 :
2233- print (
2234- f"{ icons .green_dot } The '{ email_address } ' user has been updated to a '{ role_name } ' within the '{ workspace } ' workspace."
2235- )
2236- else :
2237- print (f"{ icons .red_dot } { response .status_code } " )
2223+ if response .status_code != 200 :
2224+ raise FabricHTTPException (response )
2225+ print (
2226+ f"{ icons .green_dot } The '{ email_address } ' user has been updated to a '{ role_name } ' within the '{ workspace } ' workspace."
2227+ )
22382228
22392229
22402230def list_workspace_users (workspace : Optional [str ] = None ) -> pd .DataFrame :
@@ -2307,12 +2297,12 @@ def assign_workspace_to_dataflow_storage(
23072297 response = client .post (
23082298 f"/v1.0/myorg/groups/{ workspace_id } /AssignToDataflowStorage" , json = request_body
23092299 )
2310- if response . status_code == 200 :
2311- print (
2312- f" { icons . green_dot } The ' { dataflow_storage_account } ' dataflow storage account has been assigned to the ' { workspace } ' workspacce."
2313- )
2314- else :
2315- print ( f" { icons . red_dot } { response . status_code } " )
2300+
2301+ if response . status_code != 200 :
2302+ raise FabricHTTPException ( response )
2303+ print (
2304+ f" { icons . green_dot } The ' { dataflow_storage_account } ' dataflow storage account has been assigned to the ' { workspace } ' workspacce."
2305+ )
23162306
23172307
23182308def list_capacities () -> pd .DataFrame :
0 commit comments