Skip to content

Commit 0974232

Browse files
authored
fix: reset policy evaluations on repeated additions (#1732)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent b42f2b8 commit 0974232

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

app/cli/cmd/attestation_status.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package cmd
1717

1818
import (
1919
"fmt"
20+
"slices"
21+
"strings"
2022
"time"
2123

2224
"github.com/jedib0t/go-pretty/v6/table"
@@ -173,6 +175,11 @@ func materialsTable(status *action.AttestationStatusResult, full bool) error {
173175
return nil
174176
}
175177

178+
// Sort materials by name for consistent output
179+
slices.SortFunc(status.Materials, func(a, b action.AttestationStatusMaterial) int {
180+
return strings.Compare(a.Name, b.Name)
181+
})
182+
176183
mt := newTableWriter()
177184
mt.SetTitle("Materials")
178185

pkg/attestation/crafter/crafter.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"net/url"
2323
"os"
24+
"slices"
2425
"strings"
2526
"time"
2627

@@ -558,6 +559,12 @@ func (c *Crafter) addMaterial(ctx context.Context, m *schemaapi.CraftingSchema_M
558559
return nil, fmt.Errorf("validation error: %w", err)
559560
}
560561

562+
// Remove existing policy evaluations for this material
563+
// since the value might have changed
564+
c.CraftingState.Attestation.PolicyEvaluations = slices.DeleteFunc(c.CraftingState.Attestation.PolicyEvaluations, func(i *api.PolicyEvaluation) bool {
565+
return i.MaterialName == m.Name
566+
})
567+
561568
// Validate policy groups
562569
pgv := policies.NewPolicyGroupVerifier(c.CraftingState.InputSchema, c.attClient, c.Logger)
563570
policyGroupResults, err := pgv.VerifyMaterial(ctx, mt, value)

0 commit comments

Comments
 (0)