Add provider to license check (#88)

This commit is contained in:
Moritz Eckert 2022-09-08 11:02:04 +02:00 committed by GitHub
parent 765c097beb
commit fb5faa681c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 8 deletions

View File

@ -108,7 +108,7 @@ func initialize(cmd *cobra.Command, newDialer func(validator *cloudcmd.Validator
} }
checker := license.NewChecker(quotaChecker, fileHandler) checker := license.NewChecker(quotaChecker, fileHandler)
if err := checker.CheckLicense(cmd.Context(), cmd.Printf); err != nil { if err := checker.CheckLicense(cmd.Context(), provider, config.Provider, cmd.Printf); err != nil {
cmd.Printf("License check failed: %v", err) cmd.Printf("License check failed: %v", err)
} }

View File

@ -11,6 +11,8 @@ package license
import ( import (
"context" "context"
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants" "github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/file" "github.com/edgelesssys/constellation/internal/file"
) )
@ -30,7 +32,7 @@ func NewChecker(quotaChecker QuotaChecker, fileHandler file.Handler) *Checker {
// CheckLicense tries to read the license file and contact license server // CheckLicense tries to read the license file and contact license server
// to fetch quota information. // to fetch quota information.
// If no license file is found, community license is assumed. // If no license file is found, community license is assumed.
func (c *Checker) CheckLicense(ctx context.Context, printer func(string, ...any)) error { 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) licenseID, err := FromFile(c.fileHandler, constants.LicenseFilename)
if err != nil { if err != nil {
printer("Unable to find license file. Assuming community license.\n") printer("Unable to find license file. Assuming community license.\n")
@ -38,9 +40,19 @@ func (c *Checker) CheckLicense(ctx context.Context, printer func(string, ...any)
} else { } else {
printer("Constellation license found!\n") printer("Constellation license found!\n")
} }
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{ quotaResp, err := c.quotaChecker.QuotaCheck(ctx, QuotaCheckRequest{
License: licenseID, License: licenseID,
Action: Init, Action: Init,
Provider: providerStr,
}) })
if err != nil { if err != nil {
printer("Unable to contact license server.\n") printer("Unable to contact license server.\n")

View File

@ -11,6 +11,8 @@ package license
import ( import (
"context" "context"
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/file" "github.com/edgelesssys/constellation/internal/file"
) )
@ -21,6 +23,6 @@ func NewChecker(quotaChecker QuotaChecker, fileHandler file.Handler) *Checker {
} }
// CheckLicense is a no-op for open source version of Constellation. // CheckLicense is a no-op for open source version of Constellation.
func (c *Checker) CheckLicense(ctx context.Context, printer func(string, ...any)) error { func (c *Checker) CheckLicense(ctx context.Context, provider cloudprovider.Provider, providerCfg config.ProviderConfig, printer func(string, ...any)) error {
return nil return nil
} }

View File

@ -22,7 +22,9 @@ const (
licensePath = "api/v1/license" licensePath = "api/v1/license"
) )
type Action string type (
Action string
)
const ( const (
Init Action = "init" Init Action = "init"
@ -44,6 +46,7 @@ func NewClient() *Client {
// QuotaCheckRequest is JSON request to license server to check quota for a given license and action. // QuotaCheckRequest is JSON request to license server to check quota for a given license and action.
type QuotaCheckRequest struct { type QuotaCheckRequest struct {
Action Action `json:"action"` Action Action `json:"action"`
Provider string `json:"provider"`
License string `json:"license"` License string `json:"license"`
} }