Skip to content

feat(gcs): filename date/time tokens + manual bucket override for cross-project delivery#757

Open
vklm2002 wants to merge 3 commits into
looker-open-source:masterfrom
vklm2002:gcs-filename-date-tokens
Open

feat(gcs): filename date/time tokens + manual bucket override for cross-project delivery#757
vklm2002 wants to merge 3 commits into
looker-open-source:masterfrom
vklm2002:gcs-filename-date-tokens

Conversation

@vklm2002

Copy link
Copy Markdown

Summary

Two backward-compatible enhancements to the Google Cloud Storage action.

1. Filename date/time tokens

The destination object name now supports UTC tokens that are substituted at delivery time, before the existing Overwrite uniqueness timestamp. Each token is replaced independently wherever it appears, so any format can be composed with your own separators. Because GCS object names may contain /, this also enables date-/time-partitioned "folders" with no extra field.

Token Meaning Example (2026-06-17 08:30:45Z)
{YYYYMMDD} year+month+day composite 20260617
{YYYY} 4-digit year 2026
{YY} 2-digit year 26
{MM} month 06
{DD} day of month 17
{HH} hour, 24-hour 08
{mm} minutes 30
{ss} seconds 45

Tokens are case-sensitive (moment.js convention): {MM} is month, {mm} is minutes. {YYYYMMDD} is a convenience for {YYYY}{MM}{DD}.

Before / after

report_{YYYYMMDD}.csv               ->  report_20260617.csv
{YYYY}-{MM}-{DD}.csv                ->  2026-06-17.csv
daily/{YYYY}/{MM}/report.csv        ->  gs://<bucket>/daily/2026/06/report.csv
hourly/{YYYYMMDD}T{HH}{mm}{ss}.csv  ->  gs://<bucket>/hourly/20260617T083045.csv

Implemented with the built-in Dateno new npm dependencies (no moment/dayjs).

2. Manual bucket override (cross-project / third-party delivery)

The Bucket dropdown is populated by gcs.getBuckets(), which requires the project-level storage.buckets.list permission. Delivering a scheduled Look to a partner's bucket in their GCP project shouldn't require granting project-level IAM to your service account — partners will (correctly) only grant roles/storage.objectCreator on the single target bucket.

This PR:

  • makes getBuckets() non-fatal — if listing fails (or returns nothing), the form renders with an empty dropdown instead of erroring;
  • adds an optional "Bucket name (manual override)" field (bucket_override) that takes precedence over the dropdown.

execute() then only needs storage.objects.create on the target bucket.

Backward compatibility

  • Filenames with no tokens are unchanged.
  • The Overwrite = "No" Date.now() uniqueness suffix is intact (tokens are substituted first).
  • Existing formParams.bucket (dropdown) behavior is unchanged when no override is supplied.

Design note: time zone

Tokens resolve against the action hub server's UTC clock, not the query/schedule timezone. The action only receives the rendered data file, not the query's filters or timezone, so server-side UTC is used for deterministic, predictable partitioning. This is documented in the action README and called out here in case maintainers prefer a different stance.

Testing

yarn test (mocha + tsc --noEmit + tslint) passes clean for this action: typecheck ✅, lint ✅, and all GCS tests pass. New/updated tests cover {YYYYMMDD} resolution, tokens combined with path segments, {YY}, the {HH}/{mm}/{ss} time tokens, the {MM}-vs-{mm} case-sensitivity distinction, the no-token regression, token-before-timestamp ordering, bucket_override precedence, and the non-fatal bucket-listing form behavior.

Docs

Token syntax and the manual bucket override are documented in the Filename form-field description and in src/actions/google/gcs/README.md.

CLA

This is a Google-owned repository and requires a signed Contributor License Agreement before it can be merged. The contributor will sign the CLA.

🤖 Generated with Claude Code

vklm2002 added 2 commits June 20, 2026 00:33
Two backward-compatible enhancements to the Google Cloud Storage action.

1. Filename date tokens
   Substitute UTC date tokens anywhere in the resolved filename before the
   existing Overwrite timestamp logic: {YYYYMMDD}, {YYYY}, {MM}, {DD}
   (zero-padded, UTC). Because GCS object names may contain "/", this enables
   date-partitioned "folders", e.g. "daily/report_{YYYYMMDD}.csv" ->
   "daily/report_20260617.csv". Filenames without tokens are unchanged and the
   Overwrite="no" Date.now() uniqueness suffix still applies. No new deps.

2. Manual bucket override for cross-project / third-party delivery
   The "Bucket" dropdown is populated by gcs.getBuckets(), which requires
   project-level storage.buckets.list. Delivering to a partner's bucket in
   another project should not require granting project-level IAM. Make
   getBuckets() non-fatal (render the form with an empty dropdown instead of
   erroring) and add an optional "Bucket name (manual override)" field that
   takes precedence. execute() then only needs storage.objects.create on the
   target bucket.

Docs: document the token syntax and manual override in the Filename form-field
descriptions and in the action README (including the UTC server-clock note).

Tests: add cases for {YYYYMMDD} resolution, tokens combined with path segments,
no-token regression, token-before-timestamp ordering, and bucket_override
precedence; update the form tests for the non-fatal listing behavior.
Extend filename token substitution beyond the date-only set:

- {YY}  : 2-digit year (e.g. 26)
- {HH}  : 2-digit UTC hour, 24-hour (e.g. 08)
- {mm}  : 2-digit UTC minutes (e.g. 30)
- {ss}  : 2-digit UTC seconds (e.g. 45)

Tokens are replaced independently wherever they appear, so any format can be
composed with arbitrary separators, e.g. "{YYYY}-{MM}-{DD}_{HH}{mm}{ss}" or
"report_{MM}-{DD}-{YY}.csv". Tokens are case-sensitive (moment.js convention):
{MM} is month while {mm} is minutes. This enables sub-daily (hourly/by-minute)
partitioning in addition to date partitioning.

Updates the Filename form-field description, README token table/examples, and
adds tests for {YY}, the {HH}/{mm}/{ss} time tokens, and the {MM}-vs-{mm}
case-sensitivity distinction.
@vklm2002 vklm2002 requested a review from a team as a code owner June 20, 2026 04:44
@google-cla

google-cla Bot commented Jun 20, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for UTC date/time tokens in filenames and adds a manual bucket override option to allow writing to GCS buckets in other projects where the service account lacks project-level listing permissions. The form fields and documentation have been updated accordingly, along with comprehensive unit tests. The feedback suggests trimming the manual bucket override input to prevent potential whitespace issues that could lead to API errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/actions/google/gcs/google_cloud_storage.ts Outdated
Address review feedback: the manual bucket override is free-form text and
users often copy-paste bucket names, which can introduce leading/trailing
whitespace (spaces, newlines) and cause hard-to-debug GCS API errors (400/404).

Trim bucket_override before use; a whitespace-only value trims to "" and falls
back to the dropdown bucket. Tighten the test helper's bucket assertion to an
exact match (calledWith) so the trimming is actually verified, and add tests
for the trimmed and whitespace-only-fallback cases.
@vklm2002

Copy link
Copy Markdown
Author

@googlebot I signed it!

@vklm2002 vklm2002 force-pushed the gcs-filename-date-tokens branch from c267b0b to 8d8c865 Compare June 20, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant