Created
September 16, 2019 19:12
-
-
Save jinpyojeon/dfe51f3711e7e5147145f4de669a6a60 to your computer and use it in GitHub Desktop.
Parse STS for AWS
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 ( | |
"bufio" | |
"encoding/json" | |
"fmt" | |
"os" | |
) | |
type Credentials struct { | |
Credentials struct { | |
AccessKeyId string | |
SecretAccessKey string | |
SessionToken string | |
Expiration string | |
} | |
AssumedRoleUser struct { | |
AssumedRoleId string | |
Arn string | |
} | |
} | |
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
var input string | |
for scanner.Scan() { | |
input += scanner.Text() | |
} | |
var c Credentials | |
err := json.Unmarshal([]byte(input), &c) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Print(c) | |
fmt.Printf("export AWS_ACCESS_KEY=%s; export AWS_SECRET_ACCESS_KEY=%s; export AWS_SESSION_TOKEN=%s", | |
c.Credentials.AccessKeyId, c.Credentials.SecretAccessKey, | |
c.Credentials.SessionToken) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment