Skip to content

Commit

Permalink
Set up generic function to execute aws-vault's LoadConfigFromEnv func…
Browse files Browse the repository at this point in the history
…tion silently, without outputting any logs to the console
  • Loading branch information
arunsathiya committed Jun 21, 2023
1 parent c014fe3 commit b179903
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 1 addition & 9 deletions plugins/aws/sts_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package aws
import (
"context"
"fmt"
"io"
"log"
"os"
"time"

Expand Down Expand Up @@ -182,18 +180,12 @@ func (m CacheProviderFactory) NewAccessKeysProvider() aws.CredentialsProvider {

// getAWSAuthConfigurationForProfile loads specified configurations from both config file and environment
func getAWSAuthConfigurationForProfile(profile string) (*confighelpers.Config, error) {
// Disable log output produced by AWS Vault code
log.SetOutput(io.Discard)

// Read config file from the location set in AWS_CONFIG_FILE env var or from ~/.aws/config
configFile, err := confighelpers.LoadConfigFromEnv()
configFile, err := ExecuteSilently(confighelpers.LoadConfigFromEnv)()
if err != nil {
return nil, err
}

// Re-enable log output
log.SetOutput(os.Stderr)

configLoader := confighelpers.ConfigLoader{
File: configFile,
ActiveProfile: profile,
Expand Down
13 changes: 13 additions & 0 deletions plugins/aws/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package aws

import (
"fmt"
"io"
"log"
"os"

"github.com/99designs/aws-vault/v7/vault"
"gopkg.in/ini.v1"
)

Expand All @@ -20,3 +24,12 @@ func getConfigSectionByProfile(configFile *ini.File, profileName string) *ini.Se

return nil
}

func ExecuteSilently(f func() (*vault.ConfigFile, error)) func() (*vault.ConfigFile, error) {
return func() (*vault.ConfigFile, error) {
log.SetOutput(io.Discard)
vaultConfig, err := f()
defer log.SetOutput(os.Stderr)
return vaultConfig, err
}
}

0 comments on commit b179903

Please sign in to comment.