cli: improve user warning / information (#1933)

* print success

* warn when debug img but !debugCluster

* malte feedback

* rename to IsNamedLikeDebugImage
This commit is contained in:
Adrian Stobbe 2023-06-19 16:51:39 +02:00 committed by GitHub
parent 2808012c9c
commit be4a636361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 0 deletions

View File

@ -161,6 +161,7 @@ func (cfm *configFetchMeasurementsCmd) configFetchMeasurements(
return err
}
cfm.log.Debugf("Configuration written to %s", flags.configPath)
cmd.Print("Successfully fetched measurements and updated Configuration\n")
return nil
}

View File

@ -91,6 +91,11 @@ func (c *createCmd) create(cmd *cobra.Command, creator cloudCreator, fileHandler
printedAWarning = true
}
if conf.IsNamedLikeDebugImage() && !conf.IsDebugCluster() {
cmd.PrintErrln("WARNING: A debug image is used but debugCluster is false.")
printedAWarning = true
}
if conf.IsDebugCluster() {
cmd.PrintErrln("WARNING: Creating a debug cluster. This cluster is not secure and should only be used for debugging purposes.")
cmd.PrintErrln("DO NOT USE THIS CLUSTER IN PRODUCTION.")

View File

@ -36,6 +36,7 @@ import (
"gopkg.in/yaml.v3"
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfigapi"
"github.com/edgelesssys/constellation/v2/internal/api/versionsapi"
"github.com/edgelesssys/constellation/v2/internal/attestation/idkeydigest"
"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
@ -542,6 +543,15 @@ func (c *Config) IsReleaseImage() bool {
return strings.HasPrefix(c.Image, "v")
}
// IsNamedLikeDebugImage checks whether image name looks like a debug image.
func (c *Config) IsNamedLikeDebugImage() bool {
v, err := versionsapi.NewVersionFromShortPath(c.Image, versionsapi.VersionKindImage)
if err != nil {
return false
}
return v.Stream == "debug"
}
// GetProvider returns the configured cloud provider.
func (c *Config) GetProvider() cloudprovider.Provider {
if c.Provider.AWS != nil {

View File

@ -854,6 +854,24 @@ func TestConfigVersionCompatibility(t *testing.T) {
}
}
func TestIsDebugImage(t *testing.T) {
cases := map[string]struct {
image string
expected bool
}{
"debug image": {"ref/test/stream/debug/v2.9.0-pre.0.20230613084544-eeea7b1f56f4", true},
"release image": {"v2.8.0", false},
"empty image": {"", false},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &Config{Image: tc.image}
assert.Equal(t, tc.expected, c.IsNamedLikeDebugImage())
})
}
}
func TestIsAppClientIDError(t *testing.T) {
testCases := map[string]struct {
err error