Skip to content

Commit

Permalink
add support for programatically setting custom aws credentials (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylersouthwick committed Jul 29, 2020
1 parent 6cd9695 commit cedff5e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/awsutil/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Credentials struct {
SecretAccessKey string
SessionToken string

Credentials *credentials.Credentials

CustomEndpoints config.CustomEndpoints
session *session.Session
}
Expand All @@ -41,6 +43,10 @@ func (c *Credentials) HasProfile() bool {
return strings.TrimSpace(c.Profile) != ""
}

func (c *Credentials) HasAwsCredentials() bool {
return c.Credentials != nil
}

func (c *Credentials) HasKeys() bool {
return strings.TrimSpace(c.AccessKeyID) != "" ||
strings.TrimSpace(c.SecretAccessKey) != "" ||
Expand All @@ -65,6 +71,12 @@ func (c *Credentials) rootSession() (*session.Session, error) {
log.Debugf("creating new root session in %s", region)

switch {
case c.HasAwsCredentials():
opts = session.Options{
Config: aws.Config{
Credentials: c.Credentials,
},
}
case c.HasProfile() && c.HasKeys():
return nil, fmt.Errorf("You have to specify a profile or credentials for at least one region.")

Expand Down

0 comments on commit cedff5e

Please sign in to comment.