Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(attestation): push on dry-run #932

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/cli/cmd/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just removing the dry-run output from stdout and move it to stderr as we are doing lately in the rest of the code.

}

return encodeOutput(res, simpleStatusTable)
},
}
Expand Down
5 changes: 0 additions & 5 deletions app/cli/cmd/attestation_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"time"

"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
"github.com/muesli/reflow/wrap"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -107,14 +106,10 @@
return err
}

if err := envVarsTable(status, full); err != nil {

Check failure on line 109 in app/cli/cmd/attestation_status.go

View workflow job for this annotation

GitHub Actions / lint (main-module)

if-return: redundant if ...; err != nil check, just return error instead. (revive)

Check failure on line 109 in app/cli/cmd/attestation_status.go

View workflow job for this annotation

GitHub Actions / lint (cli)

if-return: redundant if ...; err != nil check, just return error instead. (revive)
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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/attestation/crafter/crafter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading