forked from goodrain/rainbond
/
license.go
86 lines (80 loc) · 2.09 KB
/
license.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
77
78
79
80
81
82
83
84
85
86
package cmd
import (
"fmt"
licutil "github.com/goodrain/rainbond/util/license"
"github.com/gosuri/uitable"
"github.com/urfave/cli"
)
//NewCmdLicense -
func NewCmdLicense() cli.Command {
c := cli.Command{
Name: "license",
Usage: "rainbond license manage cmd",
Subcommands: []cli.Command{
{
Name: "show",
Usage: "show license information",
Flags: []cli.Flag{
cli.StringFlag{
Name: "lic-path, lp",
Usage: "license file path",
Value: "/opt/rainbond/etc/license/license.yb",
},
cli.StringFlag{
Name: "lic-so-path, lsp",
Usage: "license.so file path",
Value: "/opt/rainbond/etc/license/license.so",
},
},
Action: func(c *cli.Context) error {
Common(c)
licPath := c.String("lic-path")
licSoPath := c.String("lic-so-path")
licInfo, err := licutil.GetLicInfo(licPath, licSoPath)
if err != nil {
showError(err.Error())
}
if licInfo == nil {
fmt.Println("non-enterprise version, no license information")
return nil
}
table := uitable.New()
table.AddRow("授权公司名称:", licInfo.Company)
table.AddRow("授权公司代码:", licInfo.Code)
table.AddRow("授权单数据中心节点数:", licInfo.Node)
table.AddRow("授权开始时间:", licInfo.StartTime)
table.AddRow("授权到期时间:", licInfo.EndTime)
table.AddRow("授权key:", licInfo.LicKey)
fmt.Println(table)
return nil
},
},
{
Name: "genkey",
Usage: "generate a license key for the machine",
Flags: []cli.Flag{
cli.StringFlag{
Name: "lic-so-path, lsp",
Usage: "license.so file path",
Value: "/opt/rainbond/etc/license/license.so",
},
},
Action: func(c *cli.Context) error {
Common(c)
licSoPath := c.String("lic-so-path")
licKey, err := licutil.GenLicKey(licSoPath)
if err != nil {
showError(err.Error())
}
if licKey == "" {
fmt.Println("non-enterprise version, no license key")
return nil
}
fmt.Println(licKey)
return nil
},
},
},
}
return c
}