Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cmd/cloudstic/cmd_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type backupArgs struct {
volumeUUID string
googleCreds string
googleCredsRef string
googleCredsJSON string
googleTokenFile string
googleTokenRef string
onedriveClientID string
Expand Down Expand Up @@ -59,6 +60,7 @@ func parseBackupArgs() *backupArgs {
volumeUUID := fs.String("volume-uuid", envDefault("CLOUDSTIC_VOLUME_UUID", ""), "Override volume UUID for local source (enables cross-machine incremental backup)")
googleCreds := fs.String("google-credentials", envDefault("GOOGLE_APPLICATION_CREDENTIALS", ""), "Path to Google service account credentials JSON file")
googleCredsRef := fs.String("google-credentials-ref", "", "Secret reference to Google service account credentials JSON")
googleCredsJSON := fs.String("google-credentials-json", envDefault("GOOGLE_CREDENTIALS_JSON", ""), "Inline Google credentials JSON (OAuth client or service account)")
googleTokenFile := fs.String("google-token-file", envDefault("GOOGLE_TOKEN_FILE", ""), "Path to Google OAuth token file")
googleTokenRef := fs.String("google-token-ref", "", "Secret reference to Google OAuth token")
onedriveClientID := fs.String("onedrive-client-id", envDefault("ONEDRIVE_CLIENT_ID", ""), "OneDrive OAuth client ID")
Expand All @@ -82,6 +84,7 @@ func parseBackupArgs() *backupArgs {
a.volumeUUID = *volumeUUID
a.googleCreds = *googleCreds
a.googleCredsRef = *googleCredsRef
a.googleCredsJSON = *googleCredsJSON
a.googleTokenFile = *googleTokenFile
a.googleTokenRef = *googleTokenRef
a.onedriveClientID = *onedriveClientID
Expand Down Expand Up @@ -144,6 +147,7 @@ func (r *runner) runSingleBackup(a *backupArgs) int {
volumeUUID: a.volumeUUID,
googleCreds: a.googleCreds,
googleCredsRef: a.googleCredsRef,
googleCredsJSON: a.googleCredsJSON,
googleTokenFile: a.googleTokenFile,
googleTokenRef: a.googleTokenRef,
onedriveClientID: a.onedriveClientID,
Expand Down Expand Up @@ -243,6 +247,9 @@ func ensureDefaultAuthRefForCloudBackup(a *backupArgs) error {
if a.googleCreds != "" {
auth.GoogleCreds = a.googleCreds
}
if a.googleCredsJSON != "" {
auth.GoogleCredsJSON = a.googleCredsJSON
}
auth.GoogleTokenFile = tokenPath
}
if provider == "onedrive" {
Expand Down Expand Up @@ -337,6 +344,9 @@ func mergeProfileBackupArgs(base *backupArgs, profileName string, p cloudstic.Ba
if !a.flagsSet["google-credentials-ref"] && p.GoogleCredsRef != "" {
a.googleCredsRef = p.GoogleCredsRef
}
if !a.flagsSet["google-credentials-json"] && p.GoogleCredsJSON != "" {
a.googleCredsJSON = p.GoogleCredsJSON
}
if !a.flagsSet["google-token-file"] && p.GoogleTokenFile != "" {
a.googleTokenFile = p.GoogleTokenFile
}
Expand Down Expand Up @@ -425,6 +435,9 @@ func applyProfileAuthToBackupArgs(a *backupArgs, auth cloudstic.ProfileAuth) err
if !a.flagsSet["google-credentials-ref"] && auth.GoogleCredsRef != "" {
a.googleCredsRef = auth.GoogleCredsRef
}
if !a.flagsSet["google-credentials-json"] && auth.GoogleCredsJSON != "" {
a.googleCredsJSON = auth.GoogleCredsJSON
}
if !a.flagsSet["google-token-file"] && auth.GoogleTokenFile != "" {
a.googleTokenFile = auth.GoogleTokenFile
}
Expand Down Expand Up @@ -639,6 +652,7 @@ type initSourceOptions struct {
volumeUUID string
googleCreds string
googleCredsRef string
googleCredsJSON string
googleTokenFile string
googleTokenRef string
onedriveClientID string
Expand Down Expand Up @@ -695,6 +709,7 @@ func initSource(ctx context.Context, opts initSourceOptions) (source.Source, err
source.WithResolver(resolver),
source.WithCredsPath(opts.googleCreds),
source.WithCredsRef(opts.googleCredsRef),
source.WithCredsJSON([]byte(opts.googleCredsJSON)),
source.WithTokenPath(tokenPath),
source.WithTokenRef(opts.googleTokenRef),
source.WithDriveName(uri.host),
Expand All @@ -714,6 +729,7 @@ func initSource(ctx context.Context, opts initSourceOptions) (source.Source, err
source.WithResolver(resolver),
source.WithCredsPath(opts.googleCreds),
source.WithCredsRef(opts.googleCredsRef),
source.WithCredsJSON([]byte(opts.googleCredsJSON)),
source.WithTokenPath(tokenPath),
source.WithTokenRef(opts.googleTokenRef),
source.WithDriveName(uri.host),
Expand Down
28 changes: 28 additions & 0 deletions cmd/cloudstic/cmd_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ type profileNewArgs struct {
skipNativeFiles bool
volumeUUID string
googleCreds string
googleCredsRef string
googleCredsJSON string
googleTokenFile string
googleTokenRef string
onedriveClientID string
onedriveTokenFile string
onedriveTokenRef string
flagsSet map[string]bool
}

Expand All @@ -181,9 +185,13 @@ func parseProfileNewArgs() *profileNewArgs {
skipNativeFiles := fs.Bool("skip-native-files", false, "Exclude Google-native files (Docs, Sheets, Slides, etc.)")
volumeUUID := fs.String("volume-uuid", "", "Override volume UUID for local source")
googleCreds := fs.String("google-credentials", "", "Path to Google service account credentials JSON file")
googleCredsRef := fs.String("google-credentials-ref", "", "Secret reference to Google service account credentials JSON")
googleCredsJSON := fs.String("google-credentials-json", "", "Inline Google credentials JSON")
googleTokenFile := fs.String("google-token-file", "", "Path to Google OAuth token file")
googleTokenRef := fs.String("google-token-ref", "", "Secret reference to Google OAuth token")
onedriveClientID := fs.String("onedrive-client-id", "", "OneDrive OAuth client ID")
onedriveTokenFile := fs.String("onedrive-token-file", "", "Path to OneDrive OAuth token file")
onedriveTokenRef := fs.String("onedrive-token-ref", "", "Secret reference to OneDrive OAuth token")
fs.Var(&a.tags, "tag", "Tag to apply to snapshots (repeatable)")
fs.Var(&a.excludes, "exclude", "Exclude pattern (repeatable)")
_ = fs.Parse(reorderArgs(fs, os.Args[3:]))
Expand All @@ -201,9 +209,13 @@ func parseProfileNewArgs() *profileNewArgs {
a.skipNativeFiles = *skipNativeFiles
a.volumeUUID = *volumeUUID
a.googleCreds = *googleCreds
a.googleCredsRef = *googleCredsRef
a.googleCredsJSON = *googleCredsJSON
a.googleTokenFile = *googleTokenFile
a.googleTokenRef = *googleTokenRef
a.onedriveClientID = *onedriveClientID
a.onedriveTokenFile = *onedriveTokenFile
a.onedriveTokenRef = *onedriveTokenRef

return a
}
Expand Down Expand Up @@ -374,9 +386,13 @@ func (r *runner) runProfileNew(ctx context.Context) int {
SkipNativeFiles: a.skipNativeFiles,
VolumeUUID: a.volumeUUID,
GoogleCreds: a.googleCreds,
GoogleCredsRef: a.googleCredsRef,
GoogleCredsJSON: a.googleCredsJSON,
GoogleTokenFile: a.googleTokenFile,
GoogleTokenRef: a.googleTokenRef,
OneDriveClientID: a.onedriveClientID,
OneDriveTokenFile: a.onedriveTokenFile,
OneDriveTokenRef: a.onedriveTokenRef,
}
cfg.Profiles[a.name] = p

Expand Down Expand Up @@ -515,15 +531,27 @@ func prefillProfileArgs(a *profileNewArgs, p cloudstic.BackupProfile) {
if !a.flagsSet["google-credentials"] && p.GoogleCreds != "" {
a.googleCreds = p.GoogleCreds
}
if !a.flagsSet["google-credentials-ref"] && p.GoogleCredsRef != "" {
a.googleCredsRef = p.GoogleCredsRef
}
if !a.flagsSet["google-credentials-json"] && p.GoogleCredsJSON != "" {
a.googleCredsJSON = p.GoogleCredsJSON
}
if !a.flagsSet["google-token-file"] && p.GoogleTokenFile != "" {
a.googleTokenFile = p.GoogleTokenFile
}
if !a.flagsSet["google-token-ref"] && p.GoogleTokenRef != "" {
a.googleTokenRef = p.GoogleTokenRef
}
if !a.flagsSet["onedrive-client-id"] && p.OneDriveClientID != "" {
a.onedriveClientID = p.OneDriveClientID
}
if !a.flagsSet["onedrive-token-file"] && p.OneDriveTokenFile != "" {
a.onedriveTokenFile = p.OneDriveTokenFile
}
if !a.flagsSet["onedrive-token-ref"] && p.OneDriveTokenRef != "" {
a.onedriveTokenRef = p.OneDriveTokenRef
}
if len(a.tags) == 0 && len(p.Tags) > 0 {
a.tags = append(stringArrayFlags{}, p.Tags...)
}
Expand Down
Loading
Loading