Skip to content

Commit 059a49e

Browse files
committed
Add baseline validator
Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
1 parent 27175dc commit 059a49e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

cmd/pkg/baseline/validator.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-FileCopyrightText: Copyright 2025 The OSPS Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package baseline
5+
6+
import (
7+
"fmt"
8+
"log"
9+
"slices"
10+
11+
"github.com/ossf/security-baseline/pkg/types"
12+
)
13+
14+
type Validator struct {
15+
}
16+
17+
// Check verifies the data parsed for consistency and completeness
18+
func Check(b *types.Baseline) error {
19+
var entryIDs []string
20+
var failed bool
21+
for _, category := range b.Categories {
22+
for _, entry := range category.Criteria {
23+
if slices.Contains(entryIDs, entry.ID) {
24+
failed = true
25+
log.Printf("duplicate ID for 'criterion' for %s", entry.ID)
26+
}
27+
if entry.ID == "" {
28+
failed = true
29+
log.Printf("missing ID for 'criterion' %s", entry.ID)
30+
}
31+
if entry.CriterionText == "" {
32+
failed = true
33+
log.Printf("missing 'criterion' text for %s", entry.ID)
34+
}
35+
// For after all fields are populated:
36+
// if entry.Rationale == "" {
37+
// failed = true
38+
// log.Printf("missing 'rationale' for %s", entry.ID)
39+
// }
40+
// if entry.Details == "" {
41+
// failed = true
42+
// log.Printf("missing 'details' for %s", entry.ID)
43+
// }
44+
entryIDs = append(entryIDs, entry.ID)
45+
}
46+
}
47+
if failed {
48+
return fmt.Errorf("error validating baseline")
49+
}
50+
return nil
51+
}

0 commit comments

Comments
 (0)