8000 Suggestion for Workbook Update Connection (#149) · williamlang/server-client-python@3fecdf4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3fecdf4

Browse files
cmtoomeyt8y8
authored andcommitted
Suggestion for Workbook Update Connection (tableau#149)
Per tableau#148, an option for updating workbook connections. Includes documentation updates and support for username, port, address, password, and embedded. Patch by @cmtoomey
1 parent b6f3dae commit 3fecdf4

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

docs/docs/api-ref.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ Modifies a workbook. The workbook item object must include the workbook ID and o
180180
Workbooks.update(wb_item_object)
181181
```
182182

183+
### Update workbook connection
184+
185+
Updates a workbook connection string. The workbook connections must be populated before they strings can be updated.
186+
187+
```py
188+
Workbooks.update_conn(workbook, workbook.connections[0])
189+
```
190+
183191
### Delete Workbook
184192

185193
Deletes a workbook with the given ID.

docs/docs/populate-connections-views.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ server.workbooks.populate_connections(workbook)
3434
print([connection.datasource_name for connection in workbook.connections])
3535
```
3636

37+
## Update connections for workbooks
38+
39+
```py
40+
server.workbooks.populate_connections(workbook)
41+
conn_to_update = workbook.connections[0]
42+
conn_to_update.server_address = 'new_address'
43+
conn_to_update.server_port = 1234
44+
conn_to_update.username = 'username'
45+
conn_to_update.password = 'password'
46+
conn_to_update.embed_password = True/False
47+
server.workbooks.update_conn(workbook, conn_to_update)
48+
```
49+
3750
## Populate connections for data sources
3851

3952
```py

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ def update(self, workbook_item):
9191
updated_workbook = copy.copy(workbook_item)
9292
return updated_workbook._parse_common_tags(server_response.content)
9393

94+
# Update workbook_connection
95+
def update_conn(self, workbook_item, connection_item):
96+
url = "{0}/{1}/connections/{2}".format(self.baseurl, workbook_item.id, connection_item.id)
97+
update_req = RequestFactory.WorkbookConnection.update_req(connection_item)
98+
server_response = self.put_request(url, update_req)
99+
logger.info('Updated workbook item (ID: {0} & connection item {1}'.format(workbook_item.id, connection_item.id))
100+
94101
# Download workbook contents with option of passing in filepath
95102
@api(version="2.0")
96103
@parameter_added_in(no_extract='2.5')

tableauserverclient/server/request_factory.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,23 @@ def publish_req_chunked(self, workbook_item, connection_credentials=None):
314314
return _add_multipart(parts)
315315

316316

317+
class WorkbookConnection(object):
318+
def update_req(self, connection_item):
319+
xml_request = ET.Element('tsRequest')
320+
connection_element = ET.SubElement(xml_request, 'connection')
321+
if connection_item.server_address:
322+
connection_element.attrib['serverAddress'] = connection_item.server_address.lower()
323+
if connection_item.server_port:
324+
connection_element.attrib['port'] = str(connection_item.server_port)
325+
if connection_item.username:
326+
connection_element.attrib['userName'] = connection_item.username
327+
if connection_item.password:
328+
connection_element.attrib['password'] = connection_item.password
329+
if connection_item.embed_password:
330+
connection_element.attrib['embedPassword'] = connection_item.embed_password
331+
return ET.tostring(xml_request)
332+
333+
317334
class RequestFactory(object):
318335
Auth = AuthRequest()
319336
Datasource = DatasourceRequest()
@@ -326,3 +343,4 @@ class RequestFactory(object):
326343
Tag = TagRequest()
327344
User = UserRequest()
328345
Workbook = WorkbookRequest()
346+
WorkbookConnection = WorkbookConnection()

0 commit comments

Comments
 (0)
0