forked from remind101/assume-role
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (52 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
log "github.com/sirupsen/logrus"
)
var (
debug *bool
// verbose *bool
)
func init() {
debug = flag.Bool("debug", false, "Show debug logs")
// verbose = flag.Bool("verbose", false, "Increased verbosity")
flag.Usage = usage
}
func usage() {
fmt.Fprintf(os.Stderr, "Usage: %s [<args...>] <role> [<command> <command args...>]\n", os.Args[0])
flag.PrintDefaults()
}
func main() {
flag.Parse()
if *debug {
log.SetLevel(log.DebugLevel)
}
log.Debug("Starting...")
argv := flag.Args()
if len(argv) < 1 {
if *reset {
unsetCredentials()
return
}
flag.Usage()
os.Exit(1)
}
log.WithField("duration", *duration).Debug("Setting STS Token Duration")
stscreds.DefaultDuration = *duration
role := argv[0]
args := argv[1:]
if *reset {
resetEnvVars()
}
creds, err := loadCredentials(role)
must(err)
log.WithField("credentials", creds).Debug("Received role credentials")
if len(args) == 0 {
printCredentials(role, creds)
return
}
must(execWithCredentials(role, args, creds))
}