web

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Overview

Package web implements the REST API, WebSocket hub, and embedded-frontend HTTP server.

Index

Constants

View Source
const (
	ScenarioTypeStandard = "standard"
	ScenarioTypeExplore  = "explore"
	ScenarioTypeCollect  = "collect"
)

Scenario type constants.

View Source
const AuthTypeWIF = "workload_identity_federation"

AuthTypeWIF is the auth_type value for Workload Identity Federation connectors.

Variables

This section is empty.

Functions

func DeleteRunLog

func DeleteRunLog(dataDir, runID string)

DeleteRunLog removes a run's JSONL log file from disk.

func ServeWS

func ServeWS(hub *Hub, w http.ResponseWriter, r *http.Request)

ServeWS upgrades an HTTP connection to a WebSocket and registers the client.

func SweepRunLogs added in v0.2.0

func SweepRunLogs(dataDir string, enabled bool, days int)

SweepRunLogs deletes run-log JSONL files in <dataDir>/run-logs whose last modification time is older than days. It is a no-op when enabled is false. Deleting a log file does not touch the corresponding runs row — only the verbose log expires. Best-effort: per-file failures are logged, not fatal.

func SweepRuns added in v0.4.0

func SweepRuns(ctx context.Context, runStore db.RunStore, dataDir string, enabled bool, days int)

SweepRuns deletes whole runs (row + scenario_results + JSONL log + collected .ndjson artifacts) whose created_at is older than days. It is a no-op when enabled is false. Runs still in the "running" status are excluded by ListExpired, so an actively-writing run is never purged. A per-run delete failure is logged and the sweep continues with the remaining runs.

Types

type AzureConnectorConfig

type AzureConnectorConfig struct {
	AuthType       string `json:"auth_type"`            // "workload_identity_federation" or "" (legacy service principal)
	TenantID       string `json:"tenant_id"`            // Azure AD tenant ID
	SubscriptionID string `json:"subscription_id"`      // Azure subscription ID
	ClientID       string `json:"client_id"`            // Azure AD application (client) ID
	TokenFile      string `json:"token_file,omitempty"` // OIDC token file path (WIF) — defaults to EKS path
}

AzureConnectorConfig is the structure stored in Connector.Config JSONB for azure type.

type Client

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

Client represents a single WebSocket connection.

type ConnectorHandlers

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

ConnectorHandlers provides REST handlers for connector management.

func NewConnectorHandlers

func NewConnectorHandlers(connectorStore db.ConnectorStore, secretStore db.SecretStore, assessmentStore db.AssessmentStore, runStore db.RunStore, credResolver *credentials.Resolver) *ConnectorHandlers

NewConnectorHandlers creates a new ConnectorHandlers instance.

func (*ConnectorHandlers) HandleCreateConnector

func (h *ConnectorHandlers) HandleCreateConnector(w http.ResponseWriter, r *http.Request)

HandleCreateConnector handles POST /api/connectors

func (*ConnectorHandlers) HandleDeleteConnector

func (h *ConnectorHandlers) HandleDeleteConnector(w http.ResponseWriter, r *http.Request)

HandleDeleteConnector handles DELETE /api/connectors/{id}

func (*ConnectorHandlers) HandleGetConnector

func (h *ConnectorHandlers) HandleGetConnector(w http.ResponseWriter, r *http.Request)

HandleGetConnector handles GET /api/connectors/{id}

func (*ConnectorHandlers) HandleGetElasticRule

func (h *ConnectorHandlers) HandleGetElasticRule(w http.ResponseWriter, r *http.Request)

HandleGetElasticRule handles GET /api/connectors/{id}/elastic/rules/{ruleId}

func (*ConnectorHandlers) HandleListConnectors

func (h *ConnectorHandlers) HandleListConnectors(w http.ResponseWriter, r *http.Request)

HandleListConnectors handles GET /api/connectors

func (*ConnectorHandlers) HandleListElasticRules

func (h *ConnectorHandlers) HandleListElasticRules(w http.ResponseWriter, r *http.Request)

HandleListElasticRules handles GET /api/connectors/{id}/elastic/rules

func (*ConnectorHandlers) HandleListElasticRulesAuto

func (h *ConnectorHandlers) HandleListElasticRulesAuto(w http.ResponseWriter, r *http.Request)

HandleListElasticRulesAuto handles GET /api/elastic/rules Auto-detects the first enabled Elastic connector and returns its enabled rules.

func (*ConnectorHandlers) HandleRuleCoverage

func (h *ConnectorHandlers) HandleRuleCoverage(w http.ResponseWriter, r *http.Request)

HandleRuleCoverage handles GET /api/rules/coverage Returns coverage data showing which Elastic rules are covered by saved scenarios.

func (*ConnectorHandlers) HandleTestConnector

func (h *ConnectorHandlers) HandleTestConnector(w http.ResponseWriter, r *http.Request)

HandleTestConnector handles POST /api/connectors/test Stateless connection test — validates config + secret group without persisting.

func (*ConnectorHandlers) HandleUpdateConnector

func (h *ConnectorHandlers) HandleUpdateConnector(w http.ResponseWriter, r *http.Request)

HandleUpdateConnector handles PUT /api/connectors/{id}

type CoverageLastResult

type CoverageLastResult struct {
	Passed    bool      `json:"passed"`
	RunID     string    `json:"runId"`
	Timestamp time.Time `json:"timestamp"`
}

CoverageLastResult holds the most recent test result for a rule.

type CoverageResponse

type CoverageResponse struct {
	Summary CoverageSummary     `json:"summary"`
	Rules   []RuleCoverageEntry `json:"rules"`
}

CoverageResponse is the top-level response for the coverage endpoint.

type CoverageScenario

type CoverageScenario struct {
	ScenarioID   string `json:"scenarioId"`
	ScenarioName string `json:"scenarioName"`
	SimulationID string `json:"simulationId,omitempty"`
	PackName     string `json:"packName,omitempty"`
}

CoverageScenario links a scenario to a rule it covers.

type CoverageSummary

type CoverageSummary struct {
	TotalRules      int     `json:"totalRules"`
	CoveredRules    int     `json:"coveredRules"`
	CoveragePercent float64 `json:"coveragePercent"`
}

CoverageSummary contains aggregate coverage statistics.

type CreateConnectorRequest

type CreateConnectorRequest struct {
	Name          string         `json:"name"`
	Type          string         `json:"type"`
	Description   string         `json:"description"`
	SecretGroupID string         `json:"secretGroupId,omitempty"`
	Config        map[string]any `json:"config"`
	IsDefault     bool           `json:"isDefault,omitempty"`
}

type CreateScheduleRequest

type CreateScheduleRequest struct {
	AssessmentID   string `json:"assessmentId"`
	CronExpression string `json:"cronExpression"`
	Enabled        bool   `json:"enabled"`
	Parallelism    int    `json:"parallelism,omitempty"`
}

type CreateSecretRequest

type CreateSecretRequest struct {
	Name        string               `json:"name"`
	Description string               `json:"description"`
	Entries     []SecretEntryRequest `json:"entries"`
}

type ElasticConnectorConfig

type ElasticConnectorConfig struct {
	KibanaURL        string `json:"kibana_url"`
	CloudID          string `json:"cloud_id,omitempty"`
	ElasticsearchURL string `json:"elasticsearch_url,omitempty"`
	ExportEnabled    bool   `json:"export_enabled,omitempty"`
	ExportDatastream string `json:"export_datastream,omitempty"`
}

ElasticConnectorConfig is the structure stored in Connector.Config JSONB for elastic type.

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type GCPConnectorConfig

type GCPConnectorConfig struct {
	AuthType            string `json:"auth_type"`                       // "workload_identity_federation" or "" (legacy service account)
	ProjectID           string `json:"project_id,omitempty"`            // GCP project ID (e.g. "my-project") — injected as GOOGLE_CLOUD_PROJECT
	ProjectNumber       string `json:"project_number,omitempty"`        // GCP project number (WIF)
	PoolID              string `json:"pool_id,omitempty"`               // Workload Identity Pool ID (WIF)
	ProviderID          string `json:"provider_id,omitempty"`           // Workload Identity Provider ID (WIF)
	ServiceAccountEmail string `json:"service_account_email,omitempty"` // Target service account (WIF)
	CredentialsFile     string `json:"credentials_file,omitempty"`      // Legacy: path to credentials file
}

GCPConnectorConfig is the structure stored in Connector.Config JSONB for gcp type.

type Handlers

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

Handlers provides REST handlers for scenarios, runs, config, and version.

func NewHandlers

func NewHandlers(ss *ScenarioService, assessmentStore db.AssessmentStore, runStore db.RunStore, configStore db.ConfigStore, scheduler *Scheduler, dataDir string) *Handlers

NewHandlers creates a new Handlers instance.

func (*Handlers) HandleDeleteAssessment added in v0.4.0

func (h *Handlers) HandleDeleteAssessment(w http.ResponseWriter, r *http.Request)

HandleDeleteAssessment handles DELETE /api/assessments/{id}

func (*Handlers) HandleDeleteRun

func (h *Handlers) HandleDeleteRun(w http.ResponseWriter, r *http.Request)

HandleDeleteRun handles DELETE /api/runs/{runId}

func (*Handlers) HandleDownloadCollectedLogs

func (h *Handlers) HandleDownloadCollectedLogs(w http.ResponseWriter, r *http.Request)

HandleDownloadCollectedLogs handles GET /api/scenario-results/{id}/collected-logs

func (*Handlers) HandleGetAssessment added in v0.4.0

func (h *Handlers) HandleGetAssessment(w http.ResponseWriter, r *http.Request)

HandleGetAssessment handles GET /api/assessments/{id}

func (*Handlers) HandleGetAssessmentByName added in v0.4.0

func (h *Handlers) HandleGetAssessmentByName(w http.ResponseWriter, r *http.Request)

HandleGetAssessmentByName handles GET /api/assessments/by-name/{name}. The returned JSON includes the raw yaml field.

func (*Handlers) HandleGetConfig

func (h *Handlers) HandleGetConfig(w http.ResponseWriter, r *http.Request)

HandleGetConfig handles GET /api/config

func (*Handlers) HandleGetRun

func (h *Handlers) HandleGetRun(w http.ResponseWriter, r *http.Request)

HandleGetRun handles GET /api/runs/{runId}

func (*Handlers) HandleGetRunLogs

func (h *Handlers) HandleGetRunLogs(w http.ResponseWriter, r *http.Request)

HandleGetRunLogs handles GET /api/runs/{runId}/logs

func (*Handlers) HandleLint

func (h *Handlers) HandleLint(w http.ResponseWriter, r *http.Request)

HandleLint handles POST /api/assessments/lint

func (*Handlers) HandleListAssessmentRuns added in v0.4.0

func (h *Handlers) HandleListAssessmentRuns(w http.ResponseWriter, r *http.Request)

HandleListAssessmentRuns handles GET /api/assessments/{id}/runs — the runs of a single assessment, most recent first. Read-only; runs are created at POST /api/runs.

func (*Handlers) HandleListAssessments added in v0.4.0

func (h *Handlers) HandleListAssessments(w http.ResponseWriter, r *http.Request)

HandleListAssessments handles GET /api/assessments. Pagination: page (default 1), per_page (default 50, clamped to [1, 100]). Filters: name (ILIKE %name% on assessment name), type (repeatable — e.g. ?type=standard&type=explore), since (Go duration like "24h" — returns assessments updated in that window).

func (*Handlers) HandleListRuns

func (h *Handlers) HandleListRuns(w http.ResponseWriter, r *http.Request)

HandleListRuns handles GET /api/runs. Pagination: page (default 1), per_page (default 50, clamped to [1, 100]). Filters: name (ILIKE %name% on saved scenario name), type (repeatable — e.g. ?type=standard&type=explore), since (Go duration like "24h" — returns runs created in that window).

func (*Handlers) HandleRun

func (h *Handlers) HandleRun(w http.ResponseWriter, r *http.Request)

HandleRun handles POST /api/runs. It starts a run of the saved assessment referenced by {assessmentId} and returns the new runId.

func (*Handlers) HandleSaveAssessment added in v0.4.0

func (h *Handlers) HandleSaveAssessment(w http.ResponseWriter, r *http.Request)

HandleSaveAssessment handles POST /api/assessments. A duplicate name returns 409.

func (*Handlers) HandleUpdateAssessment added in v0.4.0

func (h *Handlers) HandleUpdateAssessment(w http.ResponseWriter, r *http.Request)

HandleUpdateAssessment handles PUT /api/assessments/{id}

func (*Handlers) HandleUpdateConfig

func (h *Handlers) HandleUpdateConfig(w http.ResponseWriter, r *http.Request)

HandleUpdateConfig handles PUT /api/config

func (*Handlers) HandleVersion

func (h *Handlers) HandleVersion(w http.ResponseWriter, r *http.Request)

HandleVersion handles GET /api/version

type Hub

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

Hub maintains active WebSocket clients and broadcasts messages.

func NewHub

func NewHub() *Hub

NewHub creates a new Hub.

func (*Hub) BroadcastToRun

func (h *Hub) BroadcastToRun(runID string, msg WSMessage)

BroadcastToRun sends a message to all clients subscribed to a specific run.

func (*Hub) Run

func (h *Hub) Run()

Run processes register/unregister/broadcast events.

type InstallPackRequest

type InstallPackRequest struct {
	// Name is ignored: a pack's identity is derived from its manifest at
	// install time. It is retained only for backward compatibility with older
	// clients that still send it.
	Name       string         `json:"name,omitempty"`
	Type       string         `json:"type"`
	Source     string         `json:"source"`
	Version    string         `json:"version,omitempty"`
	Parameters map[string]any `json:"parameters,omitempty"`
}

type KubernetesConnectorConfig

type KubernetesConnectorConfig struct {
	ClusterName    string `json:"cluster_name"`
	Region         string `json:"region"`
	CloudConnector string `json:"cloud_connector"`          // name of AWS/GCP/Azure connector
	ResourceGroup  string `json:"resource_group,omitempty"` // AKS only
	Project        string `json:"project,omitempty"`        // GKE only (falls back to GCP connector's project_id)
}

KubernetesConnectorConfig is the structure stored in Connector.Config JSONB for kubernetes type. The cloud provider (EKS/GKE/AKS) is auto-detected from the referenced cloud connector type.

type LintRequest

type LintRequest struct {
	YAML string `json:"yaml"`
}

type LintResponse

type LintResponse struct {
	Valid     bool             `json:"valid"`
	Scenarios []LintedScenario `json:"scenarios,omitempty"`
	Error     string           `json:"error,omitempty"`
}

type LintedScenario

type LintedScenario struct {
	Name         string `json:"name"`
	ExecutorType string `json:"executorType"`
	ExecutorName string `json:"executorName"`
	Expectations int    `json:"expectations"`
}

type PackHandlers

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

PackHandlers provides REST handlers for pack management.

func NewPackHandlers

func NewPackHandlers(packStore db.PackStore, dataDir string) *PackHandlers

NewPackHandlers creates a new PackHandlers instance.

func (*PackHandlers) HandleDeletePack

func (h *PackHandlers) HandleDeletePack(w http.ResponseWriter, r *http.Request)

HandleDeletePack handles DELETE /api/packs/{name}

func (*PackHandlers) HandleGetManifest

func (h *PackHandlers) HandleGetManifest(w http.ResponseWriter, r *http.Request)

HandleGetManifest handles GET /api/packs/{name}/manifest

func (*PackHandlers) HandleGetPackParameters

func (h *PackHandlers) HandleGetPackParameters(w http.ResponseWriter, r *http.Request)

HandleGetPackParameters handles GET /api/packs/{name}/parameters

func (*PackHandlers) HandleInstallPack

func (h *PackHandlers) HandleInstallPack(w http.ResponseWriter, r *http.Request)

HandleInstallPack handles POST /api/packs/install.

Install is an eager operation: the pack binary is made available (downloaded and checksum-verified for remote, verified on disk for local), its manifest command is run to derive the pack's identity, and only then is a row persisted. Any failure (bad repo, missing asset, checksum mismatch, manifest error, non-existent path) returns an error and creates no DB record. The request's `name` is ignored — the manifest is the source of truth.

func (*PackHandlers) HandleListPacks

func (h *PackHandlers) HandleListPacks(w http.ResponseWriter, r *http.Request)

HandleListPacks handles GET /api/packs

func (*PackHandlers) HandleUpdatePackParameters

func (h *PackHandlers) HandleUpdatePackParameters(w http.ResponseWriter, r *http.Request)

HandleUpdatePackParameters handles PUT /api/packs/{name}/parameters. The request body is strict-validated against the pack's declared params_schema (fetched from the manifest). Declared keys must pass type, enum, and required-key checks; unknown keys are kept and surfaced in the response so the UI can render a soft warning. If the manifest fetch fails or the schema is empty, the handler falls back to permissive storage (today's behavior).

func (*PackHandlers) HandleUploadPack

func (h *PackHandlers) HandleUploadPack(w http.ResponseWriter, r *http.Request)

HandleUploadPack handles POST /api/packs/upload.

The uploaded binary is written to a staging location, its manifest command is run to derive the pack's identity, then it is relocated to <DataDir>/packs/<name>/upload/<name>. The request's `name` form field is ignored. A manifest failure aborts the install with no DB record.

type ResultExporter

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

ResultExporter pushes scenario results to external backends. Dispatch is keyed on connector type — today only "elastic" is supported, but adding a new case (splunk, datadog, …) is mechanical because the call site already has a single-method API.

func NewResultExporter

func NewResultExporter(connectorStore db.ConnectorStore, creds *credentials.Resolver) *ResultExporter

NewResultExporter constructs a ResultExporter.

func (*ResultExporter) Export

func (e *ResultExporter) Export(ctx context.Context, runID uuid.UUID, scenarioResults []runner.ScenarioResult)

Export iterates enabled connectors and dispatches to the matching backend.

type RuleCoverageEntry

type RuleCoverageEntry struct {
	RuleID     string              `json:"ruleId"`
	Name       string              `json:"name"`
	Severity   string              `json:"severity"`
	RiskScore  int                 `json:"riskScore"`
	Tags       []string            `json:"tags"`
	Covered    bool                `json:"covered"`
	Scenarios  []CoverageScenario  `json:"scenarios"`
	LastResult *CoverageLastResult `json:"lastResult,omitempty"`
}

RuleCoverageEntry represents a single Elastic rule and its coverage status.

type RunLogEntry

type RunLogEntry struct {
	Timestamp string         `json:"ts"`
	Level     string         `json:"level"`
	Message   string         `json:"msg"`
	Fields    map[string]any `json:"fields,omitempty"`
}

RunLogEntry is a single structured log entry written to the per-run JSONL file.

func ReadRunLog

func ReadRunLog(dataDir, runID string) ([]RunLogEntry, error)

ReadRunLog reads a run's JSONL log file and returns the entries.

type RunLogHook

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

RunLogHook is a logrus Hook that routes entries to per-run log files based on the "run_id" field in the log entry.

func NewRunLogHook

func NewRunLogHook(registry *RunLogRegistry, hub *Hub) *RunLogHook

NewRunLogHook creates a new logrus Hook backed by a RunLogRegistry. If hub is provided, log entries are also broadcast via WebSocket.

func (*RunLogHook) Fire

func (h *RunLogHook) Fire(entry *logrus.Entry) error

Fire is called by logrus when a log entry is fired.

func (*RunLogHook) Levels

func (h *RunLogHook) Levels() []logrus.Level

Levels returns all log levels this hook fires for.

type RunLogRegistry

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

RunLogRegistry is a global thread-safe registry mapping runID → RunLogWriter. The RunLogHook uses this to route log entries to the correct per-run file.

func NewRunLogRegistry

func NewRunLogRegistry() *RunLogRegistry

NewRunLogRegistry creates a new empty registry.

func (*RunLogRegistry) Register

func (r *RunLogRegistry) Register(runID string, w *RunLogWriter)

Register adds a writer for the given runID.

func (*RunLogRegistry) Unregister

func (r *RunLogRegistry) Unregister(runID string)

Unregister removes and closes the writer for the given runID.

type RunLogWriter

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

RunLogWriter writes structured log entries to a per-run JSONL file.

func NewRunLogWriter

func NewRunLogWriter(dataDir, runID string) (*RunLogWriter, error)

NewRunLogWriter creates a new RunLogWriter that writes to <dataDir>/run-logs/{runID}.jsonl.

func (*RunLogWriter) Close

func (w *RunLogWriter) Close() error

Close closes the underlying file.

func (*RunLogWriter) Write

func (w *RunLogWriter) Write(entry RunLogEntry)

Write appends a structured log entry to the JSONL file.

type RunOptions

type RunOptions struct {
	Parallelism   int
	ScheduleID    *uuid.UUID
	ScheduleName  *string
	CreatedBy     string
	ExploreMode   bool
	CleanupAlerts bool
	Timeout       time.Duration // global timeout override; 0 means use per-scenario YAML timeout
}

RunOptions contains optional parameters for running scenarios.

type RunRequest

type RunRequest struct {
	AssessmentID  string `json:"assessmentId"`
	Parallelism   int    `json:"parallelism,omitempty"`
	ExploreMode   bool   `json:"exploreMode,omitempty"`
	CleanupAlerts bool   `json:"cleanupAlerts,omitempty"`
	Timeout       string `json:"timeout,omitempty"`
}

type RunResponse

type RunResponse struct {
	RunID string `json:"runId"`
}

type SSHConnectorConfig

type SSHConnectorConfig struct {
	Host     string `json:"host"`
	Username string `json:"username"`
	Port     int    `json:"port,omitempty"` // default 22 if omitted
}

SSHConnectorConfig is the JSON payload stored in connectors.config for type="ssh". The private key lives in the linked secret group as SR_SSH_KEY.

func (SSHConnectorConfig) Validate

func (c SSHConnectorConfig) Validate() error

Validate returns an error if the SSH connector config is missing required fields.

type SaveAssessmentRequest added in v0.4.0

type SaveAssessmentRequest struct {
	Name string `json:"name"`
	Type string `json:"type,omitempty"`
	YAML string `json:"yaml"`
}

type ScenarioService

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

ScenarioService handles scenario parsing, execution, and result persistence.

func NewScenarioService

func NewScenarioService(runStore db.RunStore, assessmentStore db.AssessmentStore, packStore db.PackStore, configStore db.ConfigStore, creds *credentials.Resolver, exporter *ResultExporter, hub *Hub, runLogRegistry *RunLogRegistry, dataDir string) *ScenarioService

NewScenarioService creates a new ScenarioService.

func (*ScenarioService) Lint

func (s *ScenarioService) Lint(yamlContent []byte) (*LintResponse, error)

Lint parses YAML and returns a summary without executing.

func (*ScenarioService) Run

func (s *ScenarioService) Run(ctx context.Context, assessmentID uuid.UUID, opts *RunOptions) (string, error)

Run starts async execution of a saved assessment. Returns the runId immediately. It fetches the assessment YAML using the provided assessmentID.

type ScheduleHandlers

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

ScheduleHandlers provides REST handlers for schedule management.

func NewScheduleHandlers

func NewScheduleHandlers(scheduleStore db.ScheduleStore, assessmentStore db.AssessmentStore, scheduler *Scheduler) *ScheduleHandlers

NewScheduleHandlers creates a new ScheduleHandlers instance.

func (*ScheduleHandlers) HandleCreateSchedule

func (h *ScheduleHandlers) HandleCreateSchedule(w http.ResponseWriter, r *http.Request)

HandleCreateSchedule handles POST /api/schedules

func (*ScheduleHandlers) HandleDeleteSchedule

func (h *ScheduleHandlers) HandleDeleteSchedule(w http.ResponseWriter, r *http.Request)

HandleDeleteSchedule handles DELETE /api/schedules/{id}

func (*ScheduleHandlers) HandleGetSchedule

func (h *ScheduleHandlers) HandleGetSchedule(w http.ResponseWriter, r *http.Request)

HandleGetSchedule handles GET /api/schedules/{id}

func (*ScheduleHandlers) HandleGetScheduleByAssessment added in v0.4.0

func (h *ScheduleHandlers) HandleGetScheduleByAssessment(w http.ResponseWriter, r *http.Request)

HandleGetScheduleByAssessment handles GET /api/assessments/{id}/schedule

func (*ScheduleHandlers) HandleListSchedules

func (h *ScheduleHandlers) HandleListSchedules(w http.ResponseWriter, r *http.Request)

HandleListSchedules handles GET /api/schedules

func (*ScheduleHandlers) HandleUpdateSchedule

func (h *ScheduleHandlers) HandleUpdateSchedule(w http.ResponseWriter, r *http.Request)

HandleUpdateSchedule handles PUT /api/schedules/{id}

type Scheduler

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

Scheduler manages cron-based scenario execution.

func NewScheduler

func NewScheduler(scheduleStore db.ScheduleStore, assessmentStore db.AssessmentStore, scenarioService *ScenarioService) *Scheduler

NewScheduler creates a new Scheduler.

func (*Scheduler) Reload

func (s *Scheduler) Reload()

Reload clears all cron jobs and reloads from database.

func (*Scheduler) Start

func (s *Scheduler) Start() error

Start loads all enabled schedules and starts the cron engine.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop gracefully shuts down the scheduler.

type SecretEntryRequest

type SecretEntryRequest struct {
	Key   string  `json:"key"`
	Value *string `json:"value"` // nil = keep existing
}

Secret entry in a create/update request. Value is plaintext on write; null means keep existing encrypted value on update.

type SecretGroupResponse

type SecretGroupResponse struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Keys        []string `json:"keys"`
	CreatedBy   string   `json:"createdBy"`
	UpdatedBy   string   `json:"updatedBy"`
	CreatedAt   string   `json:"createdAt"`
	UpdatedAt   string   `json:"updatedAt"`
}

SecretGroupResponse is returned by list/get — values are stripped, only keys returned.

type SecretHandlers

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

SecretHandlers provides REST handlers for secret management.

func NewSecretHandlers

func NewSecretHandlers(secretStore db.SecretStore, encryptor *crypto.Encryptor) *SecretHandlers

NewSecretHandlers creates a new SecretHandlers instance.

func (*SecretHandlers) HandleDeleteSecret

func (h *SecretHandlers) HandleDeleteSecret(w http.ResponseWriter, r *http.Request)

HandleDeleteSecret handles DELETE /api/secrets/{id}

func (*SecretHandlers) HandleGetSecret

func (h *SecretHandlers) HandleGetSecret(w http.ResponseWriter, r *http.Request)

HandleGetSecret handles GET /api/secrets/{id}

func (*SecretHandlers) HandleListSecrets

func (h *SecretHandlers) HandleListSecrets(w http.ResponseWriter, r *http.Request)

HandleListSecrets handles GET /api/secrets

func (*SecretHandlers) HandleSaveSecret

func (h *SecretHandlers) HandleSaveSecret(w http.ResponseWriter, r *http.Request)

HandleSaveSecret handles POST /api/secrets

func (*SecretHandlers) HandleUpdateSecret

func (h *SecretHandlers) HandleUpdateSecret(w http.ResponseWriter, r *http.Request)

HandleUpdateSecret handles PUT /api/secrets/{id}

type Server

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

Server is the HTTP server for the simrun web UI.

func NewServer

func NewServer(handlers *Handlers, packHandlers *PackHandlers, secretHandlers *SecretHandlers, scheduleHandlers *ScheduleHandlers, connectorHandlers *ConnectorHandlers, authHandlers *auth.Handlers, hub *Hub, cfg *ServerConfig, sessionStore db.SessionStore) *Server

NewServer creates a new Server with all routes configured.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the HTTP server.

func (*Server) Router

func (s *Server) Router() http.Handler

Router returns the underlying router. Tests use this to wire the server into an httptest.Server without binding a real port.

type ServerConfig

type ServerConfig struct {
	Port           string
	DevMode        bool   // SR_WEB_DEV=1 enables dev proxy to :5173
	DevFrontendURL string // Defaults to http://localhost:5173
}

ServerConfig holds server configuration.

type TestConnectorRequest

type TestConnectorRequest struct {
	Type          string         `json:"type"`
	SecretGroupID string         `json:"secretGroupId"`
	Config        map[string]any `json:"config"`
}

type TestConnectorResponse

type TestConnectorResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
}

type UpdateConfigRequest

type UpdateConfigRequest struct {
	Key   string          `json:"key"`
	Value json.RawMessage `json:"value"`
}

type UpdateConnectorRequest

type UpdateConnectorRequest struct {
	Name          string         `json:"name"`
	Description   string         `json:"description"`
	SecretGroupID string         `json:"secretGroupId,omitempty"`
	Config        map[string]any `json:"config"`
	Enabled       bool           `json:"enabled"`
	IsDefault     bool           `json:"isDefault,omitempty"`
}

type UpdatePackParametersRequest

type UpdatePackParametersRequest struct {
	Parameters map[string]any `json:"parameters"`
}

type UpdateScheduleRequest

type UpdateScheduleRequest struct {
	CronExpression string `json:"cronExpression"`
	Enabled        bool   `json:"enabled"`
	Parallelism    int    `json:"parallelism,omitempty"`
}

type UpdateSecretRequest

type UpdateSecretRequest struct {
	Name        string               `json:"name"`
	Description string               `json:"description"`
	Entries     []SecretEntryRequest `json:"entries"`
}

type VersionResponse

type VersionResponse struct {
	Version   string `json:"version"`
	Commit    string `json:"commit"`
	BuildDate string `json:"buildDate"`
	GoVersion string `json:"goVersion"`
}

type WSMessage

type WSMessage struct {
	Type string `json:"type"`
	Data any    `json:"data"`
}

WSMessage is the envelope for all WebSocket messages.

Directories

Path Synopsis
Package auth provides Google OAuth login and session-cookie middleware for the web API.
Package auth provides Google OAuth login and session-cookie middleware for the web API.

Jump to

Keyboard shortcuts

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