/
kmsid.go
32 lines (28 loc) · 977 Bytes
/
kmsid.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
package awskms
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/sts"
myAWS "github.com/dcoker/biscuit/internal/aws"
)
// KmsGetCallerIdentity prints AWS client configuration info.
type KmsGetCallerIdentity struct{}
// Run prints the results of STS GetCallerIdentity.
func (w *KmsGetCallerIdentity) Run(ctx context.Context) error {
cfg := myAWS.MustNewConfig(ctx)
credentials, err := cfg.Credentials.Retrieve(ctx)
if err != nil {
return err
}
fmt.Printf("# Credentials\n")
fmt.Printf("AWS Credentials Provider: %s\n", credentials.Source)
fmt.Printf("AWS Access Key: %s\n", credentials.AccessKeyID)
fmt.Printf("# STS GetCallerIdentity\n")
stsClient := sts.NewFromConfig(cfg)
getCallerIdentityOutput, err := stsClient.GetCallerIdentity(ctx, nil)
if err != nil {
return err
}
fmt.Printf("\tAccount: %s\n\tARN: %s\n\tUserID: %s\n", *getCallerIdentityOutput.Account, *getCallerIdentityOutput.Arn, *getCallerIdentityOutput.UserId)
return nil
}