MM-26064 - ENV var license override (#14943)

* License provided through env var takes precedence over other license sources
Этот коммит содержится в:
Doug Lauder
2020-07-01 13:27:37 -04:00
коммит произвёл GitHub
родитель 4c50c7c59b
Коммит 00aeca0e5c

Просмотреть файл

@@ -7,6 +7,7 @@ import (
"bytes"
"errors"
"net/http"
"os"
"strings"
"github.com/mattermost/mattermost-server/v5/mlog"
@@ -14,9 +15,21 @@ import (
"github.com/mattermost/mattermost-server/v5/utils"
)
const requestTrialURL = "https://customers.mattermost.com/api/v1/trials"
const (
requestTrialURL = "https://customers.mattermost.com/api/v1/trials"
LicenseEnv = "MM_LICENSE"
)
func (s *Server) LoadLicense() {
// ENV var overrides all other sources of license.
licenseStr := os.Getenv(LicenseEnv)
if licenseStr != "" {
if s.ValidateAndSetLicenseBytes([]byte(licenseStr)) {
mlog.Info("License key from ENV is valid, unlocking enterprise features.")
}
return
}
licenseId := ""
props, err := s.Store.System().Get()
if err == nil {
@@ -137,14 +150,15 @@ func (s *Server) SetLicense(license *model.License) bool {
return false
}
func (s *Server) ValidateAndSetLicenseBytes(b []byte) {
func (s *Server) ValidateAndSetLicenseBytes(b []byte) bool {
if success, licenseStr := utils.ValidateLicense(b); success {
license := model.LicenseFromJson(strings.NewReader(licenseStr))
s.SetLicense(license)
return
return true
}
mlog.Warn("No valid enterprise license found")
return false
}
func (s *Server) SetClientLicense(m map[string]string) {