-
Notifications
You must be signed in to change notification settings - Fork 43
fix: extend offline secret caching to token-based auth and fix connection check #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -374,6 +374,33 @@ func GetAllEnvironmentVariables(params models.GetAllSecretsParameters, projectCo | |
| errorToReturn = err | ||
| secretsToReturn = res.Secrets | ||
| } | ||
|
|
||
| // cache secrets on success, fallback to cached secrets on connection/server failure | ||
| if errorToReturn == nil && params.WorkspaceId != "" { | ||
| if backupEncryptionKey, err := GetBackupEncryptionKey(); err == nil { | ||
| WriteBackupSecrets(params.WorkspaceId, params.Environment, params.SecretsPath, backupEncryptionKey, secretsToReturn) | ||
| } | ||
| } else if errorToReturn != nil && params.WorkspaceId != "" { | ||
| // Only fall back to cache for connection errors or server errors (5xx). | ||
| // Do not mask client errors (4xx) like 401/403 which indicate auth issues. | ||
| shouldFallback := true | ||
| var apiErr *api.APIError | ||
| if errors.As(errorToReturn, &apiErr) && apiErr.StatusCode >= 400 && apiErr.StatusCode < 500 { | ||
| shouldFallback = false | ||
| } | ||
|
Comment on lines
+386
to
+390
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| if shouldFallback { | ||
| backupEncryptionKey, _ := GetBackupEncryptionKey() | ||
| if backupEncryptionKey != nil { | ||
| backedUpSecrets, err := ReadBackupSecrets(params.WorkspaceId, params.Environment, params.SecretsPath, backupEncryptionKey) | ||
| if len(backedUpSecrets) > 0 { | ||
| PrintWarning("Unable to fetch the latest secret(s) due to connection error, serving secrets from last successful fetch. For more info, run with --debug") | ||
| secretsToReturn = backedUpSecrets | ||
| errorToReturn = err | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
jakehulberg marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return secretsToReturn, errorToReturn | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.