mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-24 23:19:39 -05:00
cli: attestation validator debug output (#1262)
* Wrote->Written * Add Validator info logs to debug output --------- Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
2023edaef0
commit
19507677c1
@ -34,11 +34,12 @@ type Validator struct {
|
||||
enforceIDKeyDigest bool
|
||||
azureCVM bool
|
||||
validator atls.Validator
|
||||
log debugLog
|
||||
}
|
||||
|
||||
// NewValidator creates a new Validator.
|
||||
func NewValidator(provider cloudprovider.Provider, conf *config.Config) (*Validator, error) {
|
||||
v := Validator{}
|
||||
func NewValidator(provider cloudprovider.Provider, conf *config.Config, log debugLog) (*Validator, error) {
|
||||
v := Validator{log: log}
|
||||
if provider == cloudprovider.Unknown {
|
||||
return nil, errors.New("unknown cloud provider")
|
||||
}
|
||||
@ -140,7 +141,7 @@ func (v *Validator) PCRS() measurements.M {
|
||||
}
|
||||
|
||||
func (v *Validator) updateValidator(cmd *cobra.Command) {
|
||||
log := warnLogger{cmd: cmd}
|
||||
log := warnLogger{cmd: cmd, log: v.log}
|
||||
switch v.provider {
|
||||
case cloudprovider.GCP:
|
||||
v.validator = gcp.NewValidator(v.pcrs, log)
|
||||
@ -160,10 +161,14 @@ func (v *Validator) updateValidator(cmd *cobra.Command) {
|
||||
// warnLogger implements logging of warnings for validators.
|
||||
type warnLogger struct {
|
||||
cmd *cobra.Command
|
||||
log debugLog
|
||||
}
|
||||
|
||||
// Infof is a no-op since we don't want extra info messages when using the CLI.
|
||||
func (wl warnLogger) Infof(format string, args ...any) {}
|
||||
// Infof messages are reduced to debug messages, since we don't want
|
||||
// the extra info when using the CLI without setting the debug flag.
|
||||
func (wl warnLogger) Infof(fmtStr string, args ...any) {
|
||||
wl.log.Debugf(fmtStr, args...)
|
||||
}
|
||||
|
||||
// Warnf prints a formatted warning from the validator.
|
||||
func (wl warnLogger) Warnf(fmtStr string, args ...any) {
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/edgelesssys/constellation/v2/internal/attestation/qemu"
|
||||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
||||
"github.com/edgelesssys/constellation/v2/internal/config"
|
||||
"github.com/edgelesssys/constellation/v2/internal/logger"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@ -95,7 +96,7 @@ func TestNewValidator(t *testing.T) {
|
||||
conf.Provider.QEMU = &config.QEMUConfig{Measurements: tc.pcrs}
|
||||
}
|
||||
|
||||
validators, err := NewValidator(tc.provider, conf)
|
||||
validators, err := NewValidator(tc.provider, conf, logger.NewTest(t))
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
@ -129,7 +129,7 @@ func (cfm *configFetchMeasurementsCmd) configFetchMeasurements(
|
||||
if err := fileHandler.WriteYAML(flags.configPath, conf, file.OptOverwrite); err != nil {
|
||||
return err
|
||||
}
|
||||
cfm.log.Debugf("Wrote configuration to YAML")
|
||||
cfm.log.Debugf("Configuration written to %s", flags.configPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud
|
||||
cmd.PrintErrf("License check failed: %v", err)
|
||||
}
|
||||
i.log.Debugf("Checked license")
|
||||
validator, err := cloudcmd.NewValidator(provider, conf)
|
||||
validator, err := cloudcmd.NewValidator(provider, conf, i.log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -288,7 +288,7 @@ func (i *initCmd) writeOutput(
|
||||
if err := fileHandler.Write(constants.AdminConfFilename, resp.Kubeconfig, file.OptNone); err != nil {
|
||||
return fmt.Errorf("writing kubeconfig: %w", err)
|
||||
}
|
||||
i.log.Debugf("Wrote kubeconfig to file: %s", constants.AdminConfFilename)
|
||||
i.log.Debugf("Kubeconfig written to %s", constants.AdminConfFilename)
|
||||
|
||||
if mergeConfig {
|
||||
if err := i.merger.mergeConfigs(constants.AdminConfFilename, fileHandler); err != nil {
|
||||
@ -303,7 +303,7 @@ func (i *initCmd) writeOutput(
|
||||
if err := fileHandler.WriteJSON(constants.ClusterIDsFileName, idFile, file.OptOverwrite); err != nil {
|
||||
return fmt.Errorf("writing Constellation ID file: %w", err)
|
||||
}
|
||||
i.log.Debugf("Wrote out Constellation ID file")
|
||||
i.log.Debugf("Constellation ID file written to %s", constants.ClusterIDsFileName)
|
||||
|
||||
if !mergeConfig {
|
||||
fmt.Fprintln(wr, "You can now connect to your cluster by executing:")
|
||||
|
@ -95,7 +95,7 @@ func (r *recoverCmd) recover(
|
||||
interval = 20 * time.Second // Azure LB takes a while to remove unhealthy instances
|
||||
}
|
||||
|
||||
validator, err := cloudcmd.NewValidator(provider, conf)
|
||||
validator, err := cloudcmd.NewValidator(provider, conf, r.log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ func (u *upgradeCheckCmd) upgradeCheck(cmd *cobra.Command, fileHandler file.Hand
|
||||
if err := upgrade.writeConfig(conf, fileHandler, flags.configPath); err != nil {
|
||||
return fmt.Errorf("writing config: %w", err)
|
||||
}
|
||||
cmd.Println("Wrote config successfully.")
|
||||
cmd.Println("Config updated successfully.")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -86,7 +86,7 @@ func (v *verifyCmd) verify(cmd *cobra.Command, fileHandler file.Handler, verifyC
|
||||
|
||||
provider := conf.GetProvider()
|
||||
v.log.Debugf("Creating aTLS Validator for %s", provider)
|
||||
validators, err := cloudcmd.NewValidator(provider, conf)
|
||||
validators, err := cloudcmd.NewValidator(provider, conf, v.log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user