format

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidConditions = []string{"contains", "not_contains"}

ValidConditions defines the valid conditions for detection criteria

View Source
var ValidDetectionTypes = []string{"string_match", "regex_match", "semantic_match"}

ValidDetectionTypes defines the valid detection types for templates

View Source
var ValidSeverityLevels = []string{"info", "low", "medium", "high", "critical"}

ValidSeverityLevels defines the valid severity levels for templates

Functions

func EnsureDir

func EnsureDir(dir string) error

EnsureDir ensures that a directory exists

func GetModulePath

func GetModulePath(baseDir, moduleType, name, version string) string

GetModulePath returns the full path for a module file

func GetTemplatePath

func GetTemplatePath(baseDir, category, name, version string) string

GetTemplatePath returns the full path for a template file

func ListModules

func ListModules(baseDir string) (map[string][]string, error)

ListModules lists all module files in a directory

func ListTemplates

func ListTemplates(baseDir string) ([]string, error)

ListTemplates lists all template files in a directory

func SanitizeFilename

func SanitizeFilename(name string) string

SanitizeFilename sanitizes a string for use as a filename

Types

type DetectionCriteria

type DetectionCriteria struct {
	Type      string `yaml:"type" json:"type"`
	Match     string `yaml:"match,omitempty" json:"match,omitempty"`
	Pattern   string `yaml:"pattern,omitempty" json:"pattern,omitempty"`
	Criteria  string `yaml:"criteria,omitempty" json:"criteria,omitempty"`
	Condition string `yaml:"condition,omitempty" json:"condition,omitempty"`
}

DetectionCriteria represents the detection criteria for a test

type DetectorConfig

type DetectorConfig struct {
	DetectionType  string                 `yaml:"detection_type" json:"detection_type"`
	DefaultOptions map[string]interface{} `yaml:"default_options,omitempty" json:"default_options,omitempty"`
}

DetectorConfig represents the configuration for a detector module

type Module

type Module struct {
	ID            string                               `yaml:"id" json:"id"`
	Type          ModuleType                           `yaml:"type" json:"type"`
	Info          ModuleInfo                           `yaml:"info" json:"info"`
	Compatibility *compatibility.CompatibilityMetadata `yaml:"compatibility" json:"compatibility"`
	Provider      *ProviderConfig                      `yaml:"provider,omitempty" json:"provider,omitempty"`
	Utility       *UtilityConfig                       `yaml:"utility,omitempty" json:"utility,omitempty"`
	Detector      *DetectorConfig                      `yaml:"detector,omitempty" json:"detector,omitempty"`
}

Module represents a module definition (provider, utility, or detector)

func LoadModuleFromFile

func LoadModuleFromFile(filePath string) (*Module, error)

LoadModuleFromFile loads a module from a YAML file

func NewModule

func NewModule(moduleType ModuleType) *Module

NewModule creates a new module with default values

func (*Module) SaveToFile

func (m *Module) SaveToFile(filePath string) error

SaveToFile saves a module to a YAML file

func (*Module) Validate

func (m *Module) Validate() []string

Validate validates the module structure and content

type ModuleInfo

type ModuleInfo struct {
	Name        string   `yaml:"name" json:"name"`
	Description string   `yaml:"description" json:"description"`
	Version     string   `yaml:"version" json:"version"`
	Author      string   `yaml:"author" json:"author"`
	Tags        []string `yaml:"tags,omitempty" json:"tags,omitempty"`
	References  []string `yaml:"references,omitempty" json:"references,omitempty"`
}

ModuleInfo represents the basic information section of a module

type ModuleType

type ModuleType string

ModuleType represents the type of module

const (
	ProviderModule ModuleType = "provider"
	UtilityModule  ModuleType = "utility"
	DetectorModule ModuleType = "detector"
)

Available module types

func GetModuleType

func GetModuleType(dirPath string) (ModuleType, error)

GetModuleType returns the module type based on the directory

type ProviderConfig

type ProviderConfig struct {
	SupportedModels []string               `yaml:"supported_models" json:"supported_models"`
	Features        []string               `yaml:"features" json:"features"`
	DefaultOptions  map[string]interface{} `yaml:"default_options,omitempty" json:"default_options,omitempty"`
	RateLimits      struct {
		RequestsPerMinute int `yaml:"requests_per_minute,omitempty" json:"requests_per_minute,omitempty"`
		TokensPerMinute   int `yaml:"tokens_per_minute,omitempty" json:"tokens_per_minute,omitempty"`
	} `yaml:"rate_limits,omitempty" json:"rate_limits,omitempty"`
}

ProviderConfig represents the configuration for a provider module

type Template

type Template struct {
	ID            string                               `yaml:"id" json:"id"`
	Info          TemplateInfo                         `yaml:"info" json:"info"`
	Compatibility *compatibility.CompatibilityMetadata `yaml:"compatibility" json:"compatibility"`
	Test          TestDefinition                       `yaml:"test" json:"test"`
	Content       []byte                               `json:"-"` // Raw content for caching
	Variables     map[string]interface{}               `yaml:"variables,omitempty" json:"variables,omitempty"`
	Parent        string                               `yaml:"parent,omitempty" json:"parent,omitempty"`
	Metadata      map[string]interface{}               `yaml:"metadata,omitempty" json:"metadata,omitempty"`
}

Template represents a vulnerability test template

func LoadFromFile

func LoadFromFile(filePath string) (*Template, error)

LoadFromFile loads a template from a YAML file

func NewTemplate

func NewTemplate() *Template

NewTemplate creates a new template with default values

func ParseTemplate

func ParseTemplate(content []byte) (*Template, error)

ParseTemplate parses a template from bytes

func (*Template) Clone

func (t *Template) Clone() *Template

Clone creates a deep copy of the template

func (*Template) GetAuthor

func (t *Template) GetAuthor() string

GetAuthor returns the template author

func (*Template) GetCategory

func (t *Template) GetCategory() string

GetCategory returns the template category

func (*Template) GetDescription

func (t *Template) GetDescription() string

GetDescription returns the template description

func (*Template) GetID

func (t *Template) GetID() string

GetID returns the template ID

func (*Template) GetMetadata

func (t *Template) GetMetadata() map[string]interface{}

GetMetadata returns the template metadata

func (*Template) GetName

func (t *Template) GetName() string

GetName returns the template name

func (*Template) GetReferences

func (t *Template) GetReferences() []string

GetReferences returns the template references

func (*Template) GetSeverity

func (t *Template) GetSeverity() string

GetSeverity returns the template severity

func (*Template) GetTags

func (t *Template) GetTags() []string

GetTags returns the template tags

func (*Template) GetVersion

func (t *Template) GetVersion() string

GetVersion returns the template version

func (*Template) SaveToFile

func (t *Template) SaveToFile(filePath string) error

SaveToFile saves a template to a YAML file

func (*Template) Validate

func (t *Template) Validate() error

Validate validates the template and returns an error if invalid (implements Template interface)

func (*Template) ValidateStructure

func (t *Template) ValidateStructure() []string

ValidateStructure validates the template structure and returns validation issues

func (*Template) Version

func (t *Template) Version() string

Version returns the version from the template info

type TemplateContent

type TemplateContent struct {
	// Sections is a list of template sections
	Sections []TemplateSection
	// Variables is a map of variable names to values
	Variables map[string]interface{}
}

TemplateContent represents the content of a template

func NewTemplateContent

func NewTemplateContent() *TemplateContent

NewTemplateContent creates a new template content

func (*TemplateContent) AddSection

func (c *TemplateContent) AddSection(sectionType, content string)

AddSection adds a section to the template content

func (*TemplateContent) AddVariable

func (c *TemplateContent) AddVariable(name string, value interface{})

AddVariable adds a variable to the template content

func (*TemplateContent) Clone

func (c *TemplateContent) Clone() *TemplateContent

Clone creates a deep copy of the template content

func (*TemplateContent) GetSectionContent

func (c *TemplateContent) GetSectionContent(sectionType string) (string, bool)

GetSectionContent gets the content of the first section of a specific type

func (*TemplateContent) GetSections

func (c *TemplateContent) GetSections(sectionType string) []TemplateSection

GetSections gets all sections of a specific type

func (*TemplateContent) GetVariable

func (c *TemplateContent) GetVariable(name string) (interface{}, bool)

GetVariable gets a variable from the template content

type TemplateInfo

type TemplateInfo struct {
	Name        string   `yaml:"name" json:"name"`
	Description string   `yaml:"description" json:"description"`
	Version     string   `yaml:"version" json:"version"`
	Author      string   `yaml:"author" json:"author"`
	Severity    string   `yaml:"severity" json:"severity"`
	Tags        []string `yaml:"tags,omitempty" json:"tags,omitempty"`
	References  []string `yaml:"references,omitempty" json:"references,omitempty"`
	Compliance  struct {
		OWASP string `yaml:"owasp,omitempty" json:"owasp,omitempty"`
		ISO   string `yaml:"iso,omitempty" json:"iso,omitempty"`
	} `yaml:"compliance,omitempty" json:"compliance,omitempty"`
}

TemplateInfo represents the basic information section of a template

type TemplateSection

type TemplateSection struct {
	// Type is the type of the section
	Type string
	// Content is the content of the section
	Content string
}

TemplateSection represents a section of a template

type TestDefinition

type TestDefinition struct {
	Prompt           string            `yaml:"prompt" json:"prompt"`
	ExpectedBehavior string            `yaml:"expected_behavior,omitempty" json:"expected_behavior,omitempty"`
	Detection        DetectionCriteria `yaml:"detection" json:"detection"`
	Variations       []TestVariation   `yaml:"variations,omitempty" json:"variations,omitempty"`
}

TestDefinition represents the test section of a template

type TestVariation

type TestVariation struct {
	Prompt    string            `yaml:"prompt" json:"prompt"`
	Detection DetectionCriteria `yaml:"detection" json:"detection"`
}

TestVariation represents a variation of a test

type UtilityConfig

type UtilityConfig struct {
	Functions      []string               `yaml:"functions" json:"functions"`
	DefaultOptions map[string]interface{} `yaml:"default_options,omitempty" json:"default_options,omitempty"`
}

UtilityConfig represents the configuration for a utility module

Jump to

Keyboard shortcuts

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