MM-26064 - ENV var license override (#14943)
* License provided through env var takes precedence over other license sources
Этот коммит содержится в:
@@ -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) {
|
||||
|
||||
Ссылка в новой задаче
Block a user