mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-02-03 11:00:09 -05:00
cli: define feature set of cli editions and exit early if a feature is not supported
This commit is contained in:
parent
8a851c8f39
commit
c62e54831b
@ -40,6 +40,7 @@ go_library(
|
||||
"//bootstrapper/initproto",
|
||||
"//cli/internal/cloudcmd",
|
||||
"//cli/internal/clusterid",
|
||||
"//cli/internal/featureset",
|
||||
"//cli/internal/helm",
|
||||
"//cli/internal/iamid",
|
||||
"//cli/internal/kubernetes",
|
||||
|
@ -14,10 +14,10 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/featureset"
|
||||
"github.com/edgelesssys/constellation/v2/internal/api/versionsapi"
|
||||
"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
|
||||
"github.com/edgelesssys/constellation/v2/internal/config"
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||
"github.com/edgelesssys/constellation/v2/internal/sigstore"
|
||||
"github.com/spf13/afero"
|
||||
@ -47,6 +47,7 @@ type fetchMeasurementsFlags struct {
|
||||
}
|
||||
|
||||
type configFetchMeasurementsCmd struct {
|
||||
canFetchMeasurements bool
|
||||
log debugLog
|
||||
}
|
||||
|
||||
@ -61,7 +62,7 @@ func runConfigFetchMeasurements(cmd *cobra.Command, _ []string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("constructing Rekor client: %w", err)
|
||||
}
|
||||
cfm := &configFetchMeasurementsCmd{log: log}
|
||||
cfm := &configFetchMeasurementsCmd{log: log, canFetchMeasurements: featureset.CanFetchMeasurements}
|
||||
|
||||
return cfm.configFetchMeasurements(cmd, sigstore.CosignVerifier{}, rekor, fileHandler, http.DefaultClient)
|
||||
}
|
||||
@ -76,6 +77,11 @@ func (cfm *configFetchMeasurementsCmd) configFetchMeasurements(
|
||||
}
|
||||
cfm.log.Debugf("Using flags %v", flags)
|
||||
|
||||
if !cfm.canFetchMeasurements {
|
||||
cmd.PrintErrln("Fetching measurements is not supported in the OSS build of the Constellation CLI. Consult the documentation for instructions on where to download the enterprise version.")
|
||||
return errors.New("fetching measurements is not supported")
|
||||
}
|
||||
|
||||
cfm.log.Debugf("Loading configuration file from %q", flags.configPath)
|
||||
conf, err := config.NewWithClient(fileHandler, flags.configPath, client, flags.force)
|
||||
var configValidationErr *config.ValidationError
|
||||
|
@ -277,7 +277,7 @@ func TestConfigFetchMeasurements(t *testing.T) {
|
||||
|
||||
err := fileHandler.WriteYAML(constants.ConfigFilename, gcpConfig, file.OptMkdirAll)
|
||||
require.NoError(err)
|
||||
cfm := &configFetchMeasurementsCmd{log: logger.NewTest(t)}
|
||||
cfm := &configFetchMeasurementsCmd{canFetchMeasurements: true, log: logger.NewTest(t)}
|
||||
|
||||
err = cfm.configFetchMeasurements(cmd, tc.cosign, tc.rekor, fileHandler, client)
|
||||
if tc.wantErr {
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/featureset"
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/helm"
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/kubernetes"
|
||||
"github.com/edgelesssys/constellation/v2/internal/api/fetcher"
|
||||
@ -73,6 +74,7 @@ func runUpgradeCheck(cmd *cobra.Command, _ []string) error {
|
||||
return fmt.Errorf("constructing Rekor client: %w", err)
|
||||
}
|
||||
up := &upgradeCheckCmd{
|
||||
canUpgradeCheck: featureset.CanUpgradeCheck,
|
||||
collect: &versionCollector{
|
||||
writer: cmd.OutOrStderr(),
|
||||
checker: checker,
|
||||
@ -123,6 +125,7 @@ func parseUpgradeCheckFlags(cmd *cobra.Command) (upgradeCheckFlags, error) {
|
||||
}
|
||||
|
||||
type upgradeCheckCmd struct {
|
||||
canUpgradeCheck bool
|
||||
collect collector
|
||||
log debugLog
|
||||
}
|
||||
@ -138,6 +141,12 @@ func (u *upgradeCheckCmd) upgradeCheck(cmd *cobra.Command, fileHandler file.Hand
|
||||
return err
|
||||
}
|
||||
u.log.Debugf("Read configuration from %q", flags.configPath)
|
||||
|
||||
if !u.canUpgradeCheck {
|
||||
cmd.PrintErrln("Planning Constellation upgrades automatically is not supported in the OSS build of the Constellation CLI. Consult the documentation for instructions on where to download the enterprise version.")
|
||||
return errors.New("upgrade check is not supported")
|
||||
}
|
||||
|
||||
// get current image version of the cluster
|
||||
csp := conf.GetProvider()
|
||||
attestationVariant := conf.GetAttestationConfig().GetVariant()
|
||||
|
@ -264,6 +264,7 @@ func TestUpgradeCheck(t *testing.T) {
|
||||
require.NoError(fileHandler.WriteYAML(tc.flags.configPath, cfg))
|
||||
|
||||
checkCmd := upgradeCheckCmd{
|
||||
canUpgradeCheck: true,
|
||||
collect: &tc.collector,
|
||||
log: logger.NewTest(t),
|
||||
}
|
||||
|
14
cli/internal/featureset/BUILD.bazel
Normal file
14
cli/internal/featureset/BUILD.bazel
Normal file
@ -0,0 +1,14 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "featureset",
|
||||
srcs = [
|
||||
"featureset.go",
|
||||
# keep
|
||||
"featureset_enterprise.go",
|
||||
# keep
|
||||
"featureset_oss.go",
|
||||
],
|
||||
importpath = "github.com/edgelesssys/constellation/v2/cli/internal/featureset",
|
||||
visibility = ["//cli:__subpackages__"],
|
||||
)
|
28
cli/internal/featureset/featureset.go
Normal file
28
cli/internal/featureset/featureset.go
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
// package featureset provides a way to check whether a feature is enabled in the current build.
|
||||
package featureset
|
||||
|
||||
// Edition is the edition of a build.
|
||||
type Edition int
|
||||
|
||||
const (
|
||||
// EditionOSS is the open-source software edition.
|
||||
EditionOSS Edition = iota
|
||||
// EditionEnterprise is the enterprise edition.
|
||||
EditionEnterprise
|
||||
)
|
||||
|
||||
// CanFetchMeasurements returns whether the current build can fetch measurements.
|
||||
const CanFetchMeasurements = canFetchMeasurements
|
||||
|
||||
// CanUpgradeCheck returns whether the current build can check for upgrades.
|
||||
// This also includes fetching new measurements.
|
||||
const CanUpgradeCheck = canUpgradeCheck
|
||||
|
||||
// CurrentEdition is the edition of the current build.
|
||||
const CurrentEdition = edition
|
15
cli/internal/featureset/featureset_enterprise.go
Normal file
15
cli/internal/featureset/featureset_enterprise.go
Normal file
@ -0,0 +1,15 @@
|
||||
//go:build enterprise
|
||||
|
||||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package featureset
|
||||
|
||||
const (
|
||||
edition = EditionEnterprise
|
||||
canFetchMeasurements = true
|
||||
canUpgradeCheck = true
|
||||
)
|
15
cli/internal/featureset/featureset_oss.go
Normal file
15
cli/internal/featureset/featureset_oss.go
Normal file
@ -0,0 +1,15 @@
|
||||
//go:build !enterprise
|
||||
|
||||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package featureset
|
||||
|
||||
const (
|
||||
edition = EditionOSS
|
||||
canFetchMeasurements = false
|
||||
canUpgradeCheck = false
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user