File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments