Skip to content

Commit

Permalink
Use source_profile for cached session
Browse files Browse the repository at this point in the history
  • Loading branch information
lox committed Oct 19, 2015
1 parent 6a892b9 commit 8d237c0
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ func (p *VaultProvider) Retrieve() (credentials.Value, error) {
return credentials.Value{}, err
}

log.Printf("Writing session for %s to keyring", p.profile)
source := p.profiles.sourceProfile(p.profile)

log.Printf("Writing session for %s to keyring", source)
p.keyring.Set(keyring.Item{
Key: sessionKey(p.profile),
Label: "aws-vault session for " + p.profile,
Key: sessionKey(source),
Label: "aws-vault session for " + source,
Data: bytes,
TrustSelf: true,
})
Expand Down Expand Up @@ -154,15 +156,11 @@ func sessionKey(profile string) string {
}

func (p *VaultProvider) getCachedSession() (session sts.Credentials, err error) {
source := p.profiles.sourceProfile(p.profile)

item, err := p.keyring.Get(sessionKey(source))
item, err := p.keyring.Get(sessionKey(p.profiles.sourceProfile(p.profile)))
if err != nil {
return session, err
}

log.Printf("Found cached session for profile %s", source)

if err = json.Unmarshal(item.Data, &session); err != nil {
return session, err
}
Expand Down Expand Up @@ -223,7 +221,7 @@ func (p *VaultProvider) getSessionToken(creds *credentials.Value) (sts.Credentia
})
}

log.Printf("Getting new session token for profile %s", p.profile)
log.Printf("Getting new session token for profile %s", p.profiles.sourceProfile(p.profile))
resp, err := client.GetSessionToken(params)
if err != nil {
return sts.Credentials{}, err
Expand Down Expand Up @@ -273,6 +271,7 @@ func (p *KeyringProvider) Retrieve() (val credentials.Value, err error) {
log.Printf("Looking up keyring for %s", p.Profile)
item, err := p.Keyring.Get(p.Profile)
if err != nil {
log.Println("Error from keyring", err)
return val, err
}

Expand Down

0 comments on commit 8d237c0

Please sign in to comment.