Skip to content

Commit

Permalink
fix: create Google Client when the first secret variable appears
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeaning777 committed May 24, 2020
1 parent 716e9b8 commit 27c5d73
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions secret_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ func isSecretUrl(value string) bool {
}

func InjectSecretToEnvironment() error {
client, err := secretmanager.NewClient(context.Background())
if err != nil {
return fmt.Errorf("failed to create secret manager client: %w", err)
}
var client *secretmanager.Client

for _, env := range os.Environ() {
pair := strings.SplitN(env, "=", 2)
Expand All @@ -67,6 +64,14 @@ func InjectSecretToEnvironment() error {
continue
}

if client == nil {
var err error
client, err = secretmanager.NewClient(context.Background())
if err != nil {
return fmt.Errorf("failed to create secret manager client: %w", err)
}
}

path, err := parseSecretUrl(pair[1])
if err != nil {
return fmt.Errorf("parse failed to environment variable %s: %w", pair[0], err)
Expand Down

0 comments on commit 27c5d73

Please sign in to comment.