diff --git a/grctl/cmd/license.go b/grctl/cmd/license.go index 55c3566df..e28460ddd 100644 --- a/grctl/cmd/license.go +++ b/grctl/cmd/license.go @@ -49,10 +49,37 @@ func NewCmdLicense() cli.Command { 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 diff --git a/release.sh b/release.sh index 02dc1d463..2cac07bc0 100755 --- a/release.sh +++ b/release.sh @@ -86,7 +86,11 @@ build::binary() { elif [ "$1" = "gateway" ];then docker run --rm -e GOOS=${GOOS} -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GATEWAY_GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${OUTPATH} ./cmd/$1 else - docker run --rm -e GOOS=${GOOS} -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -tags license -o ${OUTPATH} ./cmd/$1 + if [ "${ENTERPRISE}" = "true" ];then + docker run --rm -e GOOS=${GOOS} -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -tags license -o ${OUTPATH} ./cmd/$1 + else + docker run --rm -e GOOS=${GOOS} -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${OUTPATH} ./cmd/$1 + fi fi if [ "$GOOS" = "windows" ];then mv $OUTPATH ${OUTPATH}.exe diff --git a/util/license/license.go b/util/license/license.go index 35b087a5e..7f13cad01 100644 --- a/util/license/license.go +++ b/util/license/license.go @@ -32,6 +32,7 @@ import ( // LicInfo license information type LicInfo struct { + LicKey string `json:"license_key"` Code string `json:"code"` Company string `json:"company"` Node int64 `json:"node"` @@ -124,3 +125,19 @@ func GetLicInfo(licPath, licSoPath string) (*LicInfo, error) { } return &licInfo, nil } + +// GenLicKey - +func GenLicKey(licSoPath string) (string, error) { + p, err := plugin.Open(licSoPath) + if err != nil { + logrus.Errorf("license.so path: %s; error opening license.so: %v", licSoPath, err) + return "", fmt.Errorf("license.so path: %s; error opening license.so: %v", licSoPath, err) + } + + f, err := p.Lookup("GenLicKey") + if err != nil { + logrus.Errorf("method 'GenLicKey'; error looking up func: %v", err) + return "", fmt.Errorf("method 'GenLicKey'; error looking up func: %v", err) + } + return f.(func() (string, error))() +} diff --git a/util/license/no_license.go b/util/license/no_license.go index a2c02d161..a95cf38b6 100644 --- a/util/license/no_license.go +++ b/util/license/no_license.go @@ -48,3 +48,8 @@ func VerifyNodes(licPath, licSoPath string, nodeNums int) bool { func GetLicInfo(licPath, licSoPath string) (*LicInfo, error) { return nil, nil } + +// GenLicKey - +func GenLicKey(licSoPath string) (string, error) { + return "", nil +}