From 48a954051d5f78a7bd054b811578a936f093e913 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Tue, 11 Jun 2024 08:08:44 +0200 Subject: [PATCH] fix(attestation): push on dry-run (#932) Signed-off-by: Miguel Martinez Trivino --- app/cli/cmd/attestation_init.go | 4 ++++ app/cli/cmd/attestation_status.go | 11 +---------- .../api/attestation/v1/crafting_state_validations.go | 10 +++++++--- internal/attestation/crafter/crafter.go | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/cli/cmd/attestation_init.go b/app/cli/cmd/attestation_init.go index c414750d0..091fbb6b4 100644 --- a/app/cli/cmd/attestation_init.go +++ b/app/cli/cmd/attestation_init.go @@ -81,6 +81,10 @@ func newAttestationInitCmd() *cobra.Command { return newGracefulError(err) } + if res.DryRun { + logger.Info().Msg("The attestation is being crafted in dry-run mode. It will not get stored once rendered") + } + return encodeOutput(res, simpleStatusTable) }, } diff --git a/app/cli/cmd/attestation_status.go b/app/cli/cmd/attestation_status.go index 4e8058b1e..ddf0a3256 100644 --- a/app/cli/cmd/attestation_status.go +++ b/app/cli/cmd/attestation_status.go @@ -20,7 +20,6 @@ import ( "time" "github.com/jedib0t/go-pretty/v6/table" - "github.com/jedib0t/go-pretty/v6/text" "github.com/muesli/reflow/wrap" "github.com/spf13/cobra" @@ -107,15 +106,7 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult, full b return err } - if err := envVarsTable(status, full); err != nil { - return err - } - - if status.DryRun { - colors := text.Colors{text.FgHiBlack, text.BgHiYellow} - fmt.Println(colors.Sprint("The attestation is being crafted in dry-run mode. It will not get stored once rendered")) - } - return nil + return envVarsTable(status, full) } func envVarsTable(status *action.AttestationStatusResult, full bool) error { diff --git a/internal/attestation/crafter/api/attestation/v1/crafting_state_validations.go b/internal/attestation/crafter/api/attestation/v1/crafting_state_validations.go index d5c72c6b2..30837e695 100644 --- a/internal/attestation/crafter/api/attestation/v1/crafting_state_validations.go +++ b/internal/attestation/crafter/api/attestation/v1/crafting_state_validations.go @@ -26,14 +26,18 @@ import ( // ValidateComplete makes sure that the crafting state has been completed // before it gets passed to the renderer -func (state *CraftingState) ValidateComplete() error { +func (state *CraftingState) ValidateComplete(dryRun bool) error { validator, err := protovalidate.New() if err != nil { return fmt.Errorf("could not create validator: %w", err) } - if err := validator.Validate(state); err != nil { - return fmt.Errorf("invalid crafting state: %w", err) + // We do not want to validate the schema of the state if we are just doing a dry run + // since it's known to not to contain the workflow metadata information + if !dryRun { + if err := validator.Validate(state); err != nil { + return fmt.Errorf("invalid crafting state: %w", err) + } } // Semantic errors diff --git a/internal/attestation/crafter/crafter.go b/internal/attestation/crafter/crafter.go index a2a7fd17c..f0632cc17 100644 --- a/internal/attestation/crafter/crafter.go +++ b/internal/attestation/crafter/crafter.go @@ -599,7 +599,7 @@ func (c *Crafter) ValidateAttestation() error { return err } - return c.CraftingState.ValidateComplete() + return c.CraftingState.ValidateComplete(c.CraftingState.GetDryRun()) } func (c *Crafter) requireStateLoaded() error {