MM-18256 Converting to structured logging the file utils/licen… (#12094)
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
230a518059
Коммит
49a900554f
@@ -10,7 +10,6 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -37,7 +36,7 @@ func ValidateLicense(signed []byte) (bool, string) {
|
|||||||
|
|
||||||
_, err := base64.StdEncoding.Decode(decoded, signed)
|
_, err := base64.StdEncoding.Decode(decoded, signed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error(fmt.Sprintf("Encountered error decoding license, err=%v", err.Error()))
|
mlog.Error("Encountered error decoding license", mlog.Err(err))
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +57,7 @@ func ValidateLicense(signed []byte) (bool, string) {
|
|||||||
|
|
||||||
public, err := x509.ParsePKIXPublicKey(block.Bytes)
|
public, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error(fmt.Sprintf("Encountered error signing license, err=%v", err.Error()))
|
mlog.Error("Encountered error signing license", mlog.Err(err))
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +69,7 @@ func ValidateLicense(signed []byte) (bool, string) {
|
|||||||
|
|
||||||
err = rsa.VerifyPKCS1v15(rsaPublic, crypto.SHA512, d, signature)
|
err = rsa.VerifyPKCS1v15(rsaPublic, crypto.SHA512, d, signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error(fmt.Sprintf("Invalid signature, err=%v", err.Error()))
|
mlog.Error("Invalid signature", mlog.Err(err))
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,15 +80,15 @@ func GetAndValidateLicenseFileFromDisk(location string) (*model.License, []byte)
|
|||||||
fileName := GetLicenseFileLocation(location)
|
fileName := GetLicenseFileLocation(location)
|
||||||
|
|
||||||
if _, err := os.Stat(fileName); err != nil {
|
if _, err := os.Stat(fileName); err != nil {
|
||||||
mlog.Debug(fmt.Sprintf("We could not find the license key in the database or on disk at %v", fileName))
|
mlog.Debug("We could not find the license key in the database or on disk at", mlog.String("filename", fileName))
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mlog.Info(fmt.Sprintf("License key has not been uploaded. Loading license key from disk at %v", fileName))
|
mlog.Info("License key has not been uploaded. Loading license key from disk at", mlog.String("filename", fileName))
|
||||||
licenseBytes := GetLicenseFileFromDisk(fileName)
|
licenseBytes := GetLicenseFileFromDisk(fileName)
|
||||||
|
|
||||||
if success, licenseStr := ValidateLicense(licenseBytes); !success {
|
if success, licenseStr := ValidateLicense(licenseBytes); !success {
|
||||||
mlog.Error(fmt.Sprintf("Found license key at %v but it appears to be invalid.", fileName))
|
mlog.Error("Found license key at %v but it appears to be invalid.", mlog.String("filename", fileName))
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else {
|
} else {
|
||||||
return model.LicenseFromJson(strings.NewReader(licenseStr)), licenseBytes
|
return model.LicenseFromJson(strings.NewReader(licenseStr)), licenseBytes
|
||||||
@@ -99,14 +98,14 @@ func GetAndValidateLicenseFileFromDisk(location string) (*model.License, []byte)
|
|||||||
func GetLicenseFileFromDisk(fileName string) []byte {
|
func GetLicenseFileFromDisk(fileName string) []byte {
|
||||||
file, err := os.Open(fileName)
|
file, err := os.Open(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error(fmt.Sprintf("Failed to open license key from disk at %v err=%v", fileName, err.Error()))
|
mlog.Error("Failed to open license key from disk at", mlog.String("filename", fileName), mlog.Err(err))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
licenseBytes, err := ioutil.ReadAll(file)
|
licenseBytes, err := ioutil.ReadAll(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error(fmt.Sprintf("Failed to read license key from disk at %v err=%v", fileName, err.Error()))
|
mlog.Error("Failed to read license key from disk at", mlog.String("filename", fileName), mlog.Err(err))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user