Skip to content

Commit

Permalink
support aws root console creds
Browse files Browse the repository at this point in the history
  • Loading branch information
mhristof committed Sep 29, 2020
1 parent c0697c5 commit a4e5677
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
26 changes: 26 additions & 0 deletions awscreds/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ func convert(lines []byte) string {
ret = fmt.Sprintf("%s AWS_SESSION_TOKEN='%s'", ret, sessionToken)
}

if ret == "export" {
id := false
key := false
for _, line := range strings.Split(string(lines), "\n") {
if id {
ret = fmt.Sprintf("%s AWS_ACCESS_KEY_ID='%s'", ret, line)
}

if key {
ret = fmt.Sprintf("%s AWS_SECRET_ACCESS_KEY='%s'", ret, line)
}

if line == "Access Key ID:" {
id = true
} else {
id = false
}

if line == "Secret Access Key:" {
key = true
} else {
key = false
}
}
}

return ret
}

Expand Down
10 changes: 10 additions & 0 deletions awscreds/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ func TestConvert(t *testing.T) {
)),
out: "export AWS_SECRET_ACCESS_KEY='secret' AWS_ACCESS_KEY_ID='access' AWS_SESSION_TOKEN='token'",
},
{
name: "root creds from the console",
in: []byte(heredoc.Doc(`
Access Key ID:
access
Secret Access Key:
secret
`)),
out: "export AWS_ACCESS_KEY_ID='access' AWS_SECRET_ACCESS_KEY='secret'",
},
}

for _, tt := range cases {
Expand Down

0 comments on commit a4e5677

Please sign in to comment.