Skip to content

Commit c677199

Browse files
jacalataclaude
andcommitted
Adopt _shared.py credential helper in inspect_connection_details
Fold the inline sign-in argparse block into the shared helper landed in #1843. Users of this sample now get env / .env / interactive-prompt credential resolution, JWT + username/password auth in addition to PAT, and a clear ValueError when --server is missing under non-TTY, instead of an opaque 400/401 inside TSC. Also update the header's Python-version claim from 3.7 to 3.10 to match `pyproject.toml`'s `requires-python = ">=3.10"`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bbc1e1c commit c677199

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

samples/inspect_connection_details.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# - server-client-python#160 (queryband, initial_sql)
1919
# - server-client-python#353 (SQL Server database + schema + table)
2020
#
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.
2222
####
2323

2424
import argparse
@@ -27,6 +27,8 @@
2727

2828
import tableauserverclient as TSC
2929

30+
from _shared import add_common_arguments, build_auth, resolve_credentials
31+
3032
try:
3133
from tableaudocumentapi import Datasource, Workbook
3234
except ImportError:
@@ -74,28 +76,19 @@ def main():
7476
"Downloads the item via TSC, then parses its embedded XML with tableau-document-api."
7577
)
7678
)
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)
8982
# Options specific to this sample
9083
parser.add_argument("resource_type", choices=["workbook", "datasource"])
9184
parser.add_argument("resource_id", help="LUID of the workbook or datasource")
9285

9386
args = parser.parse_args()
9487

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()))
9790

98-
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
91+
tableau_auth = build_auth(args)
9992
server = TSC.Server(args.server, use_server_version=True)
10093

10194
with server.auth.sign_in(tableau_auth):

0 commit comments

Comments
 (0)