Documentation
¶
Overview ¶
Package web implements the REST API, WebSocket hub, and embedded-frontend HTTP server.
Index ¶
- Constants
- func DeleteRunLog(dataDir, runID string)
- func ServeWS(hub *Hub, w http.ResponseWriter, r *http.Request)
- func SweepRunLogs(dataDir string, enabled bool, days int)
- func SweepRuns(ctx context.Context, runStore db.RunStore, dataDir string, enabled bool, ...)
- type AzureConnectorConfig
- type Client
- type ConnectorHandlers
- func (h *ConnectorHandlers) HandleCreateConnector(w http.ResponseWriter, r *http.Request)
- func (h *ConnectorHandlers) HandleDeleteConnector(w http.ResponseWriter, r *http.Request)
- func (h *ConnectorHandlers) HandleGetConnector(w http.ResponseWriter, r *http.Request)
- func (h *ConnectorHandlers) HandleGetElasticRule(w http.ResponseWriter, r *http.Request)
- func (h *ConnectorHandlers) HandleListConnectors(w http.ResponseWriter, r *http.Request)
- func (h *ConnectorHandlers) HandleListElasticRules(w http.ResponseWriter, r *http.Request)
- func (h *ConnectorHandlers) HandleListElasticRulesAuto(w http.ResponseWriter, r *http.Request)
- func (h *ConnectorHandlers) HandleRuleCoverage(w http.ResponseWriter, r *http.Request)
- func (h *ConnectorHandlers) HandleTestConnector(w http.ResponseWriter, r *http.Request)
- func (h *ConnectorHandlers) HandleUpdateConnector(w http.ResponseWriter, r *http.Request)
- type CoverageLastResult
- type CoverageResponse
- type CoverageScenario
- type CoverageSummary
- type CreateConnectorRequest
- type CreateScheduleRequest
- type CreateSecretRequest
- type ElasticConnectorConfig
- type ErrorResponse
- type GCPConnectorConfig
- type Handlers
- func (h *Handlers) HandleDeleteAssessment(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleDeleteRun(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleDownloadCollectedLogs(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleGetAssessment(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleGetAssessmentByName(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleGetConfig(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleGetRun(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleGetRunLogs(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleLint(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleListAssessmentRuns(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleListAssessments(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleListRuns(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleRun(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleSaveAssessment(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleUpdateAssessment(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleUpdateConfig(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HandleVersion(w http.ResponseWriter, r *http.Request)
- type Hub
- type InstallPackRequest
- type KubernetesConnectorConfig
- type LintRequest
- type LintResponse
- type LintedScenario
- type PackHandlers
- func (h *PackHandlers) HandleDeletePack(w http.ResponseWriter, r *http.Request)
- func (h *PackHandlers) HandleGetManifest(w http.ResponseWriter, r *http.Request)
- func (h *PackHandlers) HandleGetPackParameters(w http.ResponseWriter, r *http.Request)
- func (h *PackHandlers) HandleInstallPack(w http.ResponseWriter, r *http.Request)
- func (h *PackHandlers) HandleListPacks(w http.ResponseWriter, r *http.Request)
- func (h *PackHandlers) HandleUpdatePackParameters(w http.ResponseWriter, r *http.Request)
- func (h *PackHandlers) HandleUploadPack(w http.ResponseWriter, r *http.Request)
- type ResultExporter
- type RuleCoverageEntry
- type RunLogEntry
- type RunLogHook
- type RunLogRegistry
- type RunLogWriter
- type RunOptions
- type RunRequest
- type RunResponse
- type SSHConnectorConfig
- type SaveAssessmentRequest
- type ScenarioService
- type ScheduleHandlers
- func (h *ScheduleHandlers) HandleCreateSchedule(w http.ResponseWriter, r *http.Request)
- func (h *ScheduleHandlers) HandleDeleteSchedule(w http.ResponseWriter, r *http.Request)
- func (h *ScheduleHandlers) HandleGetSchedule(w http.ResponseWriter, r *http.Request)
- func (h *ScheduleHandlers) HandleGetScheduleByAssessment(w http.ResponseWriter, r *http.Request)
- func (h *ScheduleHandlers) HandleListSchedules(w http.ResponseWriter, r *http.Request)
- func (h *ScheduleHandlers) HandleUpdateSchedule(w http.ResponseWriter, r *http.Request)
- type Scheduler
- type SecretEntryRequest
- type SecretGroupResponse
- type SecretHandlers
- func (h *SecretHandlers) HandleDeleteSecret(w http.ResponseWriter, r *http.Request)
- func (h *SecretHandlers) HandleGetSecret(w http.ResponseWriter, r *http.Request)
- func (h *SecretHandlers) HandleListSecrets(w http.ResponseWriter, r *http.Request)
- func (h *SecretHandlers) HandleSaveSecret(w http.ResponseWriter, r *http.Request)
- func (h *SecretHandlers) HandleUpdateSecret(w http.ResponseWriter, r *http.Request)
- type Server
- type ServerConfig
- type TestConnectorRequest
- type TestConnectorResponse
- type UpdateConfigRequest
- type UpdateConnectorRequest
- type UpdatePackParametersRequest
- type UpdateScheduleRequest
- type UpdateSecretRequest
- type VersionResponse
- type WSMessage
Constants ¶
const ( ScenarioTypeStandard = "standard" ScenarioTypeExplore = "explore" ScenarioTypeCollect = "collect" )
Scenario type constants.
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
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
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 CreateScheduleRequest ¶
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 (*Hub) BroadcastToRun ¶
BroadcastToRun sends a message to all clients subscribed to a specific run.
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 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) 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 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 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.
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 ¶
ListenAndServe starts the HTTP server.
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 TestConnectorResponse ¶
type UpdateConfigRequest ¶
type UpdateConfigRequest struct {
Key string `json:"key"`
Value json.RawMessage `json:"value"`
}
type UpdateConnectorRequest ¶
type UpdateScheduleRequest ¶
type UpdateSecretRequest ¶
type UpdateSecretRequest struct {
Name string `json:"name"`
Description string `json:"description"`
Entries []SecretEntryRequest `json:"entries"`
}