Skip to content

feat: add WithDriveService, WithCredsJSON and --google-credentials-json flag#177

Merged
rmanibus merged 1 commit into
mainfrom
feat/gdrive-credentials-flexibility
Mar 20, 2026
Merged

feat: add WithDriveService, WithCredsJSON and --google-credentials-json flag#177
rmanibus merged 1 commit into
mainfrom
feat/gdrive-credentials-flexibility

Conversation

@rmanibus
Copy link
Copy Markdown
Contributor

Add two new GDrive source options for improved flexibility:

  • WithDriveService: inject a pre-built *drive.Service (for library users managing auth externally via ADC, custom TokenSource, etc.)
  • WithCredsJSON: provide credentials as inline JSON bytes (mirrors rclone's service_account_credentials option)

Add --google-credentials-json CLI flag and GOOGLE_CREDENTIALS_JSON env var so inline credential JSON can be provided without mounting files (ideal for CI/CD and containerised environments). Wire through profiles and auth entries.

Refactor the auth logic in NewGDriveSource: extract buildDriveService, loadCredsBytes, serviceFromCredsBytes, and resolveDriveName helpers. The constructor drops from ~120 lines to ~50 with clear early-return priority:

  1. Pre-built service (WithDriveService)
  2. Custom HTTP client (WithHTTPClient)
  3. Explicit credentials (inline JSON > secret ref > file path)
  4. Built-in default OAuth client

Update user guide with credential documentation and env var table.

@rmanibus rmanibus added this to the v1.14.0 milestone Mar 20, 2026
@rmanibus rmanibus added the enhancement New feature or request label Mar 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 43.22581% with 88 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/source/gdrive.go 15.29% 70 Missing and 2 partials ⚠️
cmd/cloudstic/cmd_backup.go 27.27% 5 Missing and 3 partials ⚠️
cmd/cloudstic/cmd_profile.go 60.00% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

…on flag

Add two new GDrive source options for improved flexibility:
- WithDriveService: inject a pre-built *drive.Service (for library users
  managing auth externally via ADC, custom TokenSource, etc.)
- WithCredsJSON: provide credentials as inline JSON bytes (mirrors rclone's
  service_account_credentials option)

Add --google-credentials-json CLI flag and GOOGLE_CREDENTIALS_JSON env var
so inline credential JSON can be provided without mounting files (ideal for
CI/CD and containerised environments). Wire through profiles and auth entries.

Refactor the auth logic in NewGDriveSource: extract buildDriveService,
loadCredsBytes, serviceFromCredsBytes, and resolveDriveName helpers. The
constructor drops from ~120 lines to ~50 with clear early-return priority:
  1. Pre-built service (WithDriveService)
  2. Custom HTTP client (WithHTTPClient)
  3. Explicit credentials (inline JSON > secret ref > file path)
  4. Built-in default OAuth client

Update user guide with credential documentation and env var table.
@rmanibus rmanibus force-pushed the feat/gdrive-credentials-flexibility branch from 0e18ea8 to 47059c7 Compare March 20, 2026 14:31
@rmanibus rmanibus linked an issue Mar 20, 2026 that may be closed by this pull request
@rmanibus rmanibus merged commit 1229d13 into main Mar 20, 2026
11 of 12 checks passed
@rmanibus rmanibus deleted the feat/gdrive-credentials-flexibility branch March 20, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: improve Google Drive credential flexibility and readability

1 participant