mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 03:19:30 +08:00
Plugins: Add tailored interface for plugins licensing needs (#61045)
* tailored licensing service * appease linter * fix * retrigger
This commit is contained in:
@ -10,19 +10,18 @@ import (
|
||||
"github.com/grafana/grafana-azure-sdk-go/azsettings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
)
|
||||
|
||||
type Initializer struct {
|
||||
cfg *config.Cfg
|
||||
license models.Licensing
|
||||
license plugins.Licensing
|
||||
backendProvider plugins.BackendFactoryProvider
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func New(cfg *config.Cfg, backendProvider plugins.BackendFactoryProvider, license models.Licensing) Initializer {
|
||||
func New(cfg *config.Cfg, backendProvider plugins.BackendFactoryProvider, license plugins.Licensing) Initializer {
|
||||
return Initializer{
|
||||
cfg: cfg,
|
||||
license: license,
|
||||
@ -57,14 +56,9 @@ func (i *Initializer) envVars(plugin *plugins.Plugin) []string {
|
||||
hostEnv = append(
|
||||
hostEnv,
|
||||
fmt.Sprintf("GF_EDITION=%s", i.license.Edition()),
|
||||
fmt.Sprintf("GF_ENTERPRISE_LICENSE_PATH=%s", i.cfg.EnterpriseLicensePath),
|
||||
fmt.Sprintf("GF_ENTERPRISE_LICENSE_PATH=%s", i.license.Path()),
|
||||
)
|
||||
|
||||
if envProvider, ok := i.license.(models.LicenseEnvironment); ok {
|
||||
for k, v := range envProvider.Environment() {
|
||||
hostEnv = append(hostEnv, fmt.Sprintf("%s=%s", k, v))
|
||||
}
|
||||
}
|
||||
hostEnv = append(hostEnv, i.license.Environment()...)
|
||||
}
|
||||
|
||||
hostEnv = append(hostEnv, i.awsEnvVars()...)
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
)
|
||||
|
||||
func TestInitializer_Initialize(t *testing.T) {
|
||||
@ -142,14 +143,14 @@ func TestInitializer_envVars(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
licensing := &testLicensingService{
|
||||
edition: "test",
|
||||
tokenRaw: "token",
|
||||
licensing := &fakes.FakeLicensingService{
|
||||
LicenseEdition: "test",
|
||||
TokenRaw: "token",
|
||||
LicensePath: "/path/to/ent/license",
|
||||
}
|
||||
|
||||
i := &Initializer{
|
||||
cfg: &config.Cfg{
|
||||
EnterpriseLicensePath: "/path/to/ent/license",
|
||||
PluginSettings: map[string]map[string]string{
|
||||
"test": {
|
||||
"custom_env_var": "customVal",
|
||||
@ -201,43 +202,6 @@ func Test_pluginSettings_ToEnv(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
type testLicensingService struct {
|
||||
edition string
|
||||
tokenRaw string
|
||||
}
|
||||
|
||||
func (t *testLicensingService) Expiry() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (t *testLicensingService) Edition() string {
|
||||
return t.edition
|
||||
}
|
||||
|
||||
func (t *testLicensingService) StateInfo() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (t *testLicensingService) ContentDeliveryPrefix() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (t *testLicensingService) LicenseURL(_ bool) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (t *testLicensingService) Environment() map[string]string {
|
||||
return map[string]string{"GF_ENTERPRISE_LICENSE_TEXT": t.tokenRaw}
|
||||
}
|
||||
|
||||
func (*testLicensingService) EnabledFeatures() map[string]bool {
|
||||
return map[string]bool{}
|
||||
}
|
||||
|
||||
func (*testLicensingService) FeatureEnabled(feature string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type fakeBackendProvider struct {
|
||||
plugins.BackendFactoryProvider
|
||||
|
||||
|
Reference in New Issue
Block a user