finclip-app-manager/infrastructure/client/httpcall/license.go

83 lines
3.1 KiB
Go
Raw Normal View History

2023-10-31 14:07:26 +08:00
package httpcall
import (
"context"
"errors"
)
type CommonConfigData struct {
Error string `json:"error"`
Errcode string `json:"errcode"`
Data struct {
OrganName string `json:"organName"`
} `json:"data"`
}
var commonConfig CommonConfigData
func (c *Client) getCommonConfig(ctx context.Context) error {
var h = map[string]string{
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"url-call": "internal",
}
url := "http://mop-private-init-server:8080/api/v1/mop/mop-private-init-server/common/config"
rsp, err := c.Request(ctx).SetHeaders(h).SetResult(&commonConfig).Get(url)
if err != nil || rsp.StatusCode() != 200 {
return errors.New("mop-private-init-server err")
}
return nil
}
type LicenseData struct {
OrganName string `json:"organName"` //企业名称
AppCount int `json:"appCount"` //可创建的小程序数量上限
CooAppCount int `json:"cooAppCount"` //应用的数量
BundleIdCount int `json:"bundleIdCount"` //bundleId数量
ReviewOrganCount int `json:"reviewOrganCount"` //可认证通过的企业数量
ExpireTime int64 `json:"expireTime"` //服务有效期
CreateOperAdminByInitServer bool `json:"createOperAdminByInitServer"` //init服务是否创建运营端管理账号
OpenAPM bool `json:"openAPM"` //是否打开APM上报
OpenAppSearch bool `json:"openAppSearch"`
OpenApiManage bool `json:"openApiManage"`
IsWindows bool `json:"isWindows"`
IsMac bool `json:"isMac"`
IsLinux bool `json:"isLinux"`
IsIOS bool `json:"isIOS"`
IsAndroid bool `json:"isAndroid"`
IsConfiguration bool `json:"isConfiguration"`
IsApiCover bool `json:"isApiCover"`
Clients []string `json:"clients"`
DeviceNum int `json:"deviceNum"`
}
type GetLicenseRsp struct {
Data LicenseData `json:"data"`
Errcode string `json:"errcode"`
Errmsg string `json:"error"`
}
func (c *Client) GetLicense(ctx context.Context) (*LicenseData, error) {
if commonConfig.Data.OrganName == "" {
c.getCommonConfig(ctx)
}
var h = map[string]string{
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"url-call": "internal",
"Organ-Name": commonConfig.Data.OrganName, //私有化部署的时候,需要修改机构名称
}
url := "http://mop-license-checker:8080/api/v1/mop/mop-license-checker/license"
var licenseInfo GetLicenseRsp
rsp, err := c.Request(ctx).SetHeaders(h).SetResult(&licenseInfo).Get(url)
if err != nil {
return nil, err
}
if rsp.StatusCode() != 200 {
log.Errorf("get license info status code err:%+v,rsp:%+v", rsp.StatusCode(), rsp.String())
return nil, errors.New("status code error")
}
return &licenseInfo.Data, nil
}