docs: consolidate auth samples into a single samples/login.py - #1877
Draft
jacalata wants to merge 2 commits into
Draft
docs: consolidate auth samples into a single samples/login.py#1877jacalata wants to merge 2 commits into
jacalata wants to merge 2 commits into
Conversation
Merge the previously-separate samples/auth_from_env.py into samples/login.py
so there is one canonical demo of how to sign in to Tableau Server. The
consolidated sample now supports three credential sources composed in
precedence order: CLI args, TABLEAU_* env vars, and (with --interactive)
a getpass password prompt. Env-var names are TABLEAU_-prefixed to avoid
collision with generic shell vars like USERNAME (which Windows sets
automatically for the current OS user).
Public helpers on samples/login.py:
- sample_define_common_options(parser) -- unchanged name; adds
--interactive and --api-version.
- get_env(key, default=None) -- unchanged name.
- resolve_credentials(args) -- new; CLI -> env -> prompt.
- build_server_and_auth(args) -- new; returns (Server, Auth)
without signing in, replacing load_from_env's return shape.
- sample_connect_to_server(args) -- unchanged name; now calls
resolve_credentials + build_server_and_auth then signs in.
- set_up_and_log_in() -- unchanged main entry.
Removes the "Personal Access Token:" getpass fallback in
sample_connect_to_server -- nobody wants to type a 40-character random
string; a missing PAT half now raises the partial-credentials error.
The password getpass prompt is likewise gated on --interactive rather
than triggering silently on a missing --password.
Env-var rename (breaks anyone relying on the pre-change bare names in
login.py::get_env calls, though no other sample called those helpers):
SERVER -> TABLEAU_SERVER
SITE -> TABLEAU_SITE
TOKEN_NAME -> TABLEAU_TOKEN_NAME
TOKEN_VALUE -> TABLEAU_TOKEN
samples/auth_from_env.py is deleted; its load_from_env() shape is now
available as resolve_credentials(args) + build_server_and_auth(args).
The README subsection is retained but points at samples/login.py and
documents the three-source precedence.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…m login.py header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
samples/login.pywas the canonical auth demo but only partially covered the credential-loading space: argparse-driven, withget_envfallback for a few PAT fields, an odd hardcodedserver.version = "3.19"pin after sign-in, and agetpass.getpass("Personal Access Token: ")fallback nobody's going to actually use (PATs are 40-char random strings). Env-var loading for basic auth wasn't there at all.Rather than ship a second sample alongside (originally
samples/auth_from_env.pyin an earlier commit on this branch), this PR consolidates: one sample, three credential sources, clear precedence.Behavior change
Rewritten
samples/login.py:TABLEAU_*env vars > interactive password prompt (with--interactive).TABLEAU_-prefixed to avoid collision with generic shell variables likeUSERNAME(which Windows sets automatically to the OS user account). Pre-changeget_envwas reading bareSERVER/SITE/TOKEN_NAME/TOKEN_VALUE; those are renamed toTABLEAU_SERVERetc. Users relying on the bare names need to update — noted.--interactiveflag prompts for a missing password viagetpass. Requires a TTY — raisesValueErrorif stdin is redirected (pipe, file, non-interactive CI) so the failure mode is loud rather than hanging on stdin. PATs are never prompted for.--api-versionCLI flag +TABLEAU_API_VERSIONenv var replace the previous unconditionalserver.version = "3.19"pin. Default now isuse_server_version=True(auto-negotiate); the pin is opt-in.resolve_credentials(args)andbuild_server_and_auth(args)split the resolution/construction steps from the sign-in step. Callers who want to control the sign-in scope themselves (with server.auth.sign_in(auth): ...) can usebuild_server_and_authand skipsample_connect_to_server.sample_define_common_options,sample_connect_to_server,set_up_and_log_in, andget_envso any external references keep working. Greppedsamples/andtest/: nothing else in-repo imports them, confirmed.getpass.getpass("Personal Access Token: ")fallback — dead weight, no one types 40-char PATs.Testing Run
python -c "from samples.login import sample_define_common_options, sample_connect_to_server, set_up_and_log_in, resolve_credentials, build_server_and_auth, get_env"— all names importable.python samples/login.pywith no args and no env — argparse succeeds, thenbuild_server_and_authraises the "Server URL is required" ValueError cleanly.samples/ortest/file imports fromlogin.py. Verified via grep for each of the public names.samples/in this repo (greppedtest/forfrom samples); none added.blackandmypyclean via pre-commit.