Documentation
¶
Index ¶
- type DefaultLoader
- type DefaultValidator
- type DetectionEngine
- type InputValidationRule
- type InputValidator
- type LLMProvider
- type LoaderOptions
- type RateLimiter
- type SchemaValidator
- type Template
- type TemplateCache
- type TemplateExecutor
- type TemplateLoader
- type TemplateLoaderExt
- type TemplateManager
- type TemplateRegistry
- type TemplateRepository
- type TemplateResult
- type TemplateSource
- type TemplateStatus
- type TemplateValidator
- type TemplateValidatorExt
- type ValidationResult
- type ValidationRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultLoader ¶ added in v0.8.0
type DefaultLoader struct {
// contains filtered or unexported fields
}
DefaultLoader provides a default template loader implementation
func NewDefaultLoader ¶ added in v0.8.0
func NewDefaultLoader(validator TemplateValidator, cache TemplateCache) *DefaultLoader
NewDefaultLoader creates a new default loader
func (*DefaultLoader) LoadFromBytes ¶ added in v0.8.0
func (l *DefaultLoader) LoadFromBytes(data []byte) (Template, error)
LoadFromBytes loads a template from bytes
func (*DefaultLoader) LoadFromFile ¶ added in v0.8.0
func (l *DefaultLoader) LoadFromFile(path string) (Template, error)
LoadFromFile loads a template from a file
func (*DefaultLoader) LoadFromReader ¶ added in v0.8.0
func (l *DefaultLoader) LoadFromReader(reader io.Reader) (Template, error)
LoadFromReader loads a template from a reader
func (*DefaultLoader) LoadFromURL ¶ added in v0.8.0
func (l *DefaultLoader) LoadFromURL(url string) (Template, error)
LoadFromURL loads a template from a URL
type DefaultValidator ¶ added in v0.8.0
type DefaultValidator struct {
// contains filtered or unexported fields
}
DefaultValidator provides a default validator implementation
func NewDefaultValidator ¶ added in v0.8.0
func NewDefaultValidator() *DefaultValidator
NewDefaultValidator creates a new default validator
func (*DefaultValidator) AddRule ¶ added in v0.8.0
func (v *DefaultValidator) AddRule(rule ValidationRule)
AddRule adds a validation rule
func (*DefaultValidator) Validate ¶ added in v0.8.0
func (v *DefaultValidator) Validate(template Template) error
Validate validates a template
func (*DefaultValidator) ValidateContent ¶ added in v0.8.0
func (v *DefaultValidator) ValidateContent(content []byte) error
ValidateContent validates template content
func (*DefaultValidator) ValidateSchema ¶ added in v0.8.0
func (v *DefaultValidator) ValidateSchema(template Template, schema interface{}) error
ValidateSchema validates against a schema
type DetectionEngine ¶
type DetectionEngine interface {
// Detect analyzes a template and response to detect vulnerabilities
Detect(ctx context.Context, template Template, response string) (bool, int, map[string]interface{}, error)
// GetName returns the name of the detection engine
GetName() string
// GetVersion returns the version of the detection engine
GetVersion() string
// GetSupportedCategories returns the vulnerability categories this engine can detect
GetSupportedCategories() []string
// Configure configures the detection engine with options
Configure(options map[string]interface{}) error
// GetConfiguration returns the current configuration
GetConfiguration() map[string]interface{}
// IsEnabled returns whether the detection engine is enabled
IsEnabled() bool
// SetEnabled enables or disables the detection engine
SetEnabled(enabled bool)
}
DetectionEngine provides an interface for detecting vulnerabilities in LLM responses
type InputValidationRule ¶
type InputValidationRule interface {
// GetName returns the name of the rule
GetName() string
// GetDescription returns the description of the rule
GetDescription() string
// Validate validates a template against the rule
Validate(ctx context.Context, template interface{}) error
}
InputValidationRule defines a rule for validating template inputs
type InputValidator ¶
type InputValidator interface {
// Validate validates a template input
Validate(ctx context.Context, template interface{}) error
// ValidateContent validates content against validation rules
ValidateContent(ctx context.Context, content string) error
// AddRule adds a validation rule
AddRule(rule InputValidationRule) error
// RemoveRule removes a validation rule by name
RemoveRule(name string) error
// GetRules returns all validation rules
GetRules() []InputValidationRule
// SetStrictMode sets whether validation errors should fail execution
SetStrictMode(strict bool)
// IsStrictMode returns whether strict mode is enabled
IsStrictMode() bool
}
InputValidator validates template inputs before execution
type LLMProvider ¶
type LLMProvider interface {
// SendPrompt sends a prompt to the LLM and returns the response
SendPrompt(ctx context.Context, prompt string, options map[string]interface{}) (string, error)
// GetSupportedModels returns the list of supported models
GetSupportedModels() []string
// GetName returns the name of the provider
GetName() string
// GetID returns a unique identifier for the provider
GetID() string
// IsHealthy checks if the provider is healthy and available
IsHealthy(ctx context.Context) (bool, error)
// GetUsage returns usage statistics for the provider
GetUsage() map[string]interface{}
// SetTimeout sets the request timeout for the provider
SetTimeout(timeout time.Duration)
// GetTimeout gets the current request timeout
GetTimeout() time.Duration
}
LLMProvider provides an interface for interacting with LLM systems
type LoaderOptions ¶ added in v0.8.0
type LoaderOptions struct {
// Source is the source type
Source TemplateSource
// ValidateOnLoad indicates if validation should occur on load
ValidateOnLoad bool
// CacheEnabled indicates if caching is enabled
CacheEnabled bool
}
LoaderOptions represents options for template loading
type RateLimiter ¶
type RateLimiter interface {
// Allow checks if an operation is allowed under the current rate limit
Allow(ctx context.Context, userID string) (bool, error)
// Wait blocks until the operation is allowed under the rate limit
Wait(ctx context.Context, userID string) error
// Reserve reserves the right to perform an operation at the given time
Reserve(ctx context.Context, userID string) (bool, time.Duration, error)
// SetUserLimit sets a custom rate limit for a specific user
SetUserLimit(userID string, qps float64, burst int) error
// GetUserLimit gets the current rate limit for a specific user
GetUserLimit(userID string) (float64, int, error)
// GetStats returns statistics about the rate limiter
GetStats() map[string]interface{}
}
RateLimiter provides rate limiting functionality for template execution
type SchemaValidator ¶
type SchemaValidator interface {
// ValidateSchema validates template data against a schema
ValidateSchema(data interface{}) error
// ValidateTemplate validates a template against a schema
ValidateTemplate(template interface{}) error
}
SchemaValidator validates templates against a schema
type Template ¶ added in v0.8.0
type Template interface {
// GetID returns the template ID
GetID() string
// GetName returns the template name
GetName() string
// GetVersion returns the template version
GetVersion() string
// GetContent returns the template content
GetContent() ([]byte, error)
// Validate validates the template
Validate() error
}
Template represents a template
type TemplateCache ¶
type TemplateCache interface {
// Get gets a template from cache
Get(key string) (Template, bool)
// Set sets a template in cache
Set(key string, template Template, ttl time.Duration)
// Delete deletes a template from cache
Delete(key string)
// Clear clears the cache
Clear()
// Size returns the cache size
Size() int
}
TemplateCache provides template caching
type TemplateExecutor ¶
type TemplateExecutor interface {
// Execute executes a template
Execute(ctx context.Context, template Template, data interface{}) ([]byte, error)
// ExecuteWithOptions executes with options
ExecuteWithOptions(ctx context.Context, template Template, data interface{}, options map[string]interface{}) ([]byte, error)
}
TemplateExecutor executes templates
type TemplateLoader ¶
type TemplateLoader interface {
// LoadFromFile loads a template from a file
LoadFromFile(path string) (Template, error)
// LoadFromReader loads a template from a reader
LoadFromReader(reader io.Reader) (Template, error)
// LoadFromBytes loads a template from bytes
LoadFromBytes(data []byte) (Template, error)
// LoadFromURL loads a template from a URL
LoadFromURL(url string) (Template, error)
}
TemplateLoader loads templates from various sources
type TemplateLoaderExt ¶ added in v0.8.0
type TemplateLoaderExt interface {
TemplateLoader
// LoadWithOptions loads a template with options
LoadWithOptions(source interface{}, options LoaderOptions) (Template, error)
// LoadMultiple loads multiple templates
LoadMultiple(sources []interface{}) ([]Template, error)
// ValidateSource validates a template source
ValidateSource(source interface{}) error
}
TemplateLoaderExt extends the basic loader interface
type TemplateManager ¶ added in v0.8.0
type TemplateManager interface {
// ListTemplates lists all templates
ListTemplates(ctx context.Context) ([]Template, error)
// GetTemplate gets a template by ID
GetTemplate(ctx context.Context, id string) (Template, error)
// CreateTemplate creates a new template
CreateTemplate(ctx context.Context, template Template) error
// UpdateTemplate updates an existing template
UpdateTemplate(ctx context.Context, id string, template Template) error
// DeleteTemplate deletes a template
DeleteTemplate(ctx context.Context, id string) error
// ValidateTemplate validates a template
ValidateTemplate(ctx context.Context, template Template) error
}
TemplateManager manages templates
type TemplateRegistry ¶
type TemplateRegistry interface {
// Register registers a template
Register(template Template) error
// Unregister unregisters a template
Unregister(id string) error
// Get gets a registered template
Get(id string) (Template, bool)
// List lists all registered templates
List() []Template
// Clear clears the registry
Clear()
}
TemplateRegistry provides template registration
type TemplateRepository ¶ added in v0.8.0
type TemplateRepository interface {
// List lists all templates
List(ctx context.Context) ([]Template, error)
// Get gets a template by ID
Get(ctx context.Context, id string) (Template, error)
// Create creates a new template
Create(ctx context.Context, template Template) error
// Update updates an existing template
Update(ctx context.Context, id string, template Template) error
// Delete deletes a template
Delete(ctx context.Context, id string) error
// Exists checks if a template exists
Exists(ctx context.Context, id string) (bool, error)
}
TemplateRepository provides template storage
type TemplateResult ¶
type TemplateResult struct {
// TemplateID is the ID of the template
TemplateID string `json:"template_id"`
// TemplateName is the name of the template
TemplateName string `json:"template_name"`
// Description is the description of the template
Description string `json:"description"`
// Status is the status of the template
Status string `json:"status"`
// StartTime is the time the template execution started
StartTime time.Time `json:"start_time"`
// EndTime is the time the template execution ended
EndTime time.Time `json:"end_time"`
// Duration is the duration of the template execution
Duration time.Duration `json:"duration"`
// Error is any error that occurred during template execution
Error error `json:"error,omitempty"`
// Response is the response from the LLM
Response string `json:"response,omitempty"`
// Detected indicates whether the vulnerability was detected
Detected bool `json:"detected"`
// Score is the score of the template execution (0-100)
Score int `json:"score"`
// Details contains additional details about the template execution
Details map[string]interface{} `json:"details,omitempty"`
// Tags contains tags associated with the template
Tags []string `json:"tags,omitempty"`
// Metadata contains additional metadata about the template
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Input contains the input to the template
Input string `json:"input,omitempty"`
// Output contains the expected output from the template
Output string `json:"output,omitempty"`
}
TemplateResult represents the result of a template execution
type TemplateSource ¶
type TemplateSource string
TemplateSource represents a source for templates
const ( // FileSource indicates the template is from a file FileSource TemplateSource = "file" // DirectorySource indicates the template is from a directory DirectorySource TemplateSource = "directory" // GitHubSource indicates the template is from GitHub GitHubSource TemplateSource = "github" // GitLabSource indicates the template is from GitLab GitLabSource TemplateSource = "gitlab" // HTTPSource indicates the template is from HTTP HTTPSource TemplateSource = "http" // DatabaseSource indicates the template is from a database DatabaseSource TemplateSource = "database" )
Additional TemplateSource constants for management layer
const ( // SourceFile indicates the template is from a file SourceFile TemplateSource = "file" // SourceURL indicates the template is from a URL SourceURL TemplateSource = "url" // SourceBytes indicates the template is from bytes SourceBytes TemplateSource = "bytes" // SourceReader indicates the template is from a reader SourceReader TemplateSource = "reader" )
type TemplateStatus ¶
type TemplateStatus string
TemplateStatus represents the status of a template
const ( // StatusLoaded indicates the template has been loaded StatusLoaded TemplateStatus = "loaded" // StatusValidated indicates the template has been validated StatusValidated TemplateStatus = "validated" // StatusExecuting indicates the template is being executed StatusExecuting TemplateStatus = "executing" // StatusCompleted indicates the template execution has completed StatusCompleted TemplateStatus = "completed" // StatusFailed indicates the template execution has failed StatusFailed TemplateStatus = "failed" )
type TemplateValidator ¶ added in v0.8.0
type TemplateValidator interface {
// Validate validates a template
Validate(template Template) error
// ValidateContent validates template content
ValidateContent(content []byte) error
// ValidateSchema validates against a schema
ValidateSchema(template Template, schema interface{}) error
}
TemplateValidator validates templates
type TemplateValidatorExt ¶ added in v0.8.0
type TemplateValidatorExt interface {
TemplateValidator
// ValidateWithResult validates and returns detailed result
ValidateWithResult(template Template) ValidationResult
// ValidateContentWithResult validates content and returns detailed result
ValidateContentWithResult(content []byte) ValidationResult
// GetValidationRules returns the validation rules
GetValidationRules() []ValidationRule
}
TemplateValidatorExt extends the basic validator interface
type ValidationResult ¶ added in v0.8.0
type ValidationResult struct {
// Valid indicates if validation passed
Valid bool
// Errors contains validation errors
Errors []string
// Warnings contains validation warnings
Warnings []string
}
ValidationResult represents the result of validation
type ValidationRule ¶ added in v0.8.0
type ValidationRule struct {
// Name is the rule name
Name string
// Description is the rule description
Description string
// Severity is the rule severity
Severity string
// Validate is the validation function
Validate func(template Template) error
}
ValidationRule represents a validation rule