samples: credential helper, pagination fixes, and new jobs/subscriptions samples - #1843
Open
jacalata wants to merge 3 commits into
Open
samples: credential helper, pagination fixes, and new jobs/subscriptions samples#1843jacalata wants to merge 3 commits into
jacalata wants to merge 3 commits into
Conversation
Introduces samples/_shared.py with resolve_credentials(args), which fills missing sign-in values from env vars (TABLEAU_SERVER, TABLEAU_TOKEN_NAME, etc.) or a .env-style file, and falls back to interactive getpass so secrets never touch shell history. CLI args still work for CI use. Wires the new helper into login.py, publish_workbook.py, and publish_datasource.py to establish the pattern; the remaining samples still accept the same CLI args and continue to work as before. Addresses #1551 item 1.
Several samples called `server.<endpoint>.get()` and named the result `all_workbooks`, `all_datasources`, etc. This only returns the first page (default 100 items); if the item of interest was not on that page it was silently missed and the sample failed with a "not found" message. Replace those calls with `TSC.Pager(server.<endpoint>)` so every page is walked. Where a total count was being displayed we still make one plain `.get()` up front so the total_available field is available without paging through the whole site twice. Also corrects an unrelated typo in getting_started/3_hello_universe.py where the "workbooks" section actually queried datasources. Addresses #1551 item 2 (and #1531).
The existing samples cover workbooks, datasources, schedules, extracts,
projects, users, groups, favorites, and webhooks, but there was no
sample for two frequently asked-about endpoints:
* list_jobs.py -- lists background jobs (extract refreshes, publishes,
flow runs, etc.), demonstrating the .filter() queryset with
date/status/type filters and the wait_for_job helper.
* manage_subscriptions.py -- list/create/delete site subscriptions,
demonstrating the SubscriptionItem + Target pattern and paginated
listing with TSC.Pager.
Both samples use the new samples/_shared.py credential resolver so the
sign-in pattern matches the rest of the samples.
Addresses #1551 item 3.
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.
Closes #1551.
The issue listed three concerns; each is addressed as a separate commit
for reviewability.
Read credentials better than the command line. Adds
samples/_shared.pywith aresolve_credentials(args)helper thatfills missing sign-in values from environment variables
(
TABLEAU_SERVER,TABLEAU_TOKEN_NAME, etc.) or a plain.envfile,and falls back to
getpass.getpass()for anything still missing.CLI args continue to work for CI use, but are no longer the only
option. The helper is wired into
login.py,publish_workbook.py,and
publish_datasource.pyto establish the pattern; the remainingsamples still accept the same CLI args and are left alone so this
change stays surgical. No new dependencies are added (stdlib only).
Fix incorrect 'paging' used in several samples (referencing server.views.populate_image gives outdated image even with refresh to the datasource #1531).
Several samples called
server.<endpoint>.get()and named the resultall_workbooks,all_datasources, etc. That only returns the firstpage (default 100 items), so if the item of interest is not on that
page the sample silently misses it. Replaces those calls with
TSC.Pager(server.<endpoint>)so every page is walked. Where a totalcount was being displayed we still make one plain
.get()up frontso
total_availableis available without paging the whole sitetwice.
Also corrects an unrelated bug in
getting_started/3_hello_universe.pywhere the workbooks sectionactually queried datasources.
Comprehensive coverage. Adds two new samples for the biggest
endpoint gaps:
list_jobs.py-- background jobs (extract refreshes, publishes,flow runs, etc.), demonstrating the
.filter()queryset API withdate/status/type filters and
wait_for_job.manage_subscriptions.py-- list/create/delete subscriptions,demonstrating
SubscriptionItem+Targetand paginated listingwith
TSC.Pager.Not exhaustive on coverage -- data alerts, metrics, tables, databases,
virtual connections still have no dedicated sample. Left those for
follow-up rather than force a wide sweep in one PR.
Test plan
python samples/login.py --helpshows the new--env-file/--username/--passwordflags and the updated help text.TABLEAU_TOKEN_NAME/TABLEAU_TOKEN_VALUEin a shelland running
python samples/login.py -s <server>signs in withoutany secrets passed on the command line.
python samples/list_jobs.py --hours 24lists recent jobs; thesame script with
--wait <job_id>blocks until the job finishes.python samples/manage_subscriptions.py listprints existingsubscriptions;
createthendeleteround-trips cleanly.explore_datasource.py,explore_workbook.py,extracts.py,update_workbook_data_freshness_policy.py,and
publish_workbook.pycontinues to return the same behavior onsmall sites while now correctly handling >100-item sites.
Generated with Claude Code.