-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (55 loc) · 1.75 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
package main
import (
"flag"
"fmt"
"os"
"github.com/fatih/color"
"github.com/joanbono/akt/modules/rotate"
"github.com/joanbono/akt/modules/writer"
)
// Defining colors
var yellow = color.New(color.FgYellow)
var red = color.New(color.FgRed)
var cyan = color.New(color.FgCyan)
var bold = color.New(color.FgHiWhite, color.Bold)
var (
accessKey, secretKey, username string
profileFlag, userFlag string
rotateFlag bool
saveFlag bool
versionFlag bool
version string
)
func init() {
flag.StringVar(&profileFlag, "profile", "default", "Profile to use")
flag.StringVar(&userFlag, "user", "", "User to generate keys")
flag.BoolVar(&rotateFlag, "rotate", false, "Rotate keys")
flag.BoolVar(&saveFlag, "save", false, "Save new keys to .aws/credentials")
flag.BoolVar(&versionFlag, "version", false, "Show version")
flag.Parse()
}
func main() {
if versionFlag {
fmt.Printf("\n\t☁️ 🔑 AKT %v\n\n", bold.Sprintf(version))
return
}
if !rotateFlag {
fmt.Printf("\n ☁️ 🔑 AKT %v\n", bold.Sprintf(version))
fmt.Printf("%v Insufficient options!\n", yellow.Sprintf("[!]"))
fmt.Printf("%v Try with %v\n\n", cyan.Sprintf("[i]"), bold.Sprintf("akt -h"))
return
} else {
//Check that .aws/credentials file is accessible before rotating the keys
//This will prevent rotated keys not being written anywhere
if _, err := os.Stat(writer.Reader()); err != nil {
fmt.Printf("%v .aws/credentials file not found\n", red.Sprintf("[-]"))
os.Exit(2)
}
accessKey, secretKey, username = rotate.Rotate(profileFlag, userFlag)
if saveFlag {
writer.Profiler(profileFlag, accessKey, secretKey)
} else {
writer.Printer(profileFlag, accessKey, secretKey)
}
}
}