switch to using featureEnabled for enterprise features (#41559)

* switch to using featureEnabled for enterprise features
This commit is contained in:
Dan Cech
2022-01-07 15:11:23 -05:00
committed by GitHub
parent 9eb82f9fff
commit 34f757ba5a
34 changed files with 109 additions and 148 deletions
+1 -3
View File
@@ -250,15 +250,13 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i
"latestVersion": hs.updateChecker.LatestGrafanaVersion(),
"hasUpdate": hs.updateChecker.GrafanaUpdateAvailable(),
"env": setting.Env,
"isEnterprise": hs.License.HasValidLicense(),
},
"licenseInfo": map[string]interface{}{
"hasLicense": hs.License.HasLicense(),
"hasValidLicense": hs.License.HasValidLicense(),
"expiry": hs.License.Expiry(),
"stateInfo": hs.License.StateInfo(),
"licenseUrl": hs.License.LicenseURL(hasAccess(accesscontrol.ReqGrafanaAdmin, accesscontrol.LicensingPageReaderAccess)),
"edition": hs.License.Edition(),
"enabledFeatures": hs.License.EnabledFeatures(),
},
"featureToggles": hs.Cfg.FeatureToggles,
"rendererAvailable": hs.RenderService.IsAvailable(),
+1 -9
View File
@@ -611,7 +611,7 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
NewGrafanaVersion: hs.updateChecker.LatestGrafanaVersion(),
NewGrafanaVersionExists: hs.updateChecker.GrafanaUpdateAvailable(),
AppName: setting.ApplicationName,
AppNameBodyClass: getAppNameBodyClass(hs.License.HasValidLicense()),
AppNameBodyClass: "app-grafana",
FavIcon: "public/img/fav32.png",
AppleTouchIcon: "public/img/apple-touch-icon.png",
AppTitle: "Grafana",
@@ -680,11 +680,3 @@ func (hs *HTTPServer) NotFoundHandler(c *models.ReqContext) {
c.HTML(404, "index", data)
}
func getAppNameBodyClass(validLicense bool) string {
if validLicense {
return "app-enterprise"
}
return "app-grafana"
}
+1 -1
View File
@@ -349,7 +349,7 @@ func (hs *HTTPServer) RedirectResponseWithError(ctx *models.ReqContext, err erro
}
func (hs *HTTPServer) samlEnabled() bool {
return hs.SettingsProvider.KeyValue("auth.saml", "enabled").MustBool(false) && hs.License.HasValidLicense()
return hs.SettingsProvider.KeyValue("auth.saml", "enabled").MustBool(false) && hs.License.FeatureEnabled("saml")
}
func (hs *HTTPServer) samlName() string {
+1 -1
View File
@@ -30,7 +30,7 @@ func (hs *HTTPServer) GetTeamMembers(c *models.ReqContext) response.Response {
member.AvatarUrl = dtos.GetGravatarUrl(member.Email)
member.Labels = []string{}
if hs.License.HasValidLicense() && member.External {
if hs.License.FeatureEnabled("teamgroupsync") && member.External {
authProvider := GetAuthProviderLabel(member.AuthModule)
member.Labels = append(member.Labels, authProvider)
}
+4 -6
View File
@@ -1,12 +1,6 @@
package models
type Licensing interface {
// HasValidLicense is true if a valid license exists
HasValidLicense() bool
// HasLicense is true if there is a license provided
HasLicense() bool
// Expiry returns the unix epoch timestamp when the license expires, or 0 if no valid license is provided
Expiry() int64
@@ -19,6 +13,10 @@ type Licensing interface {
LicenseURL(showAdminLicensingPage bool) string
StateInfo() string
EnabledFeatures() map[string]bool
FeatureEnabled(feature string) bool
}
type LicenseEnvironment interface {
@@ -196,11 +196,11 @@ func (i *Initializer) envVars(plugin *plugins.Plugin) []string {
fmt.Sprintf("GF_VERSION=%s", i.cfg.BuildVersion),
}
if i.license != nil && i.license.HasLicense() {
if i.license != nil {
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.cfg.EnterpriseLicensePath),
)
if envProvider, ok := i.license.(models.LicenseEnvironment); ok {
@@ -227,8 +227,8 @@ func TestInitializer_envVars(t *testing.T) {
}
licensing := &testLicensingService{
edition: "test",
hasLicense: true,
edition: "test",
tokenRaw: "token",
}
i := &Initializer{
@@ -249,8 +249,8 @@ func TestInitializer_envVars(t *testing.T) {
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=", envVars[4])
assert.Equal(t, "GF_ENTERPRISE_LICENSE_PATH=/path/to/ent/license", envVars[3])
assert.Equal(t, "GF_ENTERPRISE_LICENSE_TEXT=token", envVars[4])
})
}
@@ -314,13 +314,8 @@ func Test_pluginSettings_ToEnv(t *testing.T) {
}
type testLicensingService struct {
edition string
hasLicense bool
tokenRaw string
}
func (t *testLicensingService) HasLicense() bool {
return t.hasLicense
edition string
tokenRaw string
}
func (t *testLicensingService) Expiry() int64 {
@@ -343,14 +338,18 @@ func (t *testLicensingService) LicenseURL(showAdminLicensingPage bool) string {
return ""
}
func (t *testLicensingService) HasValidLicense() bool {
return false
}
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 testPlugin struct {
backendplugin.Plugin
}
+10 -11
View File
@@ -894,13 +894,8 @@ func newLoader(cfg *setting.Cfg) *Loader {
}
type fakeLicensingService struct {
edition string
hasLicense bool
tokenRaw string
}
func (t *fakeLicensingService) HasLicense() bool {
return t.hasLicense
edition string
tokenRaw string
}
func (t *fakeLicensingService) Expiry() int64 {
@@ -923,14 +918,18 @@ func (t *fakeLicensingService) LicenseURL(_ bool) string {
return ""
}
func (t *fakeLicensingService) HasValidLicense() bool {
return false
}
func (t *fakeLicensingService) Environment() map[string]string {
return map[string]string{"GF_ENTERPRISE_LICENSE_TEXT": t.tokenRaw}
}
func (*fakeLicensingService) EnabledFeatures() map[string]bool {
return map[string]bool{}
}
func (*fakeLicensingService) FeatureEnabled(feature string) bool {
return false
}
type fakeLogger struct {
log.Logger
}
+5 -5
View File
@@ -16,10 +16,6 @@ type OSSLicensingService struct {
HooksService *hooks.HooksService
}
func (*OSSLicensingService) HasLicense() bool {
return false
}
func (*OSSLicensingService) Expiry() int64 {
return 0
}
@@ -44,7 +40,11 @@ func (l *OSSLicensingService) LicenseURL(showAdminLicensingPage bool) string {
return "https://grafana.com/oss/grafana?utm_source=grafana_footer"
}
func (*OSSLicensingService) HasValidLicense() bool {
func (*OSSLicensingService) EnabledFeatures() map[string]bool {
return map[string]bool{}
}
func (*OSSLicensingService) FeatureEnabled(feature string) bool {
return false
}