-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
74 lines (68 loc) · 1.6 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
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate go run pkg/codegen/main.go
package main
import (
"fmt"
"log"
"os"
"github.com/cnrancher/rancher-upgrade-authtool/tool"
"github.com/urfave/cli"
)
var (
Version = "dev"
GitCommit = "HEAD"
)
func getVersion() string {
return fmt.Sprintf("%s (%s)", Version, GitCommit)
}
func main() {
var config tool.Config
app := cli.NewApp()
app.Name = "Sync AD/LDAP auth config for rancher users"
app.Version = getVersion()
app.Commands = []cli.Command{
{
Name: "upgrade",
Aliases: []string{"u"},
Usage: "upgrade rancher user to new version",
Action: func(c *cli.Context) error {
if config.AuthType == "0" {
config.AuthConfigType = tool.ActiveDirectoryAuth
} else if config.AuthType == "1" {
config.AuthConfigType = tool.OpenLDAPAuth
}
return tool.Upgrade(&config)
},
},
}
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Enable dry run",
Required: false,
Destination: &config.IsDryRun,
},
cli.StringFlag{
Name: "kubeconfig",
Usage: "kube config for accessing local k8s cluster of rancher",
Destination: &config.KubeConfig,
EnvVar: "KUBECONFIG",
},
cli.StringFlag{
Name: "auth-type",
Usage: "auth type: 0 - AD auth, 1 - openldap auth",
Required: true,
Destination: &config.AuthType,
},
cli.StringFlag{
Name: "log-file",
Usage: "log file path for upgrade",
Required: false,
Destination: &config.LogFilePath,
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}