-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
license: refactor license check to be agnostic of input (#2659)
* license: refactor license check to be agnostic of input * license: remove unused code * cli: only check license file in enterprise version Signed-off-by: Moritz Sanft <[email protected]> * bazel: fix enterprise CLI build * bazel: add keep directive * Update internal/constellation/apply.go Co-authored-by: Daniel Weiße <[email protected]> * license: check for return value --------- Signed-off-by: Moritz Sanft <[email protected]> Co-authored-by: Daniel Weiße <[email protected]>
- Loading branch information
1 parent
381c546
commit 4d6a7fa
Showing
15 changed files
with
201 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//go:build enterprise | ||
|
||
/* | ||
Copyright (c) Edgeless Systems GmbH | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"io/fs" | ||
|
||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" | ||
"github.com/edgelesssys/constellation/v2/internal/constants" | ||
"github.com/edgelesssys/constellation/v2/internal/license" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// checkLicenseFile reads the local license file and checks it's quota | ||
// with the license server. If no license file is present or if errors | ||
// occur during the check, the user is informed and the community license | ||
// is used. It is a no-op in the open source version of Constellation. | ||
func (a *applyCmd) checkLicenseFile(cmd *cobra.Command, csp cloudprovider.Provider) { | ||
var licenseID string | ||
a.log.Debugf("Running license check") | ||
|
||
readBytes, err := a.fileHandler.Read(constants.LicenseFilename) | ||
if errors.Is(err, fs.ErrNotExist) { | ||
cmd.Printf("Using community license.\n") | ||
licenseID = license.CommunityLicense | ||
} else if err != nil { | ||
cmd.Printf("Error: %v\nContinuing with community license.\n", err) | ||
licenseID = license.CommunityLicense | ||
} else { | ||
cmd.Printf("Constellation license found!\n") | ||
licenseID, err = license.FromBytes(readBytes) | ||
if err != nil { | ||
cmd.Printf("Error: %v\nContinuing with community license.\n", err) | ||
licenseID = license.CommunityLicense | ||
} | ||
} | ||
|
||
quota, err := a.applier.CheckLicense(cmd.Context(), csp, licenseID) | ||
if err != nil { | ||
cmd.Printf("Unable to contact license server.\n") | ||
cmd.Printf("Please keep your vCPU quota in mind.\n") | ||
} else if licenseID == license.CommunityLicense { | ||
cmd.Printf("For details, see https://docs.edgeless.systems/constellation/overview/license\n") | ||
} else { | ||
cmd.Printf("Please keep your vCPU quota (%d) in mind.\n", quota) | ||
} | ||
|
||
a.log.Debugf("Checked license") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//go:build !enterprise | ||
|
||
/* | ||
Copyright (c) Edgeless Systems GmbH | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// checkLicenseFile reads the local license file and checks it's quota | ||
// with the license server. If no license file is present or if errors | ||
// occur during the check, the user is informed and the community license | ||
// is used. It is a no-op in the open source version of Constellation. | ||
func (a *applyCmd) checkLicenseFile(*cobra.Command, cloudprovider.Provider) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright (c) Edgeless Systems GmbH | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package constellation | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" | ||
"github.com/edgelesssys/constellation/v2/internal/license" | ||
) | ||
|
||
// An Applier handles applying a specific configuration to a Constellation cluster. | ||
// In Particular, this involves Initialization and Upgrading of the cluster. | ||
type Applier struct { | ||
log debugLog | ||
licenseChecker *license.Checker | ||
} | ||
|
||
type debugLog interface { | ||
Debugf(format string, args ...any) | ||
} | ||
|
||
// NewApplier creates a new Applier. | ||
func NewApplier(log debugLog) *Applier { | ||
return &Applier{ | ||
log: log, | ||
licenseChecker: license.NewChecker(license.NewClient()), | ||
} | ||
} | ||
|
||
// CheckLicense checks the given Constellation license with the license server | ||
// and returns the allowed quota for the license. | ||
func (a *Applier) CheckLicense(ctx context.Context, csp cloudprovider.Provider, licenseID string) (int, error) { | ||
a.log.Debugf("Contacting license server for license '%s'", licenseID) | ||
quotaResp, err := a.licenseChecker.CheckLicense(ctx, csp, licenseID) | ||
if err != nil { | ||
return 0, fmt.Errorf("checking license: %w", err) | ||
} | ||
a.log.Debugf("Got response from license server for license '%s'", licenseID) | ||
|
||
return quotaResp.Quota, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.