summaryrefslogtreecommitdiffstats
path: root/app/license.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/license.go')
-rw-r--r--app/license.go107
1 files changed, 5 insertions, 102 deletions
diff --git a/app/license.go b/app/license.go
index efb725a20..c7fd07197 100644
--- a/app/license.go
+++ b/app/license.go
@@ -4,19 +4,16 @@
package app
import (
- "crypto/md5"
- "fmt"
"net/http"
"strings"
l4g "github.com/alecthomas/log4go"
-
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
)
func (a *App) LoadLicense() {
- a.SetLicense(nil)
+ utils.RemoveLicense()
licenseId := ""
if result := <-a.Srv.Store.System().Get(); result.Err == nil {
@@ -39,7 +36,7 @@ func (a *App) LoadLicense() {
if result := <-a.Srv.Store.License().Get(licenseId); result.Err == nil {
record := result.Data.(*model.LicenseRecord)
- a.ValidateAndSetLicenseBytes([]byte(record.Bytes))
+ utils.LoadLicense([]byte(record.Bytes))
l4g.Info("License key valid unlocking enterprise features.")
} else {
l4g.Info(utils.T("mattermost.load_license.find.warn"))
@@ -62,7 +59,7 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError)
}
}
- if ok := a.SetLicense(license); !ok {
+ if ok := utils.SetLicense(license); !ok {
return nil, model.NewAppError("addLicense", model.EXPIRED_LICENSE_ERROR, nil, "", http.StatusBadRequest)
}
@@ -105,115 +102,21 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError)
return license, nil
}
-// License returns the currently active license or nil if the application is unlicensed.
-func (a *App) License() *model.License {
- license, _ := a.licenseValue.Load().(*model.License)
- return license
-}
-
-func (a *App) SetLicense(license *model.License) bool {
- defer func() {
- a.setDefaultRolesBasedOnConfig()
- for _, listener := range a.licenseListeners {
- listener()
- }
- }()
-
- if license != nil {
- license.Features.SetDefaults()
-
- if !license.IsExpired() {
- a.licenseValue.Store(license)
- a.clientLicenseValue.Store(utils.GetClientLicense(license))
- return true
- }
- }
-
- a.licenseValue.Store((*model.License)(nil))
- a.SetClientLicense(map[string]string{"IsLicensed": "false"})
- return false
-}
-
-func (a *App) ValidateAndSetLicenseBytes(b []byte) {
- if success, licenseStr := utils.ValidateLicense(b); success {
- license := model.LicenseFromJson(strings.NewReader(licenseStr))
- a.SetLicense(license)
- return
- }
-
- l4g.Warn(utils.T("utils.license.load_license.invalid.warn"))
-}
-
-func (a *App) SetClientLicense(m map[string]string) {
- a.clientLicenseValue.Store(m)
-}
-
-func (a *App) ClientLicense() map[string]string {
- clientLicense, _ := a.clientLicenseValue.Load().(map[string]string)
- return clientLicense
-}
-
func (a *App) RemoveLicense() *model.AppError {
- if license, _ := a.licenseValue.Load().(*model.License); license == nil {
- return nil
- }
+ utils.RemoveLicense()
sysVar := &model.System{}
sysVar.Name = model.SYSTEM_ACTIVE_LICENSE_ID
sysVar.Value = ""
if result := <-a.Srv.Store.System().SaveOrUpdate(sysVar); result.Err != nil {
+ utils.RemoveLicense()
return result.Err
}
- a.SetLicense(nil)
a.ReloadConfig()
a.InvalidateAllCaches()
return nil
}
-
-func (a *App) AddLicenseListener(listener func()) string {
- id := model.NewId()
- a.licenseListeners[id] = listener
- return id
-}
-
-func (a *App) RemoveLicenseListener(id string) {
- delete(a.licenseListeners, id)
-}
-
-func (a *App) GetClientLicenseEtag(useSanitized bool) string {
- value := ""
-
- lic := a.ClientLicense()
-
- if useSanitized {
- lic = a.GetSanitizedClientLicense()
- }
-
- for k, v := range lic {
- value += fmt.Sprintf("%s:%s;", k, v)
- }
-
- return model.Etag(fmt.Sprintf("%x", md5.Sum([]byte(value))))
-}
-
-func (a *App) GetSanitizedClientLicense() map[string]string {
- sanitizedLicense := make(map[string]string)
-
- for k, v := range a.ClientLicense() {
- sanitizedLicense[k] = v
- }
-
- delete(sanitizedLicense, "Id")
- delete(sanitizedLicense, "Name")
- delete(sanitizedLicense, "Email")
- delete(sanitizedLicense, "PhoneNumber")
- delete(sanitizedLicense, "IssuedAt")
- delete(sanitizedLicense, "StartsAt")
- delete(sanitizedLicense, "ExpiresAt")
-
- return sanitizedLicense
-}