MM-26064 - ENV var license override (#14943)
* License provided through env var takes precedence over other license sources
Этот коммит содержится в:
@@ -7,6 +7,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||||
@@ -14,9 +15,21 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/utils"
|
"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() {
|
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 := ""
|
licenseId := ""
|
||||||
props, err := s.Store.System().Get()
|
props, err := s.Store.System().Get()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -137,14 +150,15 @@ func (s *Server) SetLicense(license *model.License) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ValidateAndSetLicenseBytes(b []byte) {
|
func (s *Server) ValidateAndSetLicenseBytes(b []byte) bool {
|
||||||
if success, licenseStr := utils.ValidateLicense(b); success {
|
if success, licenseStr := utils.ValidateLicense(b); success {
|
||||||
license := model.LicenseFromJson(strings.NewReader(licenseStr))
|
license := model.LicenseFromJson(strings.NewReader(licenseStr))
|
||||||
s.SetLicense(license)
|
s.SetLicense(license)
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
mlog.Warn("No valid enterprise license found")
|
mlog.Warn("No valid enterprise license found")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) SetClientLicense(m map[string]string) {
|
func (s *Server) SetClientLicense(m map[string]string) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user