/
main.go
76 lines (69 loc) · 3.33 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 (
"fmt"
golog "log"
"os"
"github.com/AliyunContainerService/ack-ram-tool/pkg/ctl"
"github.com/AliyunContainerService/ack-ram-tool/pkg/ctl/credentialplugin"
"github.com/AliyunContainerService/ack-ram-tool/pkg/ctl/exportcredentials"
"github.com/AliyunContainerService/ack-ram-tool/pkg/ctl/rbac"
"github.com/AliyunContainerService/ack-ram-tool/pkg/ctl/rrsa"
"github.com/AliyunContainerService/ack-ram-tool/pkg/ctl/version"
"github.com/AliyunContainerService/ack-ram-tool/pkg/log"
vs "github.com/AliyunContainerService/ack-ram-tool/pkg/version"
"github.com/spf13/cobra"
)
var (
rootCmd = &cobra.Command{
Use: "ack-ram-tool",
Short: "A command line utility for using RAM in Alibaba Cloud Container Service For Kubernetes (ACK).",
Long: `A command line utility for using RAM in Alibaba Cloud Container Service For Kubernetes (ACK).
More info: https://github.com/AliyunContainerService/ack-ram-tool`,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
ctl.GlobalOption.UpdateValues()
err := log.SetupLogger(ctl.GlobalOption.GetLogLevel(), log.DefaultLogLevelKey, log.DefaultLogLevelEncoder)
if err != nil {
golog.Println(err)
os.Exit(1)
}
log.Logger.Debugf("Version: %s GitCommit: %s", vs.Version, vs.GitCommit)
log.Logger.Debugf("argv: %v", os.Args)
},
}
)
func init() {
rrsa.SetupRRSACmd(rootCmd)
credentialplugin.SetupCredentialPluginCmd(rootCmd)
version.SetupVersionCmd(rootCmd)
rbac.SetupCmd(rootCmd)
exportcredentials.SetupCmd(rootCmd)
rootCmd.PersistentFlags().StringVar(&ctl.GlobalOption.Region, "region-id",
"", "The region to use"+
" (env: \"ACK_RAM_TOOL_REGION_ID\")")
rootCmd.PersistentFlags().BoolVarP(&ctl.GlobalOption.AssumeYes, "assume-yes", "y", false,
"Automatic yes to prompts; assume \"yes\" as answer to all prompts and run non-interactively"+
" (env: \"ACK_RAM_TOOL_ASSUME_YES\")")
rootCmd.PersistentFlags().StringVar(&ctl.GlobalOption.CredentialFilePath, "profile-file", "",
"Path to credential file (default: ~/.aliyun/config.json or ~/.alibabacloud/credentials)"+
" (env: \"ACK_RAM_TOOL_PROFILE_FILE\")")
rootCmd.PersistentFlags().StringVar(&ctl.GlobalOption.ProfileName, "profile-name", "",
"using this named profile when parse credentials from config.json of aliyun cli"+
" (env: \"ACK_RAM_TOOL_PROFIL_ENAME\")")
rootCmd.PersistentFlags().BoolVar(&ctl.GlobalOption.IgnoreEnv,
"ignore-env-credentials", false, "don't try to parse credentials from environment variables"+
" (env: \"ACK_RAM_TOOL_IGNORE_ENV_CREDENTIALS\")")
rootCmd.PersistentFlags().BoolVar(&ctl.GlobalOption.IgnoreAliyuncliConfig,
"ignore-aliyun-cli-credentials", false, "don't try to parse credentials from config.json of aliyun cli"+
" (env: \"ACK_RAM_TOOL_IGNORE_ALIYUN_CLI_CREDENTIALS\")")
rootCmd.PersistentFlags().StringVar(&ctl.GlobalOption.LogLevel, "log-level", "",
fmt.Sprintf("log level: info, debug, error (default \"%s\")", ctl.DefaultLogLevel)+
" (env: \"ACK_RAM_TOOL_LOG_LEVEL\")")
//rootCmd.PersistentFlags().BoolVarP(&ctl.GlobalOption.InsecureSkipTLSVerify, "insecure-skip-tls-verify", "", false, "Skips the validity check for the server's certificate")
rootCmd.PersistentFlags().BoolVarP(&ctl.GlobalOption.Verbose, "verbose", "v", false, "Make the operation more talkative")
}
func main() {
if err := rootCmd.Execute(); err != nil {
golog.Println(err)
os.Exit(1)
}
}