Skip to content
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

Add an environment variable for the number of retries. #320

Merged
merged 2 commits into from
Mar 28, 2023
Merged
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
18 changes: 14 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -52,9 +53,10 @@ const (
S3Backend = "S3"
S3KMSBackend = "S3-KMS"

BackendEnvVar = "CHAMBER_SECRET_BACKEND"
BucketEnvVar = "CHAMBER_S3_BUCKET"
KMSKeyEnvVar = "CHAMBER_KMS_KEY_ALIAS"
BackendEnvVar = "CHAMBER_SECRET_BACKEND"
BucketEnvVar = "CHAMBER_S3_BUCKET"
KMSKeyEnvVar = "CHAMBER_KMS_KEY_ALIAS"
NumRetriesEnvVar = "CHAMBER_RETRIES"

DefaultKMSKey = "alias/parameter_store_key"
)
Expand All @@ -71,7 +73,7 @@ var RootCmd = &cobra.Command{
}

func init() {
RootCmd.PersistentFlags().IntVarP(&numRetries, "retries", "r", DefaultNumRetries, "For SSM or Secrets Manager, the number of retries we'll make before giving up")
RootCmd.PersistentFlags().IntVarP(&numRetries, "retries", "r", DefaultNumRetries, "For SSM or Secrets Manager, the number of retries we'll make before giving up; AKA $CHAMBER_RETRIES")
RootCmd.PersistentFlags().DurationVarP(&minThrottleDelay, "min-throttle-delay", "", store.DefaultMinThrottleDelay, "For SSM, minimal delay before retrying throttled requests. Default 500ms.")
RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "", false, "Print more information to STDOUT")
RootCmd.PersistentFlags().StringVarP(&backendFlag, "backend", "b", "ssm",
Expand Down Expand Up @@ -148,6 +150,14 @@ func getSecretStore() (store.Store, error) {
}
backend = strings.ToUpper(backend)

if numRetriesEnvVarValue := os.Getenv(NumRetriesEnvVar); !rootPflags.Changed("retries") && numRetriesEnvVarValue != "" {
var err error
numRetries, err = strconv.Atoi(numRetriesEnvVarValue)
if err != nil {
return nil, errors.New("Cannot parse $CHAMBER_RETRIES to an integer.")
}
}

var s store.Store
var err error

Expand Down