Skip to content

Commit

Permalink
Add debugging via DEBUG env
Browse files Browse the repository at this point in the history
  • Loading branch information
lox committed Sep 1, 2015
1 parent 43c5d6c commit c6f0182
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions aws-vault.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"io/ioutil"
"log"
"os"

Expand All @@ -13,6 +14,10 @@ var (
)

func main() {
if os.Getenv("DEBUG") != "1" {
log.SetOutput(ioutil.Discard)
}

ui := &cli.BasicUi{
Writer: os.Stdout,
Reader: os.Stdin,
Expand Down
7 changes: 7 additions & 0 deletions command/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ func (c *ListCommand) Run(args []string) int {
c.Ui.Error(err.Error())
return 4
}

for _, p := range profileNames {
c.Ui.Output(p)
}

if len(profileNames) == 0 {
c.Ui.Error("No profiles found")
return 1
}

return 0
}

Expand Down
4 changes: 2 additions & 2 deletions command/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func (c *StoreCommand) Run(args []string) int {
return 1
}

accessKeyId, err := c.Ui.Ask("Enter Access Key ID: ")
accessKeyId, err := c.Ui.Ask("Enter Access Key ID:")
if err != nil {
c.Ui.Error(err.Error())
return 2
}

secretKey, err := c.Ui.AskSecret("Enter Secret Access Key: ")
secretKey, err := c.Ui.AskSecret("Enter Secret Access Key:")
if err != nil {
c.Ui.Error(err.Error())
return 2
Expand Down
18 changes: 18 additions & 0 deletions vault/session.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vault

import (
"log"
"time"

"github.com/99designs/aws-vault/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -55,8 +56,15 @@ func (sp *SessionProvider) Session(conf SessionConfig) (SessionCredentials, erro
TokenCode: aws.String(token),
}

if token != "" {
log.Printf("assuming role %s with mfa %s", conf.Profile.RoleARN, serialNumber)
} else {
log.Printf("assuming role %s", conf.Profile.RoleARN)
}

resp, err := svc.AssumeRole(input)
if err != nil {
log.Printf("%#v", err)
return SessionCredentials{}, err
}
return SessionCredentials{resp.Credentials}, nil
Expand All @@ -69,6 +77,12 @@ func (sp *SessionProvider) Session(conf SessionConfig) (SessionCredentials, erro
TokenCode: aws.String(token),
}

if token != "" {
log.Printf("getting session token with mfa %s", serialNumber)
} else {
log.Printf("getting session token")
}

resp, err := svc.GetSessionToken(input)
if err != nil {
return SessionCredentials{}, err
Expand All @@ -92,6 +106,8 @@ func (ksp *KeyringSessionProvider) Session(conf SessionConfig) (SessionCredentia
}

if sessionCreds == nil || time.Now().After(*sessionCreds.Expiration) {
log.Println("fetching new session")

if ksp.CredsFunc != nil {
creds, err := ksp.CredsFunc()
if err != nil {
Expand All @@ -111,6 +127,8 @@ func (ksp *KeyringSessionProvider) Session(conf SessionConfig) (SessionCredentia
}

sessionCreds = &newCreds
} else {
log.Printf("using cached session (expires in %s)", sessionCreds.Expiration.Sub(time.Now()))
}

return *sessionCreds, nil
Expand Down

0 comments on commit c6f0182

Please sign in to comment.