validators

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package validators provides template validation for different scanner types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitleaksValidator

type GitleaksValidator struct{}

GitleaksValidator validates Gitleaks config files (TOML).

func (*GitleaksValidator) CountRules

func (v *GitleaksValidator) CountRules(content []byte) int

CountRules counts the number of rules in the Gitleaks config.

func (*GitleaksValidator) ExtractMetadata

func (v *GitleaksValidator) ExtractMetadata(content []byte) map[string]any

ExtractMetadata extracts metadata from Gitleaks config.

func (*GitleaksValidator) Validate

func (v *GitleaksValidator) Validate(content []byte) *ValidationResult

Validate validates Gitleaks config content.

type NucleiValidator

type NucleiValidator struct{}

NucleiValidator validates Nuclei template files (YAML).

func (*NucleiValidator) CountRules

func (v *NucleiValidator) CountRules(content []byte) int

CountRules returns 1 for Nuclei (each file is one template).

func (*NucleiValidator) ExtractMetadata

func (v *NucleiValidator) ExtractMetadata(content []byte) map[string]any

ExtractMetadata extracts metadata from Nuclei template.

func (*NucleiValidator) Validate

func (v *NucleiValidator) Validate(content []byte) *ValidationResult

Validate validates Nuclei template content.

type SemgrepValidator

type SemgrepValidator struct{}

SemgrepValidator validates Semgrep rule files (YAML).

func (*SemgrepValidator) CountRules

func (v *SemgrepValidator) CountRules(content []byte) int

CountRules counts the number of rules in the Semgrep config.

func (*SemgrepValidator) ExtractMetadata

func (v *SemgrepValidator) ExtractMetadata(content []byte) map[string]any

ExtractMetadata extracts metadata from Semgrep rules.

func (*SemgrepValidator) Validate

func (v *SemgrepValidator) Validate(content []byte) *ValidationResult

Validate validates Semgrep rule content.

type TemplateValidator

type TemplateValidator interface {
	// Validate validates the template content.
	Validate(content []byte) *ValidationResult

	// CountRules counts the number of rules in the template.
	CountRules(content []byte) int

	// ExtractMetadata extracts scanner-specific metadata from the template.
	ExtractMetadata(content []byte) map[string]any
}

TemplateValidator defines the interface for scanner-specific validators.

func GetValidator

func GetValidator(templateType scannertemplate.TemplateType) TemplateValidator

GetValidator returns the appropriate validator for the template type.

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
	Code    string `json:"code"`
}

ValidationError represents a single validation error.

type ValidationResult

type ValidationResult struct {
	Valid     bool              `json:"valid"`
	Errors    []ValidationError `json:"errors,omitempty"`
	RuleCount int               `json:"rule_count"`
	Metadata  map[string]any    `json:"metadata,omitempty"`
}

ValidationResult represents the result of template validation.

func ValidateTemplate

func ValidateTemplate(templateType scannertemplate.TemplateType, content []byte) *ValidationResult

ValidateTemplate validates template content based on its type.

func (*ValidationResult) AddError

func (r *ValidationResult) AddError(field, message, code string)

AddError adds an error to the validation result.

func (*ValidationResult) ErrorMessages

func (r *ValidationResult) ErrorMessages() string

ErrorMessages returns all error messages as a single string.

func (*ValidationResult) HasErrors

func (r *ValidationResult) HasErrors() bool

HasErrors returns true if there are any validation errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL