license messages (#118)

* license: tell the user whether file couldn't be found or there was another error

* license: print correct info for community license
This commit is contained in:
Thomas Tendyck 2022-09-12 13:38:50 +02:00 committed by GitHub
parent 0952435e25
commit c41018ed32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,8 @@ package license
import (
"context"
"errors"
"io/fs"
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/config"
@ -34,9 +36,12 @@ func NewChecker(quotaChecker QuotaChecker, fileHandler file.Handler) *Checker {
// If no license file is found, community license is assumed.
func (c *Checker) CheckLicense(ctx context.Context, provider cloudprovider.Provider, providerCfg config.ProviderConfig, printer func(string, ...any)) error {
licenseID, err := FromFile(c.fileHandler, constants.LicenseFilename)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
printer("Unable to find license file. Assuming community license.\n")
licenseID = CommunityLicense
} else if err != nil {
printer("Error: %v\nContinuing with community license.\n", err)
licenseID = CommunityLicense
} else {
printer("Constellation license found!\n")
}
@ -57,6 +62,9 @@ func (c *Checker) CheckLicense(ctx context.Context, provider cloudprovider.Provi
if err != nil {
printer("Unable to contact license server.\n")
printer("Please keep your vCPU quota in mind.\n")
} else if licenseID == CommunityLicense {
printer("You can use Constellation to create services for internal consumption.\n")
printer("For details, see https://docs.edgeless.systems/constellation/overview/license\n")
} else {
printer("Please keep your vCPU quota (%d) in mind.\n", quotaResp.Quota)
}