|
18 | 18 | # - server-client-python#160 (queryband, initial_sql) |
19 | 19 | # - server-client-python#353 (SQL Server database + schema + table) |
20 | 20 | # |
21 | | -# To run the script, you must have installed Python 3.7 or later. |
| 21 | +# To run the script, you must have installed Python 3.10 or later. |
22 | 22 | #### |
23 | 23 |
|
24 | 24 | import argparse |
|
27 | 27 |
|
28 | 28 | import tableauserverclient as TSC |
29 | 29 |
|
| 30 | +from _shared import add_common_arguments, build_auth, resolve_credentials |
| 31 | + |
30 | 32 | try: |
31 | 33 | from tableaudocumentapi import Datasource, Workbook |
32 | 34 | except ImportError: |
@@ -74,28 +76,19 @@ def main(): |
74 | 76 | "Downloads the item via TSC, then parses its embedded XML with tableau-document-api." |
75 | 77 | ) |
76 | 78 | ) |
77 | | - # Common options; please keep those in sync across all samples |
78 | | - parser.add_argument("--server", "-s", help="server address") |
79 | | - parser.add_argument("--site", "-S", help="site name") |
80 | | - parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server") |
81 | | - parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server") |
82 | | - parser.add_argument( |
83 | | - "--logging-level", |
84 | | - "-l", |
85 | | - choices=["debug", "info", "error"], |
86 | | - default="error", |
87 | | - help="desired logging level (set to error by default)", |
88 | | - ) |
| 79 | + # Common options -- credentials come from CLI args, env vars, a .env file, |
| 80 | + # or an interactive prompt. See samples/_shared.py. |
| 81 | + add_common_arguments(parser) |
89 | 82 | # Options specific to this sample |
90 | 83 | parser.add_argument("resource_type", choices=["workbook", "datasource"]) |
91 | 84 | parser.add_argument("resource_id", help="LUID of the workbook or datasource") |
92 | 85 |
|
93 | 86 | args = parser.parse_args() |
94 | 87 |
|
95 | | - logging_level = getattr(logging, args.logging_level.upper()) |
96 | | - logging.basicConfig(level=logging_level) |
| 88 | + resolve_credentials(args) |
| 89 | + logging.basicConfig(level=getattr(logging, args.logging_level.upper())) |
97 | 90 |
|
98 | | - tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) |
| 91 | + tableau_auth = build_auth(args) |
99 | 92 | server = TSC.Server(args.server, use_server_version=True) |
100 | 93 |
|
101 | 94 | with server.auth.sign_in(tableau_auth): |
|
0 commit comments