Documentation
¶
Overview ¶
Package db is the PostgreSQL persistence layer (pgx), running embedded migrations on startup.
Index ¶
- Variables
- type Assessment
- type AssessmentPage
- type AssessmentStore
- type AuthSession
- type ConfigStore
- type Connector
- type ConnectorStore
- type DB
- type LatestExpectationResult
- type ListAssessmentsFilters
- type ListRunsFilters
- type Pack
- type PackStore
- type Run
- type RunPage
- type RunStore
- type ScenarioResult
- type Schedule
- type ScheduleStore
- type SecretGroup
- type SecretStore
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
var ErrSessionNotFound = errors.New("session not found")
ErrSessionNotFound is returned when a session does not exist or has expired.
Functions ¶
This section is empty.
Types ¶
type Assessment ¶ added in v0.4.0
type Assessment struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
YAML string `json:"yaml"`
CreatedBy string `json:"createdBy"`
UpdatedBy string `json:"updatedBy"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Assessment represents a saved assessment definition (the saved YAML).
type AssessmentPage ¶ added in v0.4.0
type AssessmentPage struct {
Assessments []Assessment `json:"assessments"`
Total int `json:"total"`
}
AssessmentPage is a paginated slice of assessments with the total row count.
type AssessmentStore ¶ added in v0.4.0
type AssessmentStore interface {
Save(ctx context.Context, name, assessmentType, yaml, createdBy string) (*Assessment, error)
Get(ctx context.Context, id uuid.UUID) (*Assessment, error)
// GetByName returns the assessment with the given unique name.
GetByName(ctx context.Context, name string) (*Assessment, error)
// List returns a filtered, paginated slice of assessments for the UI.
List(ctx context.Context, filters ListAssessmentsFilters, limit, offset int) (AssessmentPage, error)
// ListAll returns every assessment in updated_at DESC order. For internal
// callers (e.g. coverage maps) that need the full set in one shot.
ListAll(ctx context.Context) ([]Assessment, error)
Update(ctx context.Context, id uuid.UUID, name, assessmentType, yaml, updatedBy string) error
Delete(ctx context.Context, id uuid.UUID) error
}
AssessmentStore manages saved assessment (definition) YAML persistence.
func NewAssessmentStore ¶ added in v0.4.0
func NewAssessmentStore(pool *pgxpool.Pool) AssessmentStore
NewAssessmentStore creates a new AssessmentStore backed by PostgreSQL.
type AuthSession ¶
type AuthSession struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
Picture string `json:"picture"`
CreatedAt time.Time `json:"createdAt"`
ExpiresAt time.Time `json:"expiresAt"`
}
AuthSession represents a user authentication session.
type ConfigStore ¶
type ConfigStore interface {
Get(ctx context.Context, key string) (json.RawMessage, error)
Set(ctx context.Context, key string, value json.RawMessage) error
GetAll(ctx context.Context) (map[string]json.RawMessage, error)
GetAppConfig(ctx context.Context) (config.AppConfig, error)
UpdateAppConfig(ctx context.Context, c config.AppConfig) error
}
ConfigStore manages key-value application configuration.
func NewConfigStore ¶
func NewConfigStore(pool *pgxpool.Pool) ConfigStore
NewConfigStore creates a new ConfigStore backed by PostgreSQL.
type Connector ¶
type Connector struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description"`
SecretGroupID *uuid.UUID `json:"secretGroupId,omitempty"`
Config json.RawMessage `json:"config"`
Enabled bool `json:"enabled"`
IsDefault bool `json:"isDefault"`
CreatedBy string `json:"createdBy"`
UpdatedBy string `json:"updatedBy"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Connector represents an external system connector (alert source or cloud target).
type ConnectorStore ¶
type ConnectorStore interface {
Save(ctx context.Context, name, connectorType, description string, secretGroupID *uuid.UUID, config json.RawMessage, isDefault bool, createdBy string) (*Connector, error)
Get(ctx context.Context, id uuid.UUID) (*Connector, error)
GetByName(ctx context.Context, name string) (*Connector, error)
GetDefault(ctx context.Context, connectorType string) (*Connector, error)
List(ctx context.Context) ([]Connector, error)
Update(ctx context.Context, id uuid.UUID, name, description string, secretGroupID *uuid.UUID, config json.RawMessage, enabled bool, isDefault bool, updatedBy string) error
Delete(ctx context.Context, id uuid.UUID) error
}
ConnectorStore manages connector persistence.
func NewConnectorStore ¶
func NewConnectorStore(pool *pgxpool.Pool) ConnectorStore
NewConnectorStore creates a new ConnectorStore backed by PostgreSQL.
type DB ¶
DB wraps a PostgreSQL connection pool.
type LatestExpectationResult ¶ added in v0.4.0
type LatestExpectationResult struct {
AlertName string `json:"alertName"`
Passed bool `json:"passed"`
RunID uuid.UUID `json:"runId"`
CreatedAt time.Time `json:"createdAt"`
}
LatestExpectationResult holds the most recent pass/fail for a given alert name.
type ListAssessmentsFilters ¶ added in v0.4.0
type ListAssessmentsFilters struct {
// Name is an ILIKE %name% match against assessments.name.
Name string
// Types restricts assessments.type to the listed values.
Types []string
// Since restricts assessments to updated_at >= Since.
Since *time.Time
}
ListAssessmentsFilters narrows the result set for AssessmentStore.List. Zero values mean "no constraint on this dimension".
type ListRunsFilters ¶
type ListRunsFilters struct {
// Name is an ILIKE %name% match against assessments.name.
Name string
// Types restricts assessments.type to the listed values.
Types []string
// Since restricts runs to created_at >= Since.
Since *time.Time
// AssessmentID restricts runs to the given assessments.id.
AssessmentID *uuid.UUID
}
ListRunsFilters narrows the result set for RunStore.List. Zero values mean "no constraint on this dimension".
Note: filters that reference assessments columns (Name, Types) silently exclude ad-hoc runs whose assessment_id is NULL, because NULL never matches an equality/LIKE predicate.
type Pack ¶
type Pack struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Source string `json:"source"`
Version string `json:"version,omitempty"`
Status string `json:"status"`
Parameters map[string]any `json:"parameters,omitempty"`
InstalledBy string `json:"installedBy"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Pack represents an installed simulation pack.
type PackStore ¶
type PackStore interface {
Upsert(ctx context.Context, pack *Pack, installedBy string) error
Get(ctx context.Context, name string) (*Pack, error)
List(ctx context.Context) ([]Pack, error)
Delete(ctx context.Context, name string) error
UpdateParameters(ctx context.Context, name string, parameters map[string]any) error
}
PackStore manages pack persistence.
func NewPackStore ¶
NewPackStore creates a new PackStore backed by PostgreSQL.
type Run ¶
type Run struct {
ID uuid.UUID `json:"id"`
Status string `json:"status"`
StartTime time.Time `json:"startTime"`
EndTime *time.Time `json:"endTime,omitempty"`
Total int `json:"total"`
Succeeded int `json:"succeeded"`
Failed int `json:"failed"`
// Errors counts scenarios that failed during execution (warmup, detonation,
// or matching infrastructure) rather than by missing an expected alert. It is
// a subset of Failed and is derived from scenario_results.errored.
Errors int `json:"errors"`
AssessmentID *uuid.UUID `json:"assessmentId,omitempty"`
AssessmentName *string `json:"assessmentName,omitempty"`
AssessmentType *string `json:"assessmentType,omitempty"`
ScheduleID *uuid.UUID `json:"scheduleId,omitempty"`
ScheduleName *string `json:"scheduleName,omitempty"`
CreatedBy string `json:"createdBy"`
CreatedAt time.Time `json:"createdAt"`
}
Run represents a single simrun execution.
type RunStore ¶
type RunStore interface {
Create(ctx context.Context, run *Run) error
Get(ctx context.Context, id uuid.UUID) (*Run, error)
List(ctx context.Context, filters ListRunsFilters, limit, offset int) (RunPage, error)
// ListExpired returns the IDs of runs created before cutoff whose status is
// not "running" — the run-retention sweeper's deletion candidates.
ListExpired(ctx context.Context, cutoff time.Time) ([]uuid.UUID, error)
Update(ctx context.Context, id uuid.UUID, status string, total, succeeded, failed int, endTime *time.Time) error
Delete(ctx context.Context, id uuid.UUID) error
AddScenarioResult(ctx context.Context, runID uuid.UUID, result *ScenarioResult) error
GetScenarioResults(ctx context.Context, runID uuid.UUID) ([]ScenarioResult, error)
GetScenarioResult(ctx context.Context, id uuid.UUID) (*ScenarioResult, error)
// Run lifecycle
CompleteRun(ctx context.Context, id uuid.UUID, endTime *time.Time) error
// Scenario status tracking
CreateScenarioStatus(ctx context.Context, runID uuid.UUID, name string) (uuid.UUID, error)
UpdateScenarioPhase(ctx context.Context, id uuid.UUID, phase string) error
// UpdateScenarioIdentity records executor identity mid-run (after detonation),
// touching only the identity columns and leaving status/phase untouched.
UpdateScenarioIdentity(ctx context.Context, id uuid.UUID, executorName, executorType, executionID, simulationID string) error
// UpdateScenarioExpectations persists partial expectation results mid-run,
// touching only the expectations column and leaving status/phase untouched.
UpdateScenarioExpectations(ctx context.Context, id uuid.UUID, expectationsJSON []byte) error
CompleteScenarioResult(ctx context.Context, id uuid.UUID, result *ScenarioResult) error
IncrementRunCounters(ctx context.Context, id uuid.UUID, successDelta, failDelta int) error
// GetLatestExpectationResults returns the most recent pass/fail for each alert name.
GetLatestExpectationResults(ctx context.Context) ([]LatestExpectationResult, error)
}
RunStore manages run and scenario result persistence.
func NewRunStore ¶
NewRunStore creates a new RunStore backed by PostgreSQL.
type ScenarioResult ¶
type ScenarioResult struct {
ID uuid.UUID `json:"id"`
RunID uuid.UUID `json:"runId"`
Name string `json:"name"`
Status string `json:"status"`
Phase *string `json:"phase,omitempty"`
IsSuccess *bool `json:"isSuccess"`
// Errored is true when the scenario failed during execution rather than by
// missing an expected alert (see Run.Errors).
Errored bool `json:"errored"`
ErrorMessage string `json:"errorMessage,omitempty"`
DurationSecs float64 `json:"durationSecs"`
MatchingDurSecs float64 `json:"matchingDurSecs"`
TimeExecuted *time.Time `json:"timeExecuted,omitempty"`
ExecutorName string `json:"executorName"`
ExecutorType string `json:"executorType"`
ExecutionID string `json:"executionId"`
SimulationID string `json:"simulationId,omitempty"`
Expectations json.RawMessage `json:"expectations,omitempty"`
Indicators json.RawMessage `json:"indicators,omitempty"`
Metadata json.RawMessage `json:"metadata,omitempty"`
CollectedLogPath *string `json:"collectedLogPath,omitempty"`
CollectedDocCount int `json:"collectedDocCount,omitempty"`
DiscoveredAlerts json.RawMessage `json:"discoveredAlerts,omitempty"`
CreatedAt time.Time `json:"createdAt"`
}
ScenarioResult represents the result of a single scenario execution.
type Schedule ¶
type Schedule struct {
ID uuid.UUID `json:"id"`
AssessmentID uuid.UUID `json:"assessmentId"`
CronExpression string `json:"cronExpression"`
Enabled bool `json:"enabled"`
Parallelism int `json:"parallelism"`
LastRunAt *time.Time `json:"lastRunAt,omitempty"`
CreatedBy string `json:"createdBy"`
UpdatedBy string `json:"updatedBy"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Schedule represents a cron schedule for an assessment.
type ScheduleStore ¶
type ScheduleStore interface {
Create(ctx context.Context, assessmentID uuid.UUID, cronExpr string, enabled bool, parallelism int, createdBy string) (*Schedule, error)
Get(ctx context.Context, id uuid.UUID) (*Schedule, error)
GetByAssessmentID(ctx context.Context, assessmentID uuid.UUID) (*Schedule, error)
List(ctx context.Context) ([]Schedule, error)
ListEnabled(ctx context.Context) ([]Schedule, error)
Update(ctx context.Context, id uuid.UUID, cronExpr string, enabled bool, parallelism int, updatedBy string) error
Delete(ctx context.Context, id uuid.UUID) error
UpdateLastRun(ctx context.Context, id uuid.UUID, lastRunAt time.Time) error
}
ScheduleStore manages schedule persistence.
func NewScheduleStore ¶
func NewScheduleStore(pool *pgxpool.Pool) ScheduleStore
NewScheduleStore creates a new ScheduleStore backed by PostgreSQL.
type SecretGroup ¶
type SecretGroup struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Entries json.RawMessage `json:"entries"`
CreatedBy string `json:"createdBy"`
UpdatedBy string `json:"updatedBy"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
SecretGroup represents a named group of encrypted key-value secrets.
type SecretStore ¶
type SecretStore interface {
Save(ctx context.Context, name, description string, entries json.RawMessage, createdBy string) (*SecretGroup, error)
Get(ctx context.Context, id uuid.UUID) (*SecretGroup, error)
List(ctx context.Context) ([]SecretGroup, error)
Update(ctx context.Context, id uuid.UUID, name, description string, entries json.RawMessage, updatedBy string) error
Delete(ctx context.Context, id uuid.UUID) error
}
SecretStore manages secret group persistence.
func NewSecretStore ¶
func NewSecretStore(pool *pgxpool.Pool) SecretStore
NewSecretStore creates a new SecretStore backed by PostgreSQL.
type SessionStore ¶
type SessionStore interface {
Create(ctx context.Context, email, name, picture string, ttl time.Duration) (string, error)
Get(ctx context.Context, sessionID string) (*AuthSession, error)
Delete(ctx context.Context, sessionID string) error
DeleteExpired(ctx context.Context) error
}
SessionStore manages authentication session persistence.
func NewSessionStore ¶
func NewSessionStore(pool *pgxpool.Pool) SessionStore
NewSessionStore creates a new SessionStore backed by PostgreSQL.