Skip to content

Commit

Permalink
feat: Reuse keyring connection when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreZiviani committed Mar 10, 2023
1 parent 0895e38 commit e43aabd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/securestorage/iam-credential-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func NewSecureIAMCredentialStorage() IAMCredentialsSecureStorage {
SecureStorage: SecureStorage{
StoragePrefix: "aws-fuzzy",
StorageSuffix: "aws-iam-credentials",
Debug: false,
},
}
}
Expand Down
8 changes: 8 additions & 0 deletions internal/securestorage/securestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
type SecureStorage struct {
StoragePrefix string
StorageSuffix string
Debug bool
keyring keyring.Keyring
}

// returns false if the key is not found, true if it is found, or false and an error if there was a keyring related error
Expand Down Expand Up @@ -102,6 +104,10 @@ func (s *SecureStorage) ListKeys() ([]string, error) {
}

func (s *SecureStorage) openKeyring() (keyring.Keyring, error) {
if s.keyring != nil {
return s.keyring, nil
}

cfg, err := afconfig.NewLoadedConfig()
if err != nil {
return nil, err
Expand Down Expand Up @@ -168,5 +174,7 @@ func (s *SecureStorage) openKeyring() (keyring.Keyring, error) {
return nil, errors.Wrap(err, "opening keyring")
}

s.keyring = k

return k, nil
}
1 change: 1 addition & 0 deletions internal/securestorage/sso-token-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func NewSecureSSOTokenStorage() SSOTokensSecureStorage {
SecureStorage: SecureStorage{
StoragePrefix: "aws-fuzzy",
StorageSuffix: "-sso-tokens",
Debug: false,
},
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/sso/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ssooidc"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/common-fate/clio"
opentracing "github.com/opentracing/opentracing-go"
)

Expand All @@ -37,6 +38,10 @@ func (p *Login) Execute(args []string) error {
spanSso, ctx := opentracing.StartSpanFromContextWithTracer(ctx, tracer, "ssologincmd")
defer spanSso.Finish()

if p.Verbose {
clio.SetLevelFromString("debug")
}

creds, err := p.GetCredentials(ctx)
if err != nil {
return err
Expand Down

0 comments on commit e43aabd

Please sign in to comment.