From 6c82039e591b117cc95a6e6084d998abd2f335b1 Mon Sep 17 00:00:00 2001 From: joanbono Date: Thu, 11 Mar 2021 18:24:03 +0100 Subject: [PATCH] v1,1.0 Added a check in main.go where it checks if the .aws/credentials file exists before rotating the keys, to ensure the key is rotated and then written to the file --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 7ea3e31..71b13d9 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "os" "github.com/fatih/color" "github.com/joanbono/akt/modules/rotate" @@ -45,6 +46,12 @@ func main() { 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) @@ -52,5 +59,4 @@ func main() { writer.Printer(profileFlag, accessKey, secretKey) } } - }