Merge pull request #457 from GLYASAI/license

[REV] use 'ldflags' instead of 'tag'
This commit is contained in:
barnettZQG 2019-10-08 04:53:04 -05:00 committed by GitHub
commit 1845221706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 61 deletions

View File

@ -28,6 +28,10 @@ buildTime=$(date +%F-%H)
git_commit=$(git log -n 1 --pretty --format=%h)
release_desc=${VERSION}-${git_commit}-${buildTime}
ENTERPRISE=false
if [ "${ENTERPRISE}" = "true" ];then
ENTERPRISE=true
fi
build::node() {
local releasedir=./.release
@ -38,7 +42,7 @@ build::node() {
case $1 in
node)
echo "build node"
docker run --rm -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 $releasedir/dist/usr/local/bin/node ./cmd/node
docker run --rm -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}" --ldflags "-w -s -X github.com/goodrain/rainbond/util/license.enterprise=${ENTERPRISE}" -o $releasedir/dist/usr/local/bin/node ./cmd/node
;;
grctl)
echo "build grctl"
@ -50,7 +54,7 @@ build::node() {
;;
*)
echo "build node"
docker run --rm -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 $releasedir/dist/usr/local/bin/node ./cmd/node
docker run --rm -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}" --ldflags "-w -s -X github.com/goodrain/rainbond/util/license.enterprise=${ENTERPRISE}" -o $releasedir/dist/usr/local/bin/node ./cmd/node
echo "build grctl"
docker run --rm -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 $releasedir/dist/usr/local/bin/grctl ./cmd/grctl
echo "build certutil"
@ -87,7 +91,7 @@ build::binary() {
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
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
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}" --ldflags "-w -s -X github.com/goodrain/rainbond/util/license.enterprise=${ENTERPRISE}" -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

View File

@ -16,8 +16,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//+build license
package license
import (
@ -26,10 +24,13 @@ import (
"io/ioutil"
"os"
"plugin"
"strconv"
"github.com/Sirupsen/logrus"
)
var enterprise string
// LicInfo license information
type LicInfo struct {
LicKey string `json:"license_key"`
@ -45,6 +46,14 @@ type LicInfo struct {
ModuleList []string `json:"module_list"`
}
func isEnterprise() bool {
res, err := strconv.ParseBool(enterprise)
if err != nil {
logrus.Warningf("enterprise: %s; error parsing 'string' to 'bool': %v", enterprise, err)
}
return res
}
func readFromFile(lfile string) (string, error) {
_, err := os.Stat(lfile)
if err != nil {
@ -61,6 +70,9 @@ func readFromFile(lfile string) (string, error) {
// VerifyTime verifies the time in the license.
func VerifyTime(licPath, licSoPath string) bool {
if !isEnterprise() {
return true
}
lic, err := readFromFile(licPath)
if err != nil {
logrus.Errorf("failed to read license from file: %v", err)
@ -81,6 +93,9 @@ func VerifyTime(licPath, licSoPath string) bool {
// VerifyNodes verifies the number of the nodes in the license.
func VerifyNodes(licPath, licSoPath string, nodeNums int) bool {
if !isEnterprise() {
return true
}
lic, err := readFromFile(licPath)
if err != nil {
logrus.Errorf("failed to read license from file: %v", err)
@ -101,6 +116,9 @@ func VerifyNodes(licPath, licSoPath string, nodeNums int) bool {
// GetLicInfo -
func GetLicInfo(licPath, licSoPath string) (*LicInfo, error) {
if !isEnterprise() {
return nil, nil
}
lic, err := readFromFile(licPath)
if err != nil {
logrus.Errorf("failed to read license from file: %v", err)
@ -128,6 +146,9 @@ func GetLicInfo(licPath, licSoPath string) (*LicInfo, error) {
// GenLicKey -
func GenLicKey(licSoPath string) (string, error) {
if !isEnterprise() {
return "", nil
}
p, err := plugin.Open(licSoPath)
if err != nil {
logrus.Errorf("license.so path: %s; error opening license.so: %v", licSoPath, err)

View File

@ -1,56 +0,0 @@
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//+build !license
package license
// LicInfo license information
type LicInfo struct {
LicKey string `json:"license_key"`
Code string `json:"code"`
Company string `json:"company"`
Node int64 `json:"node"`
CPU int64 `json:"cpu"`
Memory int64 `json:"memory"`
Tenant int64 `json:"tenant"`
EndTime string `json:"end_time"`
StartTime string `json:"start_time"`
DataCenter int64 `json:"data_center"`
ModuleList []string `json:"module_list"`
}
// VerifyTime verifies the time in the license.
func VerifyTime(licPath, licSoPath string) bool {
return true
}
// VerifyNodes verifies the number of the nodes in the license.
func VerifyNodes(licPath, licSoPath string, nodeNums int) bool {
return true
}
// GetLicInfo -
func GetLicInfo(licPath, licSoPath string) (*LicInfo, error) {
return nil, nil
}
// GenLicKey -
func GenLicKey(licSoPath string) (string, error) {
return "", nil
}