11import pandas as pd
22from typing import Optional
3- from ._helper_functions import (
3+ from sempy_labs ._helper_functions import (
44 _is_valid_uuid ,
5- resolve_workspace_name_and_id ,
5+ resolve_workspace_id ,
66 _update_dataframe_datatypes ,
77 _base_api ,
88 _create_dataframe ,
99 resolve_item_id ,
1010)
1111from uuid import UUID
1212import sempy_labs ._icons as icons
13- from ._gateways import _resolve_gateway_id
13+ from sempy_labs ._gateways import _resolve_gateway_id
1414from sempy ._utils ._log import log
15+ import warnings
1516
1617
1718@log
@@ -68,13 +69,13 @@ def delete_connection_role_assignment(connection: str | UUID, role_assignment_id
6869@log
6970def _resolve_connection_id (connection : str | UUID ) -> UUID :
7071
71- dfC = list_connections ()
7272 if _is_valid_uuid (connection ):
73- dfC_filt = dfC [dfC ["Connection Id" ] == connection ]
74- else :
75- dfC_filt = dfC [dfC ["Connection Name" ] == connection ]
73+ return connection
74+
75+ dfC = list_connections ()
76+ dfC_filt = dfC [dfC ["Connection Name" ] == connection ]
7677
77- if len ( dfC_filt ) == 0 :
78+ if dfC_filt . empty :
7879 raise ValueError (
7980 f"{ icons .red_dot } The '{ connection } ' is not a valid connection."
8081 )
@@ -119,16 +120,20 @@ def list_connection_role_assignments(connection: str | UUID) -> pd.DataFrame:
119120 uses_pagination = True ,
120121 )
121122
123+ rows = []
122124 for r in responses :
123125 for v in r .get ("value" , []):
124- new_data = {
125- "Connection Role Assignment Id" : v .get ("id" ),
126- "Principal Id" : v .get ("principal" , {}).get ("id" ),
127- "Principal Type" : v .get ("principal" , {}).get ("type" ),
128- "Role" : v .get ("role" ),
129- }
126+ rows .append (
127+ {
128+ "Connection Role Assignment Id" : v .get ("id" ),
129+ "Principal Id" : v .get ("principal" , {}).get ("id" ),
130+ "Principal Type" : v .get ("principal" , {}).get ("type" ),
131+ "Role" : v .get ("role" ),
132+ }
133+ )
130134
131- df = pd .concat ([df , pd .DataFrame (new_data , index = [0 ])], ignore_index = True )
135+ if rows :
136+ df = pd .DataFrame (rows , columns = list (columns .keys ()))
132137
133138 return df
134139
@@ -165,51 +170,57 @@ def list_connections() -> pd.DataFrame:
165170 request = "/v1/connections" , client = "fabric_sp" , uses_pagination = True
166171 )
167172
173+ rows = []
168174 for r in responses :
169175 for i in r .get ("value" , []):
170176 connection_details = i .get ("connectionDetails" , {})
171177 credential_details = i .get ("credentialDetails" , {})
172178
173- new_data = {
174- "Connection Id" : i .get ("id" ),
175- "Connection Name" : i .get ("displayName" ),
176- "Gateway Id" : i .get ("gatewayId" ),
177- "Connectivity Type" : i .get ("connectivityType" ),
178- "Connection Path" : connection_details .get ("path" ),
179- "Connection Type" : connection_details .get ("type" ),
180- "Privacy Level" : i .get ("privacyLevel" ),
181- "Credential Type" : (
182- credential_details .get ("credentialType" )
183- if credential_details
184- else None
185- ),
186- "Single Sign On Type" : (
187- credential_details .get ("singleSignOnType" )
188- if credential_details
189- else None
190- ),
191- "Connection Encryption" : (
192- credential_details .get ("connectionEncryption" )
193- if credential_details
194- else None
195- ),
196- "Skip Test Connection" : (
197- credential_details .get ("skipTestConnection" )
198- if credential_details
199- else None
200- ),
201- }
202-
203- df = pd .concat ([df , pd .DataFrame (new_data , index = [0 ])], ignore_index = True )
204-
205- _update_dataframe_datatypes (dataframe = df , column_map = columns )
179+ rows .append (
180+ {
181+ "Connection Id" : i .get ("id" ),
182+ "Connection Name" : i .get ("displayName" ),
183+ "Gateway Id" : i .get ("gatewayId" ),
184+ "Connectivity Type" : i .get ("connectivityType" ),
185+ "Connection Path" : connection_details .get ("path" ),
186+ "Connection Type" : connection_details .get ("type" ),
187+ "Privacy Level" : i .get ("privacyLevel" ),
188+ "Credential Type" : (
189+ credential_details .get ("credentialType" )
190+ if credential_details
191+ else None
192+ ),
193+ "Single Sign On Type" : (
194+ credential_details .get ("singleSignOnType" )
195+ if credential_details
196+ else None
197+ ),
198+ "Connection Encryption" : (
199+ credential_details .get ("connectionEncryption" )
200+ if credential_details
201+ else None
202+ ),
203+ "Skip Test Connection" : (
204+ credential_details .get ("skipTestConnection" )
205+ if credential_details
206+ else None
207+ ),
208+ }
209+ )
210+
211+ if rows :
212+ df = pd .DataFrame (rows , columns = list (columns .keys ()))
213+ _update_dataframe_datatypes (dataframe = df , column_map = columns )
206214
207215 return df
208216
209217
210218@log
211219def list_item_connections (
212- item_name : str , item_type : str , workspace : Optional [str | UUID ] = None
220+ item : Optional [str | UUID ] = None ,
221+ type : Optional [str ] = None ,
222+ workspace : Optional [str | UUID ] = None ,
223+ ** kwargs ,
213224) -> pd .DataFrame :
214225 """
215226 Shows the list of connections that the specified item is connected to.
@@ -220,9 +231,9 @@ def list_item_connections(
220231
221232 Parameters
222233 ----------
223- item_name : str
224- The item name.
225- item_type : str
234+ item : str | uuid.UUID
235+ The item name or ID .
236+ type : str
226237 The `item type <https://learn.microsoft.com/rest/api/fabric/core/items/update-item?tabs=HTTP#itemtype>`_.
227238 workspace : str | uuid.UUID, default=None
228239 The Fabric workspace name or ID.
@@ -235,9 +246,32 @@ def list_item_connections(
235246 A pandas dataframe showing the list of connections that the specified item is connected to.
236247 """
237248
238- (workspace_name , workspace_id ) = resolve_workspace_name_and_id (workspace )
239- item_type = item_type [0 ].upper () + item_type [1 :]
240- item_id = resolve_item_id (item = item_name , type = item_type , workspace = workspace_id )
249+ if "item_name" in kwargs :
250+ if item is not None :
251+ raise TypeError ("Cannot specify both 'item' and 'item_name'" )
252+ item = kwargs .pop ("item_name" )
253+ warnings .warn (
254+ "'item_name' parameter is deprecated, use 'item' instead." ,
255+ FutureWarning ,
256+ stacklevel = 2 ,
257+ )
258+ if "item_type" in kwargs :
259+ if type is not None :
260+ raise TypeError ("Cannot specify both 'type' and 'item_type'" )
261+ type = kwargs .pop ("item_type" )
262+ warnings .warn (
263+ "'item_type' parameter is deprecated, use 'type' instead." ,
264+ FutureWarning ,
265+ stacklevel = 2 ,
266+ )
267+
268+ if item is None or type is None :
269+ raise TypeError (
270+ "Missing required parameters: 'item' and 'type' must be provided either directly or via 'item_name' and 'item_type'."
271+ )
272+
273+ workspace_id = resolve_workspace_id (workspace )
274+ item_id = resolve_item_id (item = item , type = type , workspace = workspace_id )
241275
242276 columns = {
243277 "Connection Name" : "string" ,
@@ -255,18 +289,22 @@ def list_item_connections(
255289 uses_pagination = True ,
256290 )
257291
292+ rows = []
258293 for r in responses :
259294 for v in r .get ("value" , []):
260- new_data = {
261- "Connection Name" : v .get ("displayName" ),
262- "Connection Id" : v .get ("id" ),
263- "Connectivity Type" : v .get ("connectivityType" ),
264- "Connection Type" : v .get ("connectionDetails" , {}).get ("type" ),
265- "Connection Path" : v .get ("connectionDetails" , {}).get ("path" ),
266- "Gateway Id" : v .get ("gatewayId" ),
267- }
295+ rows .append (
296+ {
297+ "Connection Name" : v .get ("displayName" ),
298+ "Connection Id" : v .get ("id" ),
299+ "Connectivity Type" : v .get ("connectivityType" ),
300+ "Connection Type" : v .get ("connectionDetails" , {}).get ("type" ),
301+ "Connection Path" : v .get ("connectionDetails" , {}).get ("path" ),
302+ "Gateway Id" : v .get ("gatewayId" ),
303+ }
304+ )
268305
269- df = pd .concat ([df , pd .DataFrame (new_data , index = [0 ])], ignore_index = True )
306+ if rows :
307+ df = pd .DataFrame (rows , columns = list (columns .keys ()))
270308
271309 return df
272310
@@ -293,10 +331,10 @@ def _list_supported_connection_types(
293331 url = url .rstrip ("&" )
294332 responses = _base_api (request = url , client = "fabric_sp" , uses_pagination = True )
295333
296- records = []
334+ rows = []
297335 for r in responses :
298336 for v in r .get ("value" , []):
299- records .append (
337+ rows .append (
300338 {
301339 "Connection Type" : v .get ("type" ),
302340 "Creation Method" : v ["creationMethods" ][0 ]["name" ],
@@ -310,10 +348,9 @@ def _list_supported_connection_types(
310348 }
311349 )
312350
313- if records :
314- df = pd .DataFrame (records )
315-
316- _update_dataframe_datatypes (dataframe = df , column_map = columns )
351+ if rows :
352+ df = pd .DataFrame (rows , columns = list (columns .keys ()))
353+ _update_dataframe_datatypes (dataframe = df , column_map = columns )
317354
318355 return df
319356
0 commit comments