Skip to content

Commit e8ed8e2

Browse files
committed
fix lint errors
1 parent 8e37949 commit e8ed8e2

File tree

2 files changed

+46
-55
lines changed

2 files changed

+46
-55
lines changed

cmd/validate/vsa.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ const (
5757

5858
// Constants for validation status
5959
const (
60-
unknownReason = "unknown"
60+
unknownReason = "unknown"
61+
noPolicyDiff = "none"
62+
retrievalFailedRC = "retrieval_failed"
6163
)
6264

6365
// Reason code mappings
@@ -307,7 +309,7 @@ func runValidateVSA(cmd *cobra.Command, data *validateVSAData, args []string, fs
307309
}
308310
printVSAInfo(os.Stdout, fmt.Sprintf("Policy: %s", data.policyConfig))
309311

310-
return validateSnapshotVSAsFromSpec(ctx, snapshot, data, fs, cmd)
312+
return validateSnapshotVSAsFromSpec(ctx, snapshot, data, cmd)
311313
}
312314

313315
// validateVSAInput validates the command input using Cobra's validation patterns
@@ -439,7 +441,7 @@ func worker(jobs <-chan app.SnapshotComponent, results chan<- vsa.ComponentResul
439441

440442
// validateSnapshotVSAsFromSpec processes components from a SnapshotSpec in parallel
441443
// This is the unified processing path used by both --images and single identifier cases
442-
func validateSnapshotVSAsFromSpec(ctx context.Context, snapshot *app.SnapshotSpec, data *validateVSAData, fs afero.Fs, cmd *cobra.Command) error {
444+
func validateSnapshotVSAsFromSpec(ctx context.Context, snapshot *app.SnapshotSpec, data *validateVSAData, cmd *cobra.Command) error {
443445
// Store snapshot spec for use in fallback validation
444446
data.snapshot = snapshot
445447

@@ -1005,21 +1007,21 @@ func buildPolicyDiffDisplay(data AllSectionsData) *PolicyDiffDisplay {
10051007
if totals.Added > 0 {
10061008
diff.Added = fmt.Sprintf("[include] %d", totals.Added)
10071009
} else {
1008-
diff.Added = "none"
1010+
diff.Added = noPolicyDiff
10091011
}
10101012

10111013
// Build removed line
10121014
if totals.Removed > 0 {
10131015
diff.Removed = fmt.Sprintf("%d", totals.Removed)
10141016
} else {
1015-
diff.Removed = "none"
1017+
diff.Removed = noPolicyDiff
10161018
}
10171019

10181020
// Build changed line
10191021
if totals.Changed > 0 {
10201022
diff.Changed = fmt.Sprintf("%d", totals.Changed)
10211023
} else {
1022-
diff.Changed = "none"
1024+
diff.Changed = noPolicyDiff
10231025
}
10241026

10251027
return diff
@@ -1280,17 +1282,6 @@ func filterVSAOutputFormats(outputFormats []string) []string {
12801282
return filtered
12811283
}
12821284

1283-
// filterFallbackOutputFormats returns all output formats for fallback validation
1284-
// The fallback validation uses WriteReport which supports all formats (json, yaml, text,
1285-
// appstudio, summary, junit, attestation, etc.), just like the validate image command.
1286-
// Note: If both VSA sections and fallback specify the same format (e.g., json), both
1287-
// will output in that format (though they produce different JSON structures).
1288-
func filterFallbackOutputFormats(outputFormats []string) []string {
1289-
// Return all formats - fallback validation supports all output formats
1290-
// including json, yaml, and text, just like validate image command
1291-
return outputFormats
1292-
}
1293-
12941285
// isFailureResult determines if a result represents a failure
12951286
func isFailureResult(result vsa.ComponentResult) bool {
12961287
resultType := classifyResult(result)
@@ -1502,16 +1493,16 @@ func createValidationResultFromError(err error) *vsa.ValidationResult {
15021493
}
15031494

15041495
// Determine reason code from error message
1505-
reasonCode := "retrieval_failed"
1496+
reasonCode := retrievalFailedRC
15061497
errMsg := err.Error()
15071498

15081499
// Check for specific error types
15091500
if strings.Contains(errMsg, "timeout") || strings.Contains(errMsg, "exceeded allowed execution time") {
1510-
reasonCode = "retrieval_failed"
1501+
reasonCode = retrievalFailedRC
15111502
} else if strings.Contains(errMsg, "no entries found") || strings.Contains(errMsg, "not found") {
15121503
reasonCode = "no_vsa"
15131504
} else if strings.Contains(errMsg, "signature") {
1514-
reasonCode = "retrieval_failed"
1505+
reasonCode = retrievalFailedRC
15151506
}
15161507

15171508
return &vsa.ValidationResult{

cmd/validate/vsa_test.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,7 @@ func TestBuildResultDisplay(t *testing.T) {
20812081
name: "failed with fallback for all",
20822082
data: AllSectionsData{
20832083
OverallPassed: false,
2084-
FallbackUsed: true,
2084+
FallbackUsed: true,
20852085
FallbackCount: 2,
20862086
TotalImages: 2,
20872087
ImageStatuses: []ImageStatus{
@@ -2103,7 +2103,7 @@ func TestBuildResultDisplay(t *testing.T) {
21032103
name: "failed with fallback for some",
21042104
data: AllSectionsData{
21052105
OverallPassed: false,
2106-
FallbackUsed: true,
2106+
FallbackUsed: true,
21072107
FallbackCount: 1,
21082108
TotalImages: 3,
21092109
ImageStatuses: []ImageStatus{
@@ -2127,8 +2127,8 @@ func TestBuildResultDisplay(t *testing.T) {
21272127
name: "empty images",
21282128
data: AllSectionsData{
21292129
OverallPassed: true,
2130-
FallbackUsed: false,
2131-
TotalImages: 0,
2130+
FallbackUsed: false,
2131+
TotalImages: 0,
21322132
ImageStatuses: []ImageStatus{},
21332133
},
21342134
expected: ResultDisplay{
@@ -2277,9 +2277,9 @@ func TestBuildVSASummaryDisplay(t *testing.T) {
22772277
FallbackReasons: map[string]bool{},
22782278
},
22792279
expected: VSASummaryDisplay{
2280-
Signature: "VERIFIED",
2281-
Predicate: "passed (3/3)",
2282-
Policy: "matches (no differences)",
2280+
Signature: "VERIFIED",
2281+
Predicate: "passed (3/3)",
2282+
Policy: "matches (no differences)",
22832283
FallbackReasons: "",
22842284
},
22852285
},
@@ -2296,14 +2296,14 @@ func TestBuildVSASummaryDisplay(t *testing.T) {
22962296
"def67890": {Added: 0, Removed: 1, Changed: 1},
22972297
},
22982298
FallbackReasons: map[string]bool{
2299-
"no_vsa": true,
2299+
"no_vsa": true,
23002300
"expired": true,
23012301
},
23022302
},
23032303
expected: VSASummaryDisplay{
2304-
Signature: "NOT VERIFIED",
2305-
Predicate: "failed (2/2)",
2306-
Policy: "mismatches on 2/2 images (adds=1, removes=3, changes=1)",
2304+
Signature: "NOT VERIFIED",
2305+
Predicate: "failed (2/2)",
2306+
Policy: "mismatches on 2/2 images (adds=1, removes=3, changes=1)",
23072307
FallbackReasons: "expired, no_vsa",
23082308
},
23092309
},
@@ -2323,9 +2323,9 @@ func TestBuildVSASummaryDisplay(t *testing.T) {
23232323
},
23242324
},
23252325
expected: VSASummaryDisplay{
2326-
Signature: "VERIFIED",
2327-
Predicate: "mixed (passed: 2, failed: 1)",
2328-
Policy: "mismatches on 1/3 images (adds=1, removes=0, changes=0)",
2326+
Signature: "VERIFIED",
2327+
Predicate: "mixed (passed: 2, failed: 1)",
2328+
Policy: "mismatches on 1/3 images (adds=1, removes=0, changes=0)",
23292329
FallbackReasons: "policy_mismatch",
23302330
},
23312331
},
@@ -2340,9 +2340,9 @@ func TestBuildVSASummaryDisplay(t *testing.T) {
23402340
FallbackReasons: map[string]bool{},
23412341
},
23422342
expected: VSASummaryDisplay{
2343-
Signature: "VERIFIED",
2344-
Predicate: "(no predicate data)",
2345-
Policy: "(no policy data)",
2343+
Signature: "VERIFIED",
2344+
Predicate: "(no predicate data)",
2345+
Policy: "(no policy data)",
23462346
FallbackReasons: "",
23472347
},
23482348
},
@@ -2368,9 +2368,9 @@ func TestVSASummaryDisplay_String(t *testing.T) {
23682368
{
23692369
name: "all passed, no fallback reasons",
23702370
display: VSASummaryDisplay{
2371-
Signature: "VERIFIED",
2372-
Predicate: "passed (3/3)",
2373-
Policy: "matches (no differences)",
2371+
Signature: "VERIFIED",
2372+
Predicate: "passed (3/3)",
2373+
Policy: "matches (no differences)",
23742374
FallbackReasons: "",
23752375
},
23762376
expected: `VSA Summary
@@ -2382,9 +2382,9 @@ func TestVSASummaryDisplay_String(t *testing.T) {
23822382
{
23832383
name: "all failed, with fallback reasons",
23842384
display: VSASummaryDisplay{
2385-
Signature: "NOT VERIFIED",
2386-
Predicate: "failed (2/2)",
2387-
Policy: "mismatches on 2/2 images (adds=1, removes=3, changes=1)",
2385+
Signature: "NOT VERIFIED",
2386+
Predicate: "failed (2/2)",
2387+
Policy: "mismatches on 2/2 images (adds=1, removes=3, changes=1)",
23882388
FallbackReasons: "expired, no_vsa",
23892389
},
23902390
expected: `VSA Summary
@@ -2397,9 +2397,9 @@ func TestVSASummaryDisplay_String(t *testing.T) {
23972397
{
23982398
name: "mixed results with fallback",
23992399
display: VSASummaryDisplay{
2400-
Signature: "VERIFIED",
2401-
Predicate: "mixed (passed: 2, failed: 1)",
2402-
Policy: "mismatches on 1/3 images (adds=1, removes=0, changes=0)",
2400+
Signature: "VERIFIED",
2401+
Predicate: "mixed (passed: 2, failed: 1)",
2402+
Policy: "mismatches on 1/3 images (adds=1, removes=0, changes=0)",
24032403
FallbackReasons: "policy_mismatch",
24042404
},
24052405
expected: `VSA Summary
@@ -2412,9 +2412,9 @@ func TestVSASummaryDisplay_String(t *testing.T) {
24122412
{
24132413
name: "no predicate or policy data",
24142414
display: VSASummaryDisplay{
2415-
Signature: "VERIFIED",
2416-
Predicate: "(no predicate data)",
2417-
Policy: "(no policy data)",
2415+
Signature: "VERIFIED",
2416+
Predicate: "(no predicate data)",
2417+
Policy: "(no policy data)",
24182418
FallbackReasons: "",
24192419
},
24202420
expected: `VSA Summary
@@ -2471,7 +2471,7 @@ func TestBuildPolicyDiffDisplay(t *testing.T) {
24712471
{
24722472
name: "policy diff with all changes",
24732473
data: AllSectionsData{
2474-
HasPolicyDiff: true,
2474+
HasPolicyDiff: true,
24752475
AffectedImages: []string{"abc12345", "def67890"},
24762476
PolicyDiffCounts: map[string]PolicyDiffCounts{
24772477
"abc12345": {Added: 2, Removed: 1, Changed: 0},
@@ -2488,7 +2488,7 @@ func TestBuildPolicyDiffDisplay(t *testing.T) {
24882488
{
24892489
name: "policy diff with only added",
24902490
data: AllSectionsData{
2491-
HasPolicyDiff: true,
2491+
HasPolicyDiff: true,
24922492
AffectedImages: []string{"abc12345"},
24932493
PolicyDiffCounts: map[string]PolicyDiffCounts{
24942494
"abc12345": {Added: 5, Removed: 0, Changed: 0},
@@ -2504,7 +2504,7 @@ func TestBuildPolicyDiffDisplay(t *testing.T) {
25042504
{
25052505
name: "policy diff with only removed",
25062506
data: AllSectionsData{
2507-
HasPolicyDiff: true,
2507+
HasPolicyDiff: true,
25082508
AffectedImages: []string{"abc12345"},
25092509
PolicyDiffCounts: map[string]PolicyDiffCounts{
25102510
"abc12345": {Added: 0, Removed: 3, Changed: 0},
@@ -2520,7 +2520,7 @@ func TestBuildPolicyDiffDisplay(t *testing.T) {
25202520
{
25212521
name: "policy diff with only changed",
25222522
data: AllSectionsData{
2523-
HasPolicyDiff: true,
2523+
HasPolicyDiff: true,
25242524
AffectedImages: []string{"abc12345"},
25252525
PolicyDiffCounts: map[string]PolicyDiffCounts{
25262526
"abc12345": {Added: 0, Removed: 0, Changed: 4},
@@ -2536,7 +2536,7 @@ func TestBuildPolicyDiffDisplay(t *testing.T) {
25362536
{
25372537
name: "policy diff with no changes",
25382538
data: AllSectionsData{
2539-
HasPolicyDiff: true,
2539+
HasPolicyDiff: true,
25402540
AffectedImages: []string{"abc12345"},
25412541
PolicyDiffCounts: map[string]PolicyDiffCounts{
25422542
"abc12345": {Added: 0, Removed: 0, Changed: 0},
@@ -2661,7 +2661,7 @@ func TestPolicyDiffDisplay_String(t *testing.T) {
26612661
func TestBuildPolicyDiffDisplay_Integration(t *testing.T) {
26622662
// Test end-to-end: build from AllSectionsData and format with String()
26632663
data := AllSectionsData{
2664-
HasPolicyDiff: true,
2664+
HasPolicyDiff: true,
26652665
AffectedImages: []string{"abc12345"},
26662666
PolicyDiffCounts: map[string]PolicyDiffCounts{
26672667
"abc12345": {Added: 2, Removed: 1, Changed: 0},

0 commit comments

Comments
 (0)