Documentation
¶
Index ¶
- func Engine(ctx context.Context, policyConfig *Params, policies []Policy) error
- func ReportBasic(ctx context.Context, results []PolicyResult) error
- func ReportJSON(ctx context.Context, results []PolicyResult) error
- func ReportTable(ctx context.Context, results []PolicyResult) error
- func ValidatePolicy(p *Policy) error
- type Extractor
- type Params
- type Policy
- type PolicyFile
- type PolicyResult
- type RULE_TYPE
- type Rule
- type RuleResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReportBasic ¶
func ReportBasic(ctx context.Context, results []PolicyResult) error
ReportBasic writes results in a human-friendly basic format.
func ReportJSON ¶
func ReportJSON(ctx context.Context, results []PolicyResult) error
ReportJSON writes results as pretty-printed JSON to stdout.
func ReportTable ¶
func ReportTable(ctx context.Context, results []PolicyResult) error
ReportTable writes results in a per-policy, per-violation detail table format.
func ValidatePolicy ¶
ValidatePolicy performs basic semantic checks on a policy
Types ¶
type Extractor ¶
Extractor provides a simple mapping from canonical field names to component-level or document-level.
func NewExtractor ¶
func (*Extractor) HasField ¶
func (extract *Extractor) HasField(comp sbom.GetComponent, field string) bool
HasField returns true if the given field exists and has at least one non-empty value. Uses the same prefix rules as Values().
func (*Extractor) MapFieldWithFunction ¶
MapFieldWithFunction creates an Extractor for SBOM fields. quick mapping of fields with respective funtions
func (*Extractor) RetrieveValues ¶
func (e *Extractor) RetrieveValues(comp sbom.GetComponent, field string) []string
Values returns a slice of string values for the given field on the provided component. Lookup rules:
- If field starts with "sbom_" → resolve against doc-level getters only.
- Otherwise → resolve against component-level getters only.
Field name is normalized to lowercase.
type Policy ¶
type Policy struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Rules []Rule `yaml:"rules"`
Action string `yaml:"action,omitempty"`
}
Policy represents single policy
func BuildPolicyFromCLI ¶
BuildPolicyFromCLI builds a Policy from CLI flags. where each element is ONE full rule string, e.g. "field=license,values=MIT,Apache-2.0".
func LoadPoliciesFromFile ¶
LoadPoliciesFromFile reads a YAML policy file and unmarshals it into policies.
type PolicyFile ¶
type PolicyFile struct {
SchemaVersion int `yaml:"schemaVersion,omitempty"`
Policy []Policy `yaml:"policy"`
}
PolicyFile represents the top-level YAML structure
type PolicyResult ¶
type PolicyResult struct {
PolicyName string `json:"name,omitempty"`
PolicyType string `json:"type,omitempty"`
PolicyAction string `json:"action,omitempty"`
OverallResult string `json:"overall_result"` // overall: pass|warn|fail
RuleResults []RuleResult `json:"policy_results,omitempty"` // both passes & fails
TotalChecks int `json:"total_checks,omitempty"` // number of total check
TotalRules int `json:"total_rules,omitempty"`
TotalComponents int `json:"total_components,omitempty"` // number of components scanned
ViolationCnt int `json:"violation_count,omitempty"` // number of failed policy_results
}
Result represent the evaluation result of policay against SBOM
func EvaluatePolicyAgainstSBOMs ¶
func EvaluatePolicyAgainstSBOMs(ctx context.Context, policy Policy, doc sbom.Document, fieldExtractor *Extractor) (PolicyResult, error)
EvaluatePolicyAgainstSBOMs evaluates a single policy against a SBOMs.
func NewPolicyResult ¶
func NewPolicyResult(p Policy) *PolicyResult
type Rule ¶
type Rule struct {
Field string `yaml:"field"`
Values []string `yaml:"values,omitempty"`
Patterns []string `yaml:"patterns,omitempty"`
}
Rule represents field/values or field/patterns
type RuleResult ¶
type RuleResult struct {
ComponentID string `json:"component_id,omitempty"` // component unique id (or "<document>")
ComponentName string `json:"component_name,omitempty"` // friendly name
DeclaredField string `json:"declared_field"` // the field evaluated (e.g., license)
DeclaredValues string `json:"declared_values"` // the decalred values
ActualValues []string `json:"actual_values,omitempty"` // actual values seen on SBOM
Result string `json:"result"` // "pass" | "fail"
Reason string `json:"reason,omitempty"` // human-friendly reason for failure
}