From 00bb4799899cbbcdf48b147639dee3cee7ea199b Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Fri, 31 Mar 2017 06:54:30 -0700 Subject: PLT-6090 adding ability to read license file from disk (#5895) * PLT-6090 adding ability to read license file from disk * Fixing unit test that fails only sometimes * Fixing test that fails randomly --- utils/license.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'utils/license.go') diff --git a/utils/license.go b/utils/license.go index 5ec94386d..f0763d741 100644 --- a/utils/license.go +++ b/utils/license.go @@ -12,6 +12,8 @@ import ( "encoding/base64" "encoding/pem" "fmt" + "io/ioutil" + "os" "strconv" "strings" @@ -112,6 +114,31 @@ func ValidateLicense(signed []byte) (bool, string) { return true, string(plaintext) } +func GetLicenseFileFromDisk(fileName string) []byte { + file, err := os.Open(fileName) + if err != nil { + l4g.Error("Failed to open license key from disk at %v err=%v", fileName, err.Error()) + return nil + } + defer file.Close() + + licenseBytes, err := ioutil.ReadAll(file) + if err != nil { + l4g.Error("Failed to read license key from disk at %v err=%v", fileName, err.Error()) + return nil + } + + return licenseBytes +} + +func GetLicenseFileLocation(fileLocation string) string { + if fileLocation == "" { + return FindDir("config") + "mattermost.mattermost-license" + } else { + return fileLocation + } +} + func getClientLicense(l *model.License) map[string]string { props := make(map[string]string) -- cgit v1.2.3-1-g7c22