2 Star 2 Fork 1

cockroachdb/cockroach

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
license_check.go 2.04 KB
一键复制 编辑 原始数据 按行查看 历史
Matt Tracy 提交于 2017-08-31 17:48 . ui/server: Analytics Identify Event
// Copyright 2017 The Cockroach Authors.
//
// Licensed as a CockroachDB Enterprise file under the Cockroach Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/cockroachdb/cockroach/blob/master/LICENSE
package utilccl
import (
"time"
"github.com/cockroachdb/cockroach/pkg/ccl/utilccl/licenseccl"
"github.com/cockroachdb/cockroach/pkg/server"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
)
var enterpriseLicense = settings.RegisterValidatedStringSetting(
"enterprise.license",
"the encoded cluster license",
"",
func(s string) error {
_, err := licenseccl.Decode(s)
return err
},
)
func init() {
enterpriseLicense.Hide()
}
var testingEnterpriseEnabled = false
// TestingEnableEnterprise allows overriding the license check in tests.
func TestingEnableEnterprise() func() {
before := testingEnterpriseEnabled
testingEnterpriseEnabled = true
return func() {
testingEnterpriseEnabled = before
}
}
// CheckEnterpriseEnabled returns a non-nil error if the requested enterprise
// feature is not enabled, including information or a link explaining how to
// enable it.
func CheckEnterpriseEnabled(st *cluster.Settings, cluster uuid.UUID, org, feature string) error {
if testingEnterpriseEnabled {
return nil
}
return checkEnterpriseEnabledAt(st, timeutil.Now(), cluster, org, feature)
}
func init() {
server.LicenseCheckFn = CheckEnterpriseEnabled
}
func checkEnterpriseEnabledAt(
st *cluster.Settings, at time.Time, cluster uuid.UUID, org, feature string,
) error {
var lic *licenseccl.License
// FIXME(tschottdorf): see whether it makes sense to cache the decoded
// license.
if str := enterpriseLicense.Get(&st.SV); str != "" {
var err error
if lic, err = licenseccl.Decode(str); err != nil {
return err
}
}
return lic.Check(at, cluster, org, feature)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_cockroachdb/cockroach.git
git@gitee.com:mirrors_cockroachdb/cockroach.git
mirrors_cockroachdb
cockroach
cockroach
v1.1.8

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385