constellation/internal/license/checker_enterprise.go

65 lines
1.7 KiB
Go
Raw Normal View History

//go:build enterprise
/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package license
import (
"context"
2022-09-08 05:02:04 -04:00
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/file"
)
type Checker struct {
quotaChecker QuotaChecker
fileHandler file.Handler
}
func NewChecker(quotaChecker QuotaChecker, fileHandler file.Handler) *Checker {
return &Checker{
quotaChecker: quotaChecker,
fileHandler: fileHandler,
}
}
// CheckLicense tries to read the license file and contact license server
// to fetch quota information.
// If no license file is found, community license is assumed.
2022-09-08 05:02:04 -04:00
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 {
printer("Unable to find license file. Assuming community license.\n")
licenseID = CommunityLicense
} else {
printer("Constellation license found!\n")
}
2022-09-08 05:02:04 -04:00
providerStr := provider.String()
if provider == cloudprovider.Azure {
if *providerCfg.Azure.ConfidentialVM {
providerStr = "azure-cvm"
} else {
providerStr = "azure-tl"
}
}
quotaResp, err := c.quotaChecker.QuotaCheck(ctx, QuotaCheckRequest{
2022-09-08 05:02:04 -04:00
License: licenseID,
Action: Init,
Provider: providerStr,
})
if err != nil {
printer("Unable to contact license server.\n")
printer("Please keep your vCPU quota in mind.\n")
} else {
printer("Please keep your vCPU quota (%d) in mind.\n", quotaResp.Quota)
}
return nil
}