ee license check

os.Exit(0) on license check failure
docker-compose -- restart netmaker container on faiure vice always
This commit is contained in:
Matthew R Kasun 2023-04-12 10:45:06 -04:00
parent 9390c0652a
commit e244dcb4bd
7 changed files with 20 additions and 14 deletions

View file

@ -4,7 +4,7 @@ services:
netmaker: netmaker:
container_name: netmaker container_name: netmaker
image: gravitl/netmaker:v0.18.6 image: gravitl/netmaker:v0.18.6
restart: always restart: on-failure
volumes: volumes:
- dnsconfig:/root/config/dnsconfig - dnsconfig:/root/config/dnsconfig
- sqldata:/root/data - sqldata:/root/data

View file

@ -4,7 +4,7 @@ services:
netmaker: netmaker:
container_name: netmaker container_name: netmaker
image: gravitl/netmaker:REPLACE_SERVER_IMAGE_TAG image: gravitl/netmaker:REPLACE_SERVER_IMAGE_TAG
restart: always restart: on-failure
volumes: volumes:
- dnsconfig:/root/config/dnsconfig - dnsconfig:/root/config/dnsconfig
- sqldata:/root/data - sqldata:/root/data

View file

@ -6,7 +6,7 @@ services:
image: 'gravitl/netclient:v0.18.6' image: 'gravitl/netclient:v0.18.6'
hostname: netmaker-1 hostname: netmaker-1
network_mode: host network_mode: host
restart: always restart: on-failure
environment: environment:
TOKEN: "TOKEN_VALUE" TOKEN: "TOKEN_VALUE"
volumes: volumes:

View file

@ -4,7 +4,7 @@ services:
netmaker: # The Primary Server for running Netmaker netmaker: # The Primary Server for running Netmaker
container_name: netmaker container_name: netmaker
image: gravitl/netmaker:REPLACE_SERVER_IMAGE_TAG image: gravitl/netmaker:REPLACE_SERVER_IMAGE_TAG
restart: always restart: on-failure
volumes: # Volume mounts necessary for sql, coredns, and mqtt volumes: # Volume mounts necessary for sql, coredns, and mqtt
- dnsconfig:/root/config/dnsconfig - dnsconfig:/root/config/dnsconfig
- sqldata:/root/data - sqldata:/root/data

View file

@ -4,7 +4,7 @@ services:
netmaker: netmaker:
container_name: netmaker container_name: netmaker
image: gravitl/netmaker:REPLACE_SERVER_IMAGE_TAG image: gravitl/netmaker:REPLACE_SERVER_IMAGE_TAG
restart: always restart: on-failure
volumes: volumes:
- dnsconfig:/root/config/dnsconfig - dnsconfig:/root/config/dnsconfig
- sqldata:/root/data - sqldata:/root/data

View file

@ -44,17 +44,17 @@ func ValidateLicense() error {
netmakerAccountID := servercfg.GetNetmakerAccountID() netmakerAccountID := servercfg.GetNetmakerAccountID()
logger.Log(0, "proceeding with Netmaker license validation...") logger.Log(0, "proceeding with Netmaker license validation...")
if len(licenseKeyValue) == 0 || len(netmakerAccountID) == 0 { if len(licenseKeyValue) == 0 || len(netmakerAccountID) == 0 {
logger.FatalLog(errValidation.Error()) logger.FatalLog0(errValidation.Error())
} }
apiPublicKey, err := getLicensePublicKey(licenseKeyValue) apiPublicKey, err := getLicensePublicKey(licenseKeyValue)
if err != nil { if err != nil {
logger.FatalLog(errValidation.Error()) logger.FatalLog0(errValidation.Error())
} }
tempPubKey, tempPrivKey, err := FetchApiServerKeys() tempPubKey, tempPrivKey, err := FetchApiServerKeys()
if err != nil { if err != nil {
logger.FatalLog(errValidation.Error()) logger.FatalLog0(errValidation.Error())
} }
licenseSecret := LicenseSecret{ licenseSecret := LicenseSecret{
@ -64,32 +64,32 @@ func ValidateLicense() error {
secretData, err := json.Marshal(&licenseSecret) secretData, err := json.Marshal(&licenseSecret)
if err != nil { if err != nil {
logger.FatalLog(errValidation.Error()) logger.FatalLog0(errValidation.Error())
} }
encryptedData, err := ncutils.BoxEncrypt(secretData, apiPublicKey, tempPrivKey) encryptedData, err := ncutils.BoxEncrypt(secretData, apiPublicKey, tempPrivKey)
if err != nil { if err != nil {
logger.FatalLog(errValidation.Error()) logger.FatalLog0(errValidation.Error())
} }
validationResponse, err := validateLicenseKey(encryptedData, tempPubKey) validationResponse, err := validateLicenseKey(encryptedData, tempPubKey)
if err != nil || len(validationResponse) == 0 { if err != nil || len(validationResponse) == 0 {
logger.FatalLog(errValidation.Error()) logger.FatalLog0(errValidation.Error())
} }
var licenseResponse ValidatedLicense var licenseResponse ValidatedLicense
if err = json.Unmarshal(validationResponse, &licenseResponse); err != nil { if err = json.Unmarshal(validationResponse, &licenseResponse); err != nil {
logger.FatalLog(errValidation.Error()) logger.FatalLog0(errValidation.Error())
} }
respData, err := ncutils.BoxDecrypt(base64decode(licenseResponse.EncryptedLicense), apiPublicKey, tempPrivKey) respData, err := ncutils.BoxDecrypt(base64decode(licenseResponse.EncryptedLicense), apiPublicKey, tempPrivKey)
if err != nil { if err != nil {
logger.FatalLog(errValidation.Error()) logger.FatalLog0(errValidation.Error())
} }
license := LicenseKey{} license := LicenseKey{}
if err = json.Unmarshal(respData, &license); err != nil { if err = json.Unmarshal(respData, &license); err != nil {
logger.FatalLog(errValidation.Error()) logger.FatalLog0(errValidation.Error())
} }
Limits.Networks = math.MaxInt Limits.Networks = math.MaxInt

View file

@ -138,6 +138,12 @@ func FatalLog(message ...string) {
os.Exit(2) os.Exit(2)
} }
// FatalLog0 - exits os after logging
func FatalLog0(message ...string) {
fmt.Printf("[%s] Fatal: %s \n", program, MakeString(" ", message...))
os.Exit(0)
}
// == private == // == private ==
// resetLogs - reallocates logs map // resetLogs - reallocates logs map