Skip to content

Commit a40d774

Browse files
committed
Added response parsing
1 parent 9c2bec3 commit a40d774

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

samples/update_connections_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main():
4848
embed_password = args.embed_password.lower() == "true"
4949

5050
# Call unified update_connections method
51-
updated_ids = endpoint.update_connections(
51+
connection_items = endpoint.update_connections(
5252
resource,
5353
connection_luids=connection_luids,
5454
authentication_type=args.authentication_type,
@@ -57,7 +57,7 @@ def main():
5757
embed_password=embed_password,
5858
)
5959

60-
print(f"Updated connections on {args.resource_type} {args.resource_id}: {updated_ids}")
60+
print(f"Updated connections on {args.resource_type} {args.resource_id}: {connection_items}")
6161

6262

6363
if __name__ == "__main__":

tableauserverclient/server/endpoint/datasources_endpoint.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,12 @@ def update_connections(
367367
password=password,
368368
embed_password=embed_password,
369369
)
370-
response = self.put_request(url, request_body)
370+
server_response = self.put_request(url, request_body)
371+
connection_items = list(ConnectionItem.from_response(server_response.content, self.parent_srv.namespace))
372+
updated_ids = [conn.id for conn in connection_items]
371373

372-
logger.info(f"Updated connections for datasource {datasource_item.id}: {', '.join(connection_luids)}")
373-
return connection_luids
374+
logger.info(f"Updated connections for datasource {datasource_item.id}: {', '.join(updated_ids)}")
375+
return connection_items
374376

375377
@api(version="2.8")
376378
def refresh(self, datasource_item: DatasourceItem, incremental: bool = False) -> JobItem:

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,12 @@ def update_connections(
376376
)
377377

378378
# Send request
379-
response = self.put_request(url, request_body)
379+
server_response = self.put_request(url, request_body)
380+
connection_items = list(ConnectionItem.from_response(server_response.content, self.parent_srv.namespace))
381+
updated_ids = [conn.id for conn in connection_items]
380382

381-
logger.info(f"Updated connections for workbook {workbook_item.id}: {', '.join(connection_luids)}")
382-
return connection_luids
383+
logger.info(f"Updated connections for workbook {workbook_item.id}: {', '.join(updated_ids)}")
384+
return connection_items
383385

384386
# Download workbook contents with option of passing in filepath
385387
@api(version="2.0")
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<tsResponse xmlns="http://tableau.com/api"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.26.xsd">
4+
xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_25.xsd">
55
<connections>
66
<connection id="be786ae0-d2bf-4a4b-9b34-e2de8d2d4488"
77
type="sqlserver"
88
serverAddress="updated-server"
99
serverPort="1433"
1010
userName="user1"
1111
embedPassword="true"
12-
authentication="auth-keypair" />
12+
authenticationType="auth-keypair" />
1313
<connection id="a1b2c3d4-e5f6-7a8b-9c0d-123456789abc"
1414
type="sqlserver"
1515
serverAddress="updated-server"
1616
serverPort="1433"
1717
userName="user1"
1818
embedPassword="true"
19-
authentication="auth-keypair" />
19+
authenticationType="auth-keypair" />
2020
</connections>
2121
</tsResponse>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<tsResponse xmlns="http://tableau.com/api"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.26.xsd">
4+
xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_25.xsd">
55
<connections>
66
<connection id="abc12345-def6-7890-gh12-ijklmnopqrst"
77
type="sqlserver"
88
serverAddress="updated-db-host"
99
serverPort="1433"
1010
userName="svc-client"
1111
embedPassword="true"
12-
authentication="AD Service Principal" />
12+
authenticationType="AD Service Principal" />
1313
<connection id="1234abcd-5678-efgh-ijkl-0987654321mn"
1414
type="sqlserver"
1515
serverAddress="updated-db-host"
1616
serverPort="1433"
1717
userName="svc-client"
1818
embedPassword="true"
19-
authentication="AD Service Principal" />
19+
authenticationType="AD Service Principal" />
2020
</connections>
2121
</tsResponse>

test/test_datasource.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,17 @@ def test_update_connections(self) -> None:
244244
print("BASEURL:", self.server.baseurl)
245245
print("Calling PUT on:", f"{self.server.baseurl}/{datasource.id}/connections")
246246

247-
updated_luids = self.server.datasources.update_connections(
247+
connection_items = self.server.datasources.update_connections(
248248
datasource_item=datasource,
249249
connection_luids=connection_luids,
250250
authentication_type="auth-keypair",
251251
username="testuser",
252252
password="testpass",
253253
embed_password=True,
254254
)
255+
updated_ids = [conn.id for conn in connection_items]
255256

256-
self.assertEqual(updated_luids, connection_luids)
257+
self.assertEqual(updated_ids, connection_luids)
257258

258259
def test_populate_permissions(self) -> None:
259260
with open(asset(POPULATE_PERMISSIONS_XML), "rb") as f:

test/test_workbook.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,16 +1001,17 @@ def test_update_workbook_connections(self) -> None:
10011001
text=response_xml,
10021002
)
10031003

1004-
updated_luids = self.server.workbooks.update_connections(
1004+
connection_items = self.server.workbooks.update_connections(
10051005
workbook_item=workbook,
10061006
connection_luids=connection_luids,
10071007
authentication_type="AD Service Principal",
10081008
username="svc-client",
10091009
password="secret-token",
10101010
embed_password=True,
10111011
)
1012+
updated_ids = [conn.id for conn in connection_items]
10121013

1013-
self.assertEqual(updated_luids, connection_luids)
1014+
self.assertEqual(updated_ids, connection_luids)
10141015

10151016
def test_get_workbook_all_fields(self) -> None:
10161017
self.server.version = "3.21"

0 commit comments

Comments
 (0)