Licensing service (#19903)

* Licensing: supplies a service to handle licensing information

* Licensing: uses the license service further

Uses the license service instead of settings.isEnterprise:
- external team members
- saml
- usage stats

* Licensing: fixes broken tests due to new Licensing service dependency

* Licensing: fixes linting errors

* Licensing: exposes license expiry information to the frontend
This commit is contained in:
Leonard Gram
2019-11-01 14:56:12 +01:00
committed by GitHub
parent 0ecc9a57f1
commit 992b4b8adf
12 changed files with 61 additions and 19 deletions

View File

@@ -154,7 +154,7 @@ func (hs *HTTPServer) registerRoutes() {
teamsRoute.Post("/", bind(models.CreateTeamCommand{}), Wrap(hs.CreateTeam))
teamsRoute.Put("/:teamId", bind(models.UpdateTeamCommand{}), Wrap(hs.UpdateTeam))
teamsRoute.Delete("/:teamId", Wrap(hs.DeleteTeamByID))
teamsRoute.Get("/:teamId/members", Wrap(GetTeamMembers))
teamsRoute.Get("/:teamId/members", Wrap(hs.GetTeamMembers))
teamsRoute.Post("/:teamId/members", bind(models.AddTeamMemberCommand{}), Wrap(hs.AddTeamMember))
teamsRoute.Put("/:teamId/members/:userId", bind(models.UpdateTeamMemberCommand{}), Wrap(hs.UpdateTeamMember))
teamsRoute.Delete("/:teamId/members/:userId", Wrap(hs.RemoveTeamMember))

View File

@@ -196,7 +196,11 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf
"latestVersion": plugins.GrafanaLatestVersion,
"hasUpdate": plugins.GrafanaHasUpdate,
"env": setting.Env,
"isEnterprise": setting.IsEnterprise,
"isEnterprise": hs.License.HasValidLicense(),
},
"licenseInfo": map[string]interface{}{
"hasLicense": hs.License.HasLicense(),
"expiry": hs.License.Expiry(),
},
"featureToggles": hs.Cfg.FeatureToggles,
}

View File

@@ -69,6 +69,7 @@ type HTTPServer struct {
RemoteCacheService *remotecache.RemoteCache `inject:""`
ProvisioningService ProvisioningService `inject:""`
Login *login.LoginService `inject:""`
License models.Licensing `inject:""`
}
func (hs *HTTPServer) Init() error {

View File

@@ -83,7 +83,7 @@ func (hs *HTTPServer) setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, er
NewGrafanaVersion: plugins.GrafanaLatestVersion,
NewGrafanaVersionExists: plugins.GrafanaHasUpdate,
AppName: setting.ApplicationName,
AppNameBodyClass: getAppNameBodyClass(setting.ApplicationName),
AppNameBodyClass: getAppNameBodyClass(hs.License.HasValidLicense()),
}
if setting.DisableGravatar {
@@ -372,13 +372,10 @@ func (hs *HTTPServer) NotFoundHandler(c *m.ReqContext) {
c.HTML(404, "index", data)
}
func getAppNameBodyClass(name string) string {
switch name {
case setting.APP_NAME:
return "app-grafana"
case setting.APP_NAME_ENTERPRISE:
func getAppNameBodyClass(validLicense bool) string {
if validLicense {
return "app-enterprise"
default:
return ""
}
return "app-grafana"
}

View File

@@ -40,7 +40,7 @@ func (hs *HTTPServer) LoginView(c *models.ReqContext) {
}
viewData.Settings["oauth"] = enabledOAuths
viewData.Settings["samlEnabled"] = setting.IsEnterprise && hs.Cfg.SAMLEnabled
viewData.Settings["samlEnabled"] = hs.License.HasValidLicense() && hs.Cfg.SAMLEnabled
if loginError, ok := tryGetEncryptedCookie(c, LoginErrorCookieName); ok {
//this cookie is only set whenever an OAuth login fails

View File

@@ -60,7 +60,8 @@ func TestLoginErrorCookieApiEndpoint(t *testing.T) {
sc := setupScenarioContext("/login")
hs := &HTTPServer{
Cfg: setting.NewCfg(),
Cfg: setting.NewCfg(),
License: models.OSSLicensingService{},
}
sc.defaultHandler = Wrap(func(w http.ResponseWriter, c *models.ReqContext) {
@@ -109,7 +110,8 @@ func TestLoginOAuthRedirect(t *testing.T) {
sc := setupScenarioContext("/login")
hs := &HTTPServer{
Cfg: setting.NewCfg(),
Cfg: setting.NewCfg(),
License: models.OSSLicensingService{},
}
sc.defaultHandler = Wrap(func(c *models.ReqContext) {

View File

@@ -5,12 +5,11 @@ import (
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/teamguardian"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
)
// GET /api/teams/:teamId/members
func GetTeamMembers(c *m.ReqContext) Response {
func (hs *HTTPServer) GetTeamMembers(c *m.ReqContext) Response {
query := m.GetTeamMembersQuery{OrgId: c.OrgId, TeamId: c.ParamsInt64(":teamId")}
if err := bus.Dispatch(&query); err != nil {
@@ -21,7 +20,7 @@ func GetTeamMembers(c *m.ReqContext) Response {
member.AvatarUrl = dtos.GetGravatarUrl(member.Email)
member.Labels = []string{}
if setting.IsEnterprise && member.External {
if hs.License.HasValidLicense() && member.External {
authProvider := GetAuthProviderLabel(member.AuthModule)
member.Labels = append(member.Labels, authProvider)
}