Open benlower opened 8 years ago
This is significantly non-trivial.
do we need a "SNT" label for items like this then? :)
So wait, it's not a matter of using a conditional on the datasource? I couldn't just modify the below example to change the server name and save the workbook whenever the script is run?
from tableaudocumentapi import Workbook
sourceWB = Workbook('WorkbookToUpdate.twb')
sourceWB.datasources[0].connections[0].server = "MY-NEW-SERVER"
sourceWB.datasources[0].connections[0].dbname = "NEW-DATABASE"
sourceWB.datasources[0].connections[0].username = "benl"
sourceWB.save()
@jessebikman it depends on what the original ask meant to cover for 'Replace Data Source' -- Tableau Desktop has a feature by that name that re-targets all worksheets (including calculations and table calcs) to use the new data source (which may have slightly different properties, like comments on fields).
That's 'SNT'
Just changing the connection information ('sql-dev' to 'sql-prod') is pretty easy, and as you point out, possible today.
Oh yes, the feature named that! Ok - thanks for making that more clear. Obvious in hindsight now.
I've run the sample code to modify and save a workbook. I can change the Server name, the Database name, the User name, and the Port, but there does not seem to be any way to change the database table. Hardly seems useful without that. Am I missing something?
@ebolz please open a new issue with a quick example.
Right now the connection object doesn't expose table name (not all connection types have table) but it would be easy to add!
What I'd like is a merge option. if you add a datasource or sheet+datasource, if datasource with same connection details exists, add all customizations and calculated fields from new source to existing. log report for merge conflicts where there are name collisions, etc...
scenario (assumes you know what logshark is or will go look it up now):
In this code: sourceWB.datasources[0].connections[0].server = "MY-NEW-SERVER" sourceWB.datasources[0].connections[0].dbname = "NEW-DATABASE" sourceWB.datasources[0].connections[0].username = "benl"
It does not seem like Document API allows a way for the user to give the password for the database. Does it assume the password is the same in "NEW-DATABSE" as it was in the old database? I don't understand how it can ask for a database user but not password.
Hi guys, Sorry but rookie to Python and API syntax... Though I did manage to adapt the TSC API codes to my own stuff (server, site, db, etc...), I couldn't find a way to make these 3 lines of code from document API to work fine !!
First, I have not been able to make this code find my workbook from its name !! Server problem ? Name ? What is wrong ? Does it need the whole path to the physical file ? assumed it was working n the server, then try full path but didn't work either.
As a resume : I am lost ;) THANKS in advance for your help.
from tableaudocumentapi import Workbook sourceWB = Workbook('WorkbookToUpdate.twb') sourceWB.datasources[0].connections[0].server = "MY-NEW-SERVER" sourceWB.datasources[0].connections[0].dbname = "NEW-DATABASE" sourceWB.datasources[0].connections[0].username = "benl" sourceWB.save()
@benlower Hi! I am surprised this is of more interest - or maybe I am missing something. I would imagine MANY would like to have two published data sources (exactly the same with the exception of the connection string) - call them "stg" and "prod". Those data sources are likely being refreshed regularly. Now, I as the admin have a .twb with connections to the published data sources (which are federated btw). What I would like to do is take the ONE .twb workbook which is using the "stg" data source on server. Id like to save over the existing workbook, then switch the "stg" to "prod" datasource (which are exactly the same besides the connection details) and publish. What am i missing? I would think (while dangerous in many circumstances) I could replace a "datasource".
@YEM-1 (or anyone else that is interested) I'm fairly confident that a .twbx/.twb file does not store a password. I would assume this was a deliberate security decision by the Tableau team. It certainly seems like a wise decision to me.
@YEM-1 (or anyone else that is interested) I'm fairly confident that a .twbx/.twb file does not store a password. I would assume this was a deliberate security decision by the Tableau team. It certainly seems like a wise decision to me.
Published data sources contain embedded passwords.
@YEM-1 (or anyone else that is interested) I'm fairly confident that a .twbx/.twb file does not store a password. I would assume this was a deliberate security decision by the Tableau team. It certainly seems like a wise decision to me.
Published data sources contain embedded passwords.
Well, I suppose that is easy to say. Do you have any evidence the password is present in the .twb/.twbx file? The .twb file is simply XML, its easy to examine. There is also the behavior of Tableau itself, which seems to repeatedly request passwords in a manner indicating that the .twb/.twbx files aren't archiving them.
Hi @YEM-1 the twb/twbx/tds/tdsx does not contain the password so the document api does not provide a way to embed the password. Embedded passwords are only a concept in the context of Tableau Server, and they are stored in a secure manner separate from the datasource documents as you would expect from any secure application that needs to store and handle user provided credentials.
@RussTheAerialist Thanks! So say we all.
I'm currently looking for a way to replace one published datasource with another. I'm not sure if this is currently possible (just started exploring the Document API)... but anyway I think an API contract like this would be nice to have:
WB = Workbook('..\data\myDownloadedWB.twbx') newDS = Datasource.from_file('..\data\myDownloadedDS.tdsx') WB.datasources[0].save(newDS)
An even better solution would be to let us do this directly on the server! Currently I'm using the REST API to download/publish
(via beta feedback)
Replace data source -- we have QA and prod data sources and it would be good to be able to change the data source a worksheet uses programmatically