From e45282deaa1d78d7ff3a125e9fd11e3fdc120b07 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 4 Feb 2016 13:00:03 -0500 Subject: Move license storage to database --- utils/license.go | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) (limited to 'utils/license.go') diff --git a/utils/license.go b/utils/license.go index 0d1cd597c..b773a163e 100644 --- a/utils/license.go +++ b/utils/license.go @@ -1,19 +1,15 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils import ( - "bytes" "crypto" "crypto/rsa" "crypto/sha512" "crypto/x509" "encoding/base64" "encoding/pem" - "io" - "os" - "path/filepath" "strconv" "strings" @@ -22,10 +18,6 @@ import ( "github.com/mattermost/platform/model" ) -const ( - LICENSE_FILENAME = "active.dat" -) - var IsLicensed bool = false var License *model.License = &model.License{} var ClientLicense map[string]string = make(map[string]string) @@ -41,18 +33,8 @@ NxpC+5KFhU+xSeeklNqwCgnlOyZ7qSTxmdJHb+60SwuYnnGIYzLJhY4LYDr4J+KR 1wIDAQAB -----END PUBLIC KEY-----`) -func LoadLicense() { - file, err := os.Open(LicenseLocation()) - if err != nil { - l4g.Warn(T("utils.license.load_license.open_find.warn")) - return - } - defer file.Close() - - buf := bytes.NewBuffer(nil) - io.Copy(buf, file) - - if success, licenseStr := ValidateLicense(buf.Bytes()); success { +func LoadLicense(licenseBytes []byte) { + if success, licenseStr := ValidateLicense(licenseBytes); success { license := model.LicenseFromJson(strings.NewReader(licenseStr)) SetLicense(license) return @@ -74,21 +56,10 @@ func SetLicense(license *model.License) bool { return false } -func LicenseLocation() string { - return filepath.Dir(CfgFileName) + "/" + LICENSE_FILENAME -} - -func RemoveLicense() bool { +func RemoveLicense() { License = &model.License{} IsLicensed = false ClientLicense = getClientLicense(License) - - if err := os.Remove(LicenseLocation()); err != nil { - l4g.Error(T("utils.license.remove_license.unable.error"), err.Error()) - return false - } - - return true } func ValidateLicense(signed []byte) (bool, string) { -- cgit v1.2.3-1-g7c22