-
Notifications
You must be signed in to change notification settings - Fork 448
New APIs: Update multiple connections in a single workbook/datasource #1638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New APIs: Update multiple connections in a single workbook/datasource #1638
Conversation
|
|
||
| @api(version="3.26") | ||
| def update_connections( | ||
| self, datasource_item: DatasourceItem, connection_luids: list[str], authentication_type: str, username: Optional[str] = None, password: Optional[str] = None, embed_password: Optional[bool] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It changes the username, password, embed, and auth type setting uniformly across all of the listed connections?
The type for connection_luids should actually be Iterable[str] since the only criteria is that it can be looped over.
| from xml.etree.ElementTree import Element, SubElement, tostring | ||
|
|
||
| url = f"{self.baseurl}/{datasource_item.id}/connections" | ||
| print("Method URL:", url) | ||
|
|
||
| ts_request = Element("tsRequest") | ||
|
|
||
| # <connectionLuids> | ||
| conn_luids_elem = SubElement(ts_request, "connectionLuids") | ||
| for luid in connection_luids: | ||
| SubElement(conn_luids_elem, "connectionLuid").text = luid | ||
|
|
||
| # <connection> | ||
| connection_elem = SubElement(ts_request, "connection") | ||
| connection_elem.set("authenticationType", authentication_type) | ||
|
|
||
| if username: | ||
| connection_elem.set("userName", username) | ||
|
|
||
| if password: | ||
| connection_elem.set("password", password) | ||
|
|
||
| if embed_password is not None: | ||
| connection_elem.set("embedPassword", str(embed_password).lower()) | ||
|
|
||
| request_body = tostring(ts_request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML payload generation is typically done in the request_factory.py. Can this be moved?
|
|
||
| # Update workbook_connections | ||
| @api(version="3.26") | ||
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments as the datasource function signature.
| from xml.etree.ElementTree import Element, SubElement, tostring | ||
|
|
||
| url = f"{self.baseurl}/{workbook_item.id}/connections" | ||
|
|
||
| ts_request = Element("tsRequest") | ||
|
|
||
| # <connectionLuids> | ||
| conn_luids_elem = SubElement(ts_request, "connectionLuids") | ||
| for luid in connection_luids: | ||
| SubElement(conn_luids_elem, "connectionLuid").text = luid | ||
|
|
||
| # <connection> | ||
| connection_elem = SubElement(ts_request, "connection") | ||
| connection_elem.set("authenticationType", authentication_type) | ||
|
|
||
| if username: | ||
| connection_elem.set("userName", username) | ||
|
|
||
| if password: | ||
| connection_elem.set("password", password) | ||
|
|
||
| if embed_password is not None: | ||
| connection_elem.set("embedPassword", str(embed_password).lower()) | ||
|
|
||
| request_body = tostring(ts_request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as datasource, this belongs in request factory
Also correct the type hints to clarify that it accepts any Iterable.
|
@vchavatapalli thanks for adding this. For a better trail for the record, could you update this PR title & description to explain which are the new APIs you're adding? Also, make sure to run |
chore: refactor XML payload into RequestFactory
This are new API's coming up in next release
Attaching our test document for more details:
https://salesforce.quip.com/gQy6AHWU1Utt