MM-18256 Converting to structured logging the file utils/licen… (#12094)
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
230a518059
Коммит
49a900554f
@@ -10,7 +10,6 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -37,7 +36,7 @@ func ValidateLicense(signed []byte) (bool, string) {
|
||||
|
||||
_, err := base64.StdEncoding.Decode(decoded, signed)
|
||||
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, ""
|
||||
}
|
||||
|
||||
@@ -58,7 +57,7 @@ func ValidateLicense(signed []byte) (bool, string) {
|
||||
|
||||
public, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||
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, ""
|
||||
}
|
||||
|
||||
@@ -70,7 +69,7 @@ func ValidateLicense(signed []byte) (bool, string) {
|
||||
|
||||
err = rsa.VerifyPKCS1v15(rsaPublic, crypto.SHA512, d, signature)
|
||||
if err != nil {
|
||||
mlog.Error(fmt.Sprintf("Invalid signature, err=%v", err.Error()))
|
||||
mlog.Error("Invalid signature", mlog.Err(err))
|
||||
return false, ""
|
||||
}
|
||||
|
||||
@@ -81,15 +80,15 @@ func GetAndValidateLicenseFileFromDisk(location string) (*model.License, []byte)
|
||||
fileName := GetLicenseFileLocation(location)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
} else {
|
||||
return model.LicenseFromJson(strings.NewReader(licenseStr)), licenseBytes
|
||||
@@ -99,14 +98,14 @@ func GetAndValidateLicenseFileFromDisk(location string) (*model.License, []byte)
|
||||
func GetLicenseFileFromDisk(fileName string) []byte {
|
||||
file, err := os.Open(fileName)
|
||||
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
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
licenseBytes, err := ioutil.ReadAll(file)
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user