-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (55 loc) · 1.19 KB
/
main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Encoding: UTF-8
//
// AWS ECR Proxy
//
// Copyright © 2023 Brian Dwyer - Intelligent Digital Services
//
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"time"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ecr"
"github.com/aws/aws-sdk-go-v2/service/sts"
)
var accountFlag bool
func init() {
flag.BoolVar(&accountFlag, "account", false, "Display AWS Account")
}
func main() {
flag.Parse()
if versionFlag {
showVersion()
os.Exit(0)
}
// AWS Session
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
defer cancel()
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
log.Fatal(err)
}
// Emit AWS Account ID
if accountFlag {
result, err := sts.NewFromConfig(cfg).GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
if err != nil {
log.Fatal(err)
}
if _, err = fmt.Println(*result.Account); err != nil {
log.Fatal(err)
}
return
}
// ECR Client
result, err := ecr.NewFromConfig(cfg).GetAuthorizationToken(ctx, &ecr.GetAuthorizationTokenInput{})
if err != nil {
log.Fatal(err)
}
if _, err = fmt.Print(*result.AuthorizationData[0].AuthorizationToken); err != nil {
log.Fatal(err)
}
}