scan

package
v0.2.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: 11 Imported by: 0

Documentation

Overview

Package scan provides API endpoints for managing red-team scans

Package scan provides API endpoints for managing red-team scans

Package scan provides API endpoints for managing red-team scans

Package scan provides API endpoints for managing red-team scans

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound          = errors.New("resource not found")
	ErrInvalidID         = errors.New("invalid ID")
	ErrInvalidParameters = errors.New("invalid parameters")
	ErrAlreadyExists     = errors.New("resource already exists")
)

Common errors

Functions

This section is empty.

Types

type CreateScanConfigRequest

type CreateScanConfigRequest struct {
	// Name is the name of the scan configuration
	Name string `json:"name" validate:"required"`
	// Description is a description of the scan configuration
	Description string `json:"description"`
	// Target is the target of the scan (e.g., a prompt, system, or model)
	Target string `json:"target" validate:"required"`
	// TargetType is the type of target (e.g., "prompt", "system", "model")
	TargetType string `json:"target_type" validate:"required"`
	// Templates is a list of template IDs to use for the scan
	Templates []string `json:"templates" validate:"required,min=1"`
	// Parameters is a map of parameters for the scan
	Parameters map[string]interface{} `json:"parameters"`
}

CreateScanConfigRequest represents a request to create a scan configuration

type CreateScanRequest

type CreateScanRequest struct {
	// ConfigID is the ID of the scan configuration
	ConfigID string `json:"config_id" validate:"required"`
}

CreateScanRequest represents a request to create a scan

type ErrorResponse

type ErrorResponse struct {
	// Error is the error message
	Error string `json:"error"`
	// Code is the error code
	Code int `json:"code"`
}

ErrorResponse represents an error response

type FilterParams

type FilterParams struct {
	// Status filters results by status
	Status string `json:"status"`
	// Severity filters results by severity
	Severity string `json:"severity"`
	// StartDate filters results by start date
	StartDate string `json:"start_date"`
	// EndDate filters results by end date
	EndDate string `json:"end_date"`
	// Search is a search term to filter results
	Search string `json:"search"`
}

FilterParams represents filter parameters for list endpoints

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler handles HTTP requests for scan management

func NewHandler

func NewHandler(service *Service) *Handler

NewHandler creates a new scan handler

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(mux *http.ServeMux, middleware func(http.Handler) http.Handler)

RegisterRoutes registers the scan API routes with the given router

type ListResponse

type ListResponse struct {
	// Pagination contains pagination information
	Pagination PaginationParams `json:"pagination"`
	// Data contains the response data
	Data interface{} `json:"data"`
}

ListResponse represents a paginated list response

type MemoryStorage

type MemoryStorage struct {
	// contains filtered or unexported fields
}

MemoryStorage implements the Storage interface using in-memory storage This is primarily for testing and development purposes

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new MemoryStorage instance

func (*MemoryStorage) CreateScan

func (s *MemoryStorage) CreateScan(ctx context.Context, scan *Scan) error

CreateScan creates a new scan

func (*MemoryStorage) CreateScanConfig

func (s *MemoryStorage) CreateScanConfig(ctx context.Context, config *ScanConfig) error

CreateScanConfig creates a new scan configuration

func (*MemoryStorage) CreateScanResult

func (s *MemoryStorage) CreateScanResult(ctx context.Context, result *ScanResult) error

CreateScanResult creates a new scan result

func (*MemoryStorage) DeleteScan

func (s *MemoryStorage) DeleteScan(ctx context.Context, id string) error

DeleteScan deletes a scan by ID

func (*MemoryStorage) DeleteScanConfig

func (s *MemoryStorage) DeleteScanConfig(ctx context.Context, id string) error

DeleteScanConfig deletes a scan configuration by ID

func (*MemoryStorage) DeleteScanResult

func (s *MemoryStorage) DeleteScanResult(ctx context.Context, id string) error

DeleteScanResult deletes a scan result by ID

func (*MemoryStorage) GetScan

func (s *MemoryStorage) GetScan(ctx context.Context, id string) (*Scan, error)

GetScan retrieves a scan by ID

func (*MemoryStorage) GetScanConfig

func (s *MemoryStorage) GetScanConfig(ctx context.Context, id string) (*ScanConfig, error)

GetScanConfig retrieves a scan configuration by ID

func (*MemoryStorage) GetScanResult

func (s *MemoryStorage) GetScanResult(ctx context.Context, id string) (*ScanResult, error)

GetScanResult retrieves a scan result by ID

func (*MemoryStorage) ListScanConfigs

func (s *MemoryStorage) ListScanConfigs(ctx context.Context, page, pageSize int, filters FilterParams) ([]*ScanConfig, int, error)

ListScanConfigs lists scan configurations with pagination and filtering

func (*MemoryStorage) ListScanResults

func (s *MemoryStorage) ListScanResults(ctx context.Context, scanID string, page, pageSize int, filters FilterParams) ([]*ScanResult, int, error)

ListScanResults lists scan results for a specific scan with pagination and filtering

func (*MemoryStorage) ListScans

func (s *MemoryStorage) ListScans(ctx context.Context, page, pageSize int, filters FilterParams) ([]*Scan, int, error)

ListScans lists scans with pagination and filtering

func (*MemoryStorage) UpdateScan

func (s *MemoryStorage) UpdateScan(ctx context.Context, scan *Scan) error

UpdateScan updates an existing scan

func (*MemoryStorage) UpdateScanConfig

func (s *MemoryStorage) UpdateScanConfig(ctx context.Context, config *ScanConfig) error

UpdateScanConfig updates an existing scan configuration

func (*MemoryStorage) UpdateScanResult

func (s *MemoryStorage) UpdateScanResult(ctx context.Context, result *ScanResult) error

UpdateScanResult updates an existing scan result

type PaginationParams

type PaginationParams struct {
	// Page is the page number (1-based)
	Page int `json:"page"`
	// PageSize is the number of items per page
	PageSize int `json:"page_size"`
	// TotalItems is the total number of items
	TotalItems int `json:"total_items"`
	// TotalPages is the total number of pages
	TotalPages int `json:"total_pages"`
}

PaginationParams represents pagination parameters for list endpoints

type Scan

type Scan struct {
	// ID is the unique identifier for the scan
	ID string `json:"id"`
	// ConfigID is the ID of the scan configuration
	ConfigID string `json:"config_id"`
	// Status is the status of the scan
	Status ScanStatus `json:"status"`
	// StartTime is the time the scan started
	StartTime time.Time `json:"start_time"`
	// EndTime is the time the scan ended
	EndTime time.Time `json:"end_time,omitempty"`
	// Progress is the progress of the scan (0-100)
	Progress int `json:"progress"`
	// Error is the error message if the scan failed
	Error string `json:"error,omitempty"`
	// Results is the results of the scan
	Results []ScanResult `json:"results,omitempty"`
}

Scan represents a scan execution

type ScanConfig

type ScanConfig struct {
	// ID is the unique identifier for the scan configuration
	ID string `json:"id"`
	// Name is the name of the scan configuration
	Name string `json:"name"`
	// Description is a description of the scan configuration
	Description string `json:"description"`
	// Target is the target of the scan (e.g., a prompt, system, or model)
	Target string `json:"target"`
	// TargetType is the type of target (e.g., "prompt", "system", "model")
	TargetType string `json:"target_type"`
	// Templates is a list of template IDs to use for the scan
	Templates []string `json:"templates"`
	// Parameters is a map of parameters for the scan
	Parameters map[string]interface{} `json:"parameters"`
	// CreatedAt is the time the scan configuration was created
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the scan configuration was last updated
	UpdatedAt time.Time `json:"updated_at"`
	// CreatedBy is the user who created the scan configuration
	CreatedBy string `json:"created_by"`
}

ScanConfig represents the configuration for a scan

type ScanResult

type ScanResult struct {
	// ID is the unique identifier for the scan result
	ID string `json:"id"`
	// ScanID is the ID of the scan
	ScanID string `json:"scan_id"`
	// TemplateID is the ID of the template that generated the result
	TemplateID string `json:"template_id"`
	// Severity is the severity of the finding
	Severity ScanSeverity `json:"severity"`
	// Title is the title of the finding
	Title string `json:"title"`
	// Description is a description of the finding
	Description string `json:"description"`
	// Details contains detailed information about the finding
	Details map[string]interface{} `json:"details"`
	// Timestamp is the time the result was generated
	Timestamp time.Time `json:"timestamp"`
}

ScanResult represents a result from a scan

type ScanSeverity

type ScanSeverity string

ScanSeverity represents the severity level of a scan finding

const (
	// ScanSeverityLow indicates a low severity finding
	ScanSeverityLow ScanSeverity = "low"
	// ScanSeverityMedium indicates a medium severity finding
	ScanSeverityMedium ScanSeverity = "medium"
	// ScanSeverityHigh indicates a high severity finding
	ScanSeverityHigh ScanSeverity = "high"
	// ScanSeverityCritical indicates a critical severity finding
	ScanSeverityCritical ScanSeverity = "critical"
)

type ScanStatus

type ScanStatus string

ScanStatus represents the status of a scan

const (
	// ScanStatusPending indicates the scan is pending execution
	ScanStatusPending ScanStatus = "pending"
	// ScanStatusRunning indicates the scan is currently running
	ScanStatusRunning ScanStatus = "running"
	// ScanStatusCompleted indicates the scan has completed successfully
	ScanStatusCompleted ScanStatus = "completed"
	// ScanStatusFailed indicates the scan has failed
	ScanStatusFailed ScanStatus = "failed"
	// ScanStatusCancelled indicates the scan was cancelled
	ScanStatusCancelled ScanStatus = "cancelled"
)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles the business logic for scan operations

func NewService

func NewService(storage Storage) *Service

NewService creates a new scan service

func (*Service) CancelScan

func (s *Service) CancelScan(ctx context.Context, id string) (*Scan, error)

CancelScan cancels a running scan

func (*Service) CreateScan

func (s *Service) CreateScan(ctx context.Context, req CreateScanRequest) (*Scan, error)

CreateScan creates a new scan execution

func (*Service) CreateScanConfig

func (s *Service) CreateScanConfig(ctx context.Context, req CreateScanConfigRequest, userID string) (*ScanConfig, error)

CreateScanConfig creates a new scan configuration

func (*Service) DeleteScanConfig

func (s *Service) DeleteScanConfig(ctx context.Context, id string) error

DeleteScanConfig deletes a scan configuration by ID

func (*Service) GetScan

func (s *Service) GetScan(ctx context.Context, id string) (*Scan, error)

GetScan retrieves a scan by ID

func (*Service) GetScanConfig

func (s *Service) GetScanConfig(ctx context.Context, id string) (*ScanConfig, error)

GetScanConfig retrieves a scan configuration by ID

func (*Service) GetScanResults

func (s *Service) GetScanResults(ctx context.Context, scanID string, page, pageSize int, filters FilterParams) ([]*ScanResult, *PaginationParams, error)

GetScanResults retrieves the results for a scan with pagination and filtering

func (*Service) ListScanConfigs

func (s *Service) ListScanConfigs(ctx context.Context, page, pageSize int, filters FilterParams) ([]*ScanConfig, *PaginationParams, error)

ListScanConfigs lists scan configurations with pagination and filtering

func (*Service) ListScans

func (s *Service) ListScans(ctx context.Context, page, pageSize int, filters FilterParams) ([]*Scan, *PaginationParams, error)

ListScans lists scans with pagination and filtering

func (*Service) UpdateScanConfig

func (s *Service) UpdateScanConfig(ctx context.Context, id string, req UpdateScanConfigRequest) (*ScanConfig, error)

UpdateScanConfig updates an existing scan configuration

type Storage

type Storage interface {
	// ScanConfig methods
	CreateScanConfig(ctx context.Context, config *ScanConfig) error
	GetScanConfig(ctx context.Context, id string) (*ScanConfig, error)
	UpdateScanConfig(ctx context.Context, config *ScanConfig) error
	DeleteScanConfig(ctx context.Context, id string) error
	ListScanConfigs(ctx context.Context, page, pageSize int, filters FilterParams) ([]*ScanConfig, int, error)

	// Scan methods
	CreateScan(ctx context.Context, scan *Scan) error
	GetScan(ctx context.Context, id string) (*Scan, error)
	UpdateScan(ctx context.Context, scan *Scan) error
	DeleteScan(ctx context.Context, id string) error
	ListScans(ctx context.Context, page, pageSize int, filters FilterParams) ([]*Scan, int, error)

	// ScanResult methods
	CreateScanResult(ctx context.Context, result *ScanResult) error
	GetScanResult(ctx context.Context, id string) (*ScanResult, error)
	UpdateScanResult(ctx context.Context, result *ScanResult) error
	DeleteScanResult(ctx context.Context, id string) error
	ListScanResults(ctx context.Context, scanID string, page, pageSize int, filters FilterParams) ([]*ScanResult, int, error)
}

Storage defines the interface for storing scan data

type UpdateScanConfigRequest

type UpdateScanConfigRequest struct {
	// Name is the name of the scan configuration
	Name string `json:"name"`
	// Description is a description of the scan configuration
	Description string `json:"description"`
	// Target is the target of the scan (e.g., a prompt, system, or model)
	Target string `json:"target"`
	// TargetType is the type of target (e.g., "prompt", "system", "model")
	TargetType string `json:"target_type"`
	// Templates is a list of template IDs to use for the scan
	Templates []string `json:"templates"`
	// Parameters is a map of parameters for the scan
	Parameters map[string]interface{} `json:"parameters"`
}

UpdateScanConfigRequest represents a request to update a scan configuration

Jump to

Keyboard shortcuts

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