Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #129 from secrethub/feature/use-aws
Browse files Browse the repository at this point in the history
Use AWS identity provider with SECRETHUB_IDENTITY_PROVIDER=aws envvar
  • Loading branch information
SimonBarendse authored Sep 6, 2019
2 parents 9466a59 + 1b6648d commit 5268dc9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/secrethub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const (
userAgentPrefix = "SecretHub/v1 secrethub-go/" + ClientVersion
)

// Errors
var (
ErrUnknownIdentityProvider = errClient.Code("unknown_identity_provider").ErrorPref("%s is not a supported identity provider. Valid options are `aws` and `key`.")
)

// ClientInterface is an interface that can be used to consume the SecretHub client and is implemented by secrethub.Client.
type ClientInterface interface {
// AccessRules returns a service used to manage access rules.
Expand Down Expand Up @@ -110,7 +115,19 @@ func NewClient(with ...ClientOption) (*Client, error) {

// Try to use default key credentials if none provided explicitly
if client.decrypter == nil {
err := client.with(WithCredentials(credentials.UseKey(client.DefaultCredential())))
identityProvider := os.Getenv("SECRETHUB_IDENTITY_PROVIDER")

var provider credentials.Provider
switch strings.ToLower(identityProvider) {
case "", "key":
provider = credentials.UseKey(client.DefaultCredential())
case "aws":
provider = credentials.UseAWS()
default:
return nil, ErrUnknownIdentityProvider(identityProvider)
}

err := client.with(WithCredentials(provider))
// nolint: staticcheck
if err != nil {
// TODO: log that default credential was not loaded.
Expand Down

0 comments on commit 5268dc9

Please sign in to comment.