-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (58 loc) · 2.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"os"
"github.com/alecthomas/kong"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/wolfeidau/cognito-cli/internal/commands"
"github.com/wolfeidau/cognito-cli/pkg/cognito"
)
var (
version = "unknown"
)
type regionFlag string
func (r regionFlag) AfterApply(cfg *aws.Config) error {
cfg.Region = aws.String(string(r))
return nil
}
type profileFlag string
func (p profileFlag) AfterApply(cfg *aws.Config) error {
cfg.Credentials = credentials.NewSharedCredentials("", string(p))
return nil
}
var flags struct {
Debug bool `help:"Enable debug mode."`
Region regionFlag `help:"AWS Region." env:"AWS_REGION" default:"us-east-1" short:"r"`
Profile profileFlag `help:"AWS CLI profile." env:"AWS_PROFILE" short:"p"`
DisableLocalTime bool `help:"Disable localisation of times output."`
Version kong.VersionFlag
Ls commands.LsCmd `cmd:"ls" help:"List pools."`
ListAttributes commands.ListAttributesCmd `cmd:"list-attributes" help:"List the schema attributes of the user pool."`
Find commands.FindCmd `cmd:"find" help:"Find users."`
Export commands.ExportCmd `cmd:"export" help:"Export users, filter and write the results in CSV format."`
Logout commands.LogoutCmd `cmd:"logout" help:"Find users and trigger a logout."`
}
func main() {
awscfg := &aws.Config{}
cli := kong.Parse(&flags,
kong.Bind(awscfg),
kong.Vars{"version": version}, // bind a var for version
kong.Name("cognito-cli"),
kong.Description("A cognito cli."),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: false,
Summary: true,
}))
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if flags.Debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
log.Debug().Str("region", string(flags.Region)).Str("profile", string(flags.Profile)).Msg("aws config")
cognitoSvc := cognito.NewService(awscfg)
err := cli.Run(&commands.CLIContext{Debug: flags.Debug, DisableLocalTime: flags.DisableLocalTime, Cognito: cognitoSvc, Writer: os.Stdout})
cli.FatalIfErrorf(err)
}