Commit b5ca2381 by Dan Cech Committed by GitHub

provide license token directly via plugin environment (#25987)

* provide license token directly via plugin environment
parent bbdcd59c
...@@ -16,4 +16,6 @@ type Licensing interface { ...@@ -16,4 +16,6 @@ type Licensing interface {
LicenseURL(user *SignedInUser) string LicenseURL(user *SignedInUser) string
StateInfo() string StateInfo() string
TokenRaw() string
} }
...@@ -100,7 +100,11 @@ func (m *manager) Register(pluginID string, factory PluginFactoryFunc) error { ...@@ -100,7 +100,11 @@ func (m *manager) Register(pluginID string, factory PluginFactoryFunc) error {
} }
if m.License.HasLicense() { if m.License.HasLicense() {
hostEnv = append(hostEnv, fmt.Sprintf("GF_ENTERPRISE_LICENSE_PATH=%s", m.Cfg.EnterpriseLicensePath)) hostEnv = append(
hostEnv,
fmt.Sprintf("GF_ENTERPRISE_LICENSE_PATH=%s", m.Cfg.EnterpriseLicensePath),
fmt.Sprintf("GF_ENTERPRISE_LICENSE_TEXT=%s", m.License.TokenRaw()),
)
} }
env := pluginSettings.ToEnv("GF_PLUGIN", hostEnv) env := pluginSettings.ToEnv("GF_PLUGIN", hostEnv)
......
...@@ -251,6 +251,7 @@ func TestManager(t *testing.T) { ...@@ -251,6 +251,7 @@ func TestManager(t *testing.T) {
t.Run("Plugin registration scenario when Grafana is licensed", func(t *testing.T) { t.Run("Plugin registration scenario when Grafana is licensed", func(t *testing.T) {
ctx.license.edition = "Enterprise" ctx.license.edition = "Enterprise"
ctx.license.hasLicense = true ctx.license.hasLicense = true
ctx.license.tokenRaw = "testtoken"
ctx.cfg.BuildVersion = "7.0.0" ctx.cfg.BuildVersion = "7.0.0"
ctx.cfg.EnterpriseLicensePath = "/license.txt" ctx.cfg.EnterpriseLicensePath = "/license.txt"
...@@ -258,8 +259,8 @@ func TestManager(t *testing.T) { ...@@ -258,8 +259,8 @@ func TestManager(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
t.Run("Should provide expected host environment variables", func(t *testing.T) { t.Run("Should provide expected host environment variables", func(t *testing.T) {
require.Len(t, ctx.env, 3) require.Len(t, ctx.env, 4)
require.EqualValues(t, []string{"GF_VERSION=7.0.0", "GF_EDITION=Enterprise", "GF_ENTERPRISE_LICENSE_PATH=/license.txt"}, ctx.env) require.EqualValues(t, []string{"GF_VERSION=7.0.0", "GF_EDITION=Enterprise", "GF_ENTERPRISE_LICENSE_PATH=/license.txt", "GF_ENTERPRISE_LICENSE_TEXT=testtoken"}, ctx.env)
}) })
}) })
}) })
...@@ -383,6 +384,7 @@ func (tp *testPlugin) CallResource(ctx context.Context, req *backend.CallResourc ...@@ -383,6 +384,7 @@ func (tp *testPlugin) CallResource(ctx context.Context, req *backend.CallResourc
type testLicensingService struct { type testLicensingService struct {
edition string edition string
hasLicense bool hasLicense bool
tokenRaw string
} }
func (t *testLicensingService) HasLicense() bool { func (t *testLicensingService) HasLicense() bool {
...@@ -408,3 +410,7 @@ func (t *testLicensingService) LicenseURL(user *models.SignedInUser) string { ...@@ -408,3 +410,7 @@ func (t *testLicensingService) LicenseURL(user *models.SignedInUser) string {
func (t *testLicensingService) HasValidLicense() bool { func (t *testLicensingService) HasValidLicense() bool {
return false return false
} }
func (t *testLicensingService) TokenRaw() string {
return t.tokenRaw
}
...@@ -56,3 +56,7 @@ func (l *OSSLicensingService) Init() error { ...@@ -56,3 +56,7 @@ func (l *OSSLicensingService) Init() error {
func (*OSSLicensingService) HasValidLicense() bool { func (*OSSLicensingService) HasValidLicense() bool {
return false return false
} }
func (*OSSLicensingService) TokenRaw() string {
return ""
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment