Last active
August 14, 2020 18:02
-
-
Save m87carlson/5695b9e13620274f3fcfd631c0860dce to your computer and use it in GitHub Desktop.
small go program to replace aws credentials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"os" | |
"regexp" | |
) | |
func main() { | |
awsId := regexp.MustCompile("(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}") | |
awsSecret := regexp.MustCompile("[A-Za-z0-9/\\+=]{40}") | |
awsAccountId := regexp.MustCompile("[0-9]{4}\\-?[0-9]{4}\\-?[0-9]{4}") | |
privateKey := regexp.MustCompile(`(?s)-{3,}([\s\S]*?)-{3,}\n([\s\S\n].*)\n-{3,}([\s\S]*?)-{3,}`) | |
in,_ := ioutil.ReadAll(os.Stdin) | |
text := string(in) | |
text = awsId.ReplaceAllString(text, "< aws id >") | |
text = awsSecret.ReplaceAllString(text, "< aws secret >") | |
text = awsAccountId.ReplaceAllString(text, "< aws account id >") | |
text = privateKey.ReplaceAllString(text, "-----\n< private key >\n-----") | |
fmt.Println(text) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment