Skip to content

Commit

Permalink
Merge pull request #31 from untangle/mfw-1313-fix-license-status
Browse files Browse the repository at this point in the history
Mfw 1313 fix license status
  • Loading branch information
TiffanyKalin-untangle authored Dec 20, 2021
2 parents f5760e7 + d0e507d commit d1fde73
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions services/licensemanager/LicenseManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
"github.com/untangle/golang-shared/services/settings"
)

const (
// LicenseFileDoesNotExistStr is the string to check if licenses should be reloaded when status is returned
LicenseFileDoesNotExistStr string = "RELOAD_LICENSES"
)

var config Config
var services map[string]*Service

Expand Down Expand Up @@ -168,7 +173,17 @@ func GetLicenseDetails() (LicenseInfo, error) {
var retLicense LicenseInfo

// Load file
licenseFileExists := licenseFileExists(config.LicenseLocation)
if !licenseFileExists {
logger.Warn("License file does not exist\n")
return retLicense, errors.New(LicenseFileDoesNotExistStr)
}

jsonLicense, err := ioutil.ReadFile(config.LicenseLocation)
if err != nil {
logger.Warn("Error opening license file: %s\n", err.Error())
return retLicense, err
}

// Unmarshal
err = json.Unmarshal(jsonLicense, &retLicense)
Expand All @@ -181,6 +196,12 @@ func GetLicenseDetails() (LicenseInfo, error) {
return retLicense, nil
}

// GetLicenseFileDoesNotExistStr returns the error string for license file does not exist for comparison reasons
// @return string of the license file does not exist error
func GetLicenseFileDoesNotExistStr() string {
return LicenseFileDoesNotExistStr
}

// SetServices will disable any disabled services to un-enabled in settings
func SetServices(enabledServices map[string]bool) error {
var err error = nil
Expand Down Expand Up @@ -260,6 +281,16 @@ func setServiceState(serviceName string, newAllowedState string, saveStates bool

}

// licenseFileExists checks if a file exists and is not a directory before we
// try using it to prevent further errors.
func licenseFileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

// shutdownServices iterates servicesToShutdown and calls the shutdown hook on them, and also removes the license file
// @param licenseFile string - the license file location
// @param servicesToShutdown map[string]Service - the services we want to shutdown
Expand Down

0 comments on commit d1fde73

Please sign in to comment.