From 0b0140b761f67c7424915131cd8693479c959cdb Mon Sep 17 00:00:00 2001 From: "lean.dev" <34773040+leandro-deveikis@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:44:04 -0300 Subject: [PATCH] Licensing: Send the app url to plugin (#64258) --- pkg/plugins/ifaces.go | 2 ++ pkg/plugins/licensing/licensing.go | 6 ++++++ pkg/plugins/manager/fakes/fakes.go | 5 +++++ pkg/plugins/manager/loader/initializer/initializer.go | 1 + pkg/plugins/manager/loader/initializer/initializer_test.go | 6 ++++-- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/plugins/ifaces.go b/pkg/plugins/ifaces.go index fac68172d8a..0f17544da52 100644 --- a/pkg/plugins/ifaces.go +++ b/pkg/plugins/ifaces.go @@ -99,6 +99,8 @@ type Licensing interface { Edition() string Path() string + + AppURL() string } // RoleRegistry handles the plugin RBAC roles and their assignments diff --git a/pkg/plugins/licensing/licensing.go b/pkg/plugins/licensing/licensing.go index 9a00e5828c2..e2d4c9c76f7 100644 --- a/pkg/plugins/licensing/licensing.go +++ b/pkg/plugins/licensing/licensing.go @@ -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 +} diff --git a/pkg/plugins/manager/fakes/fakes.go b/pkg/plugins/manager/fakes/fakes.go index 394cce815eb..e1d765dd4b6 100644 --- a/pkg/plugins/manager/fakes/fakes.go +++ b/pkg/plugins/manager/fakes/fakes.go @@ -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)} } diff --git a/pkg/plugins/manager/loader/initializer/initializer.go b/pkg/plugins/manager/loader/initializer/initializer.go index 2373b0abc74..4c9a8e06322 100644 --- a/pkg/plugins/manager/loader/initializer/initializer.go +++ b/pkg/plugins/manager/loader/initializer/initializer.go @@ -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()...) } diff --git a/pkg/plugins/manager/loader/initializer/initializer_test.go b/pkg/plugins/manager/loader/initializer/initializer_test.go index 6cc505b274f..4b0d662acd0 100644 --- a/pkg/plugins/manager/loader/initializer/initializer_test.go +++ b/pkg/plugins/manager/loader/initializer/initializer_test.go @@ -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]) }) }