-
Notifications
You must be signed in to change notification settings - Fork 0
chore: refactor XML payload into RequestFactory #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,8 +321,14 @@ def update_connection( | |
|
||
@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 | ||
) -> list[str]: | ||
self, | ||
datasource_item: DatasourceItem, | ||
connection_luids: Iterable[str], | ||
authentication_type: str, | ||
username: Optional[str] = None, | ||
password: Optional[str] = None, | ||
embed_password: Optional[bool] = None, | ||
) -> Iterable[str]: | ||
""" | ||
Bulk updates one or more datasource connections by LUID. | ||
|
||
|
@@ -331,7 +337,7 @@ def update_connections( | |
datasource_item : DatasourceItem | ||
The datasource item containing the connections. | ||
|
||
connection_luids : list of str | ||
connection_luids : Iterable of str | ||
The connection LUIDs to update. | ||
|
||
authentication_type : str | ||
|
@@ -348,41 +354,23 @@ def update_connections( | |
|
||
Returns | ||
------- | ||
list of str | ||
Iterable of str | ||
The connection LUIDs that were updated. | ||
""" | ||
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) | ||
|
||
request_body = RequestFactory.Datasource.update_connections_req( | ||
connection_luids=connection_luids, | ||
authentication_type=authentication_type, | ||
username=username, | ||
password=password, | ||
embed_password=embed_password, | ||
) | ||
response = self.put_request(url, request_body) | ||
|
||
logger.info( | ||
f"Updated connections for datasource {datasource_item.id}: {', '.join(connection_luids)}" | ||
) | ||
logger.info(f"Updated connections for datasource {datasource_item.id}: {', '.join(connection_luids)}") | ||
return connection_luids | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As outlined in this PR, the function works with any |
||
|
||
@api(version="2.8") | ||
|
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 response doesn't seem to get used. Can you give me an example response XML?
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 response is just a success message, so not necessarily needs to be used.