Licensing: Send the app url to plugin (#64258)

This commit is contained in:
lean.dev 2023-03-08 14:44:04 -03:00 committed by GitHub
parent 4625958aea
commit 0b0140b761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 2 deletions

View File

@ -99,6 +99,8 @@ type Licensing interface {
Edition() string
Path() string
AppURL() string
}
// RoleRegistry handles the plugin RBAC roles and their assignments

View File

@ -9,12 +9,14 @@ import (
type Service struct {
licensePath string
appURL string
license licensing.Licensing
}
func ProvideLicensing(cfg *setting.Cfg, l licensing.Licensing) *Service {
return &Service{
licensePath: cfg.EnterpriseLicensePath,
appURL: cfg.AppURL,
license: l,
}
}
@ -36,3 +38,7 @@ func (l Service) Edition() string {
func (l Service) Path() string {
return l.licensePath
}
func (l Service) AppURL() string {
return l.appURL
}

View File

@ -322,6 +322,7 @@ type FakeLicensingService struct {
LicenseEdition string
TokenRaw string
LicensePath string
LicenseAppURL string
}
func NewFakeLicensingService() *FakeLicensingService {
@ -336,6 +337,10 @@ func (s *FakeLicensingService) Path() string {
return s.LicensePath
}
func (s *FakeLicensingService) AppURL() string {
return s.LicenseAppURL
}
func (s *FakeLicensingService) Environment() []string {
return []string{fmt.Sprintf("GF_ENTERPRISE_LICENSE_TEXT=%s", s.TokenRaw)}
}

View File

@ -57,6 +57,7 @@ func (i *Initializer) envVars(plugin *plugins.Plugin) []string {
hostEnv,
fmt.Sprintf("GF_EDITION=%s", i.license.Edition()),
fmt.Sprintf("GF_ENTERPRISE_LICENSE_PATH=%s", i.license.Path()),
fmt.Sprintf("GF_ENTERPRISE_APP_URL=%s", i.license.AppURL()),
)
hostEnv = append(hostEnv, i.license.Environment()...)
}

View File

@ -140,6 +140,7 @@ func TestInitializer_envVars(t *testing.T) {
LicenseEdition: "test",
TokenRaw: "token",
LicensePath: "/path/to/ent/license",
LicenseAppURL: "https://myorg.com/",
}
i := &Initializer{
@ -158,12 +159,13 @@ func TestInitializer_envVars(t *testing.T) {
}
envVars := i.envVars(p)
assert.Len(t, envVars, 5)
assert.Len(t, envVars, 6)
assert.Equal(t, "GF_PLUGIN_CUSTOM_ENV_VAR=customVal", envVars[0])
assert.Equal(t, "GF_VERSION=", envVars[1])
assert.Equal(t, "GF_EDITION=test", envVars[2])
assert.Equal(t, "GF_ENTERPRISE_LICENSE_PATH=/path/to/ent/license", envVars[3])
assert.Equal(t, "GF_ENTERPRISE_LICENSE_TEXT=token", envVars[4])
assert.Equal(t, "GF_ENTERPRISE_APP_URL=https://myorg.com/", envVars[4])
assert.Equal(t, "GF_ENTERPRISE_LICENSE_TEXT=token", envVars[5])
})
}