From da167c6ca95db29111ea48ccf0004b472ac6ab01 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Tue, 11 Jun 2024 00:09:44 +0200 Subject: [PATCH 1/2] fix(attestation): push on dry-run Signed-off-by: Miguel Martinez Trivino --- app/cli/cmd/attestation_init.go | 4 ++++ app/cli/cmd/attestation_status.go | 5 ----- .../api/attestation/v1/crafting_state_validations.go | 10 +++++++--- internal/attestation/crafter/crafter.go | 2 +- 4 files changed, 12 insertions(+), 9 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..8bd78c0b4 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" @@ -111,10 +110,6 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult, full b 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 } 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 { From d6abe89482613433dde1d0514f228f266ef34f6f Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Tue, 11 Jun 2024 00:20:43 +0200 Subject: [PATCH 2/2] fix(attestation): push on dry-run Signed-off-by: Miguel Martinez Trivino --- app/cli/cmd/attestation_status.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/cli/cmd/attestation_status.go b/app/cli/cmd/attestation_status.go index 8bd78c0b4..ddf0a3256 100644 --- a/app/cli/cmd/attestation_status.go +++ b/app/cli/cmd/attestation_status.go @@ -106,11 +106,7 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult, full b return err } - if err := envVarsTable(status, full); err != nil { - return err - } - - return nil + return envVarsTable(status, full) } func envVarsTable(status *action.AttestationStatusResult, full bool) error {