-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (46 loc) · 1.24 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
package main
import (
"context"
"fmt"
"log"
"log/slog"
"github.com/alecthomas/kong"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/kms"
)
const (
keySuffixNext = "-next"
keySuffixCurrent = "-current"
keySuffixPrevious = "-previous"
)
type cli struct {
KeyAliasPrefix string `required:"" help:"Alias prefix to use when operating on keys; Actual keys will get aliases with '-next', '-current' and '-previous' suffixes."`
Export CmdExport `cmd:"" help:"Export KMS keys as JWKS"`
Rotate CmdRotate `cmd:"" help:"Rotate KMS keys; will create new keys if necessary"`
LogLevel slog.Level `help:"Log level" default:"info"`
}
func main() {
var cli cli
ctx := kong.Parse(&cli)
slog.SetLogLoggerLevel(cli.LogLevel)
cfg, err := config.LoadDefaultConfig(context.Background())
if err != nil {
log.Fatalf("unable to load AWS config, %v", err)
}
ktx := &Context{
KeyAliasPrefix: cli.KeyAliasPrefix,
kms: kms.NewFromConfig(cfg),
}
ctx.FatalIfErrorf(ctx.Run(ktx))
}
type Context struct {
KeyAliasPrefix string
kms *kms.Client
}
func (c Context) keyAlias(suffix string) *string {
ka := fmt.Sprintf("alias/%s%s", c.KeyAliasPrefix, suffix)
return &ka
}
func ptr[T any](i T) *T {
return &i
}