@@ -330,79 +330,69 @@ def update_connection(self, workbook_item: WorkbookItem, connection_item: Connec
330330
331331 # Update workbook_connections
332332 @api (version = "3.26" )
333- def update_connections (
334- self ,
335- workbook_item : WorkbookItem ,
336- connection_luids : Iterable [str ],
337- authentication_type : str ,
338- username : Optional [str ] = None ,
339- password : Optional [str ] = None ,
340- embed_password : Optional [bool ] = None ,
341- ) -> list [ConnectionItem ]:
342- """
343- Bulk updates one or more workbook connections by LUID, including authenticationType, username, password, and embedPassword.
333+ def update_connections (self , workbook_item : WorkbookItem , connection_luids : list [str ], authentication_type : str , username : Optional [str ] = None , password : Optional [str ] = None , embed_password : Optional [bool ] = None
334+ ) -> list [str ]:
335+ """
336+ Bulk updates one or more workbook connections by LUID, including authenticationType, username, password, and embedPassword.
344337
345- Parameters
346- ----------
347- workbook_item : WorkbookItem
348- The workbook item containing the connections.
338+ Parameters
339+ ----------
340+ workbook_item : WorkbookItem
341+ The workbook item containing the connections.
349342
350- connection_luids : Iterable of str
351- The connection LUIDs to update.
343+ connection_luids : list of str
344+ The connection LUIDs to update.
352345
353- authentication_type : str
354- The authentication type to use (e.g., 'AD Service Principal').
346+ authentication_type : str
347+ The authentication type to use (e.g., 'AD Service Principal').
355348
356- username : str, optional
357- The username to set (e.g., client ID for keypair auth).
349+ username : str, optional
350+ The username to set (e.g., client ID for keypair auth).
358351
359- password : str, optional
360- The password or secret to set.
352+ password : str, optional
353+ The password or secret to set.
361354
362- embed_password : bool, optional
363- Whether to embed the password.
355+ embed_password : bool, optional
356+ Whether to embed the password.
364357
365- Returns
366- -------
367- Iterable of str
368- The connection LUIDs that were updated.
369- """
358+ Returns
359+ -------
360+ list of str
361+ The connection LUIDs that were updated.
362+ """
363+ from xml .etree .ElementTree import Element , SubElement , tostring
370364
371- url = f"{ self .baseurl } /{ workbook_item .id } /connections"
365+ url = f"{ self .baseurl } /{ workbook_item .id } /connections"
372366
373- request_body = RequestFactory .Workbook .update_connections_req (
374- connection_luids ,
375- authentication_type ,
376- username = username ,
377- password = password ,
378- embed_password = embed_password ,
379- )
367+ ts_request = Element ("tsRequest" )
380368
381- # Send request
382- server_response = self . put_request ( url , request_body )
383- connection_items = ConnectionItem . from_response ( server_response . content , self . parent_srv . namespace )
384- updated_ids : list [ str ] = [ conn . id for conn in connection_items ]
369+ # <connectionLuids>
370+ conn_luids_elem = SubElement ( ts_request , "connectionLuids" )
371+ for luid in connection_luids :
372+ SubElement ( conn_luids_elem , "connectionLuid" ). text = luid
385373
386- logger .info (f"Updated connections for workbook { workbook_item .id } : { ', ' .join (updated_ids )} " )
387- return connection_items
374+ # <connection>
375+ connection_elem = SubElement (ts_request , "connection" )
376+ connection_elem .set ("authenticationType" , authentication_type )
388377
389- T = TypeVar ("T" , bound = FileObjectW )
378+ if username :
379+ connection_elem .set ("userName" , username )
390380
391- @overload
392- def download (
393- self ,
394- workbook_id : str ,
395- filepath : T ,
396- include_extract : bool = True ,
397- ) -> T : ...
381+ if password :
382+ connection_elem .set ("password" , password )
398383
399- @overload
400- def download (
401- self ,
402- workbook_id : str ,
403- filepath : Optional [FilePath ] = None ,
404- include_extract : bool = True ,
405- ) -> str : ...
384+ if embed_password is not None :
385+ connection_elem .set ("embedPassword" , str (embed_password ).lower ())
386+
387+ request_body = tostring (ts_request )
388+
389+ # Send request
390+ response = self .put_request (url , request_body )
391+
392+ logger .info (
393+ f"Updated connections for workbook { workbook_item .id } : { ', ' .join (connection_luids )} "
394+ )
395+ return connection_luids
406396
407397 # Download workbook contents with option of passing in filepath
408398 @api (version = "2.0" )
0 commit comments