simulation

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package simulation provides domain models for Breach and Attack Simulation (BAS).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControlTest

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

ControlTest represents a security control effectiveness test.

func NewControlTest

func NewControlTest(tenantID shared.ID, name, framework, controlID string) (*ControlTest, error)

NewControlTest creates a new control test.

func ReconstituteControlTest

func ReconstituteControlTest(
	id, tenantID shared.ID,
	name, description, framework, controlID, controlName, category string,
	testProcedure, expectedResult string,
	status ControlTestStatus,
	lastTestedAt *time.Time, lastTestedBy *shared.ID,
	evidence, notes, riskLevel string,
	linkedSimulationIDs, tags []string,
	createdAt, updatedAt time.Time,
) *ControlTest

ReconstituteControlTest creates from persisted data.

func (*ControlTest) Category

func (c *ControlTest) Category() string

func (*ControlTest) ControlID

func (c *ControlTest) ControlID() string

func (*ControlTest) ControlName

func (c *ControlTest) ControlName() string

func (*ControlTest) CreatedAt

func (c *ControlTest) CreatedAt() time.Time

func (*ControlTest) Description

func (c *ControlTest) Description() string

func (*ControlTest) Evidence

func (c *ControlTest) Evidence() string

func (*ControlTest) ExpectedResult

func (c *ControlTest) ExpectedResult() string

func (*ControlTest) Framework

func (c *ControlTest) Framework() string

func (*ControlTest) ID

func (c *ControlTest) ID() shared.ID

Getters

func (*ControlTest) LastTestedAt

func (c *ControlTest) LastTestedAt() *time.Time

func (*ControlTest) LastTestedBy

func (c *ControlTest) LastTestedBy() *shared.ID

func (*ControlTest) LinkSimulation

func (c *ControlTest) LinkSimulation(simulationID string)

LinkSimulation links a simulation to this control test.

func (*ControlTest) LinkedSimulationIDs

func (c *ControlTest) LinkedSimulationIDs() []string

func (*ControlTest) Name

func (c *ControlTest) Name() string

func (*ControlTest) Notes

func (c *ControlTest) Notes() string

func (*ControlTest) RecordResult

func (c *ControlTest) RecordResult(status ControlTestStatus, evidence, notes string, testedBy shared.ID)

RecordResult records a test result.

func (*ControlTest) RiskLevel

func (c *ControlTest) RiskLevel() string

func (*ControlTest) SetTestDetails

func (c *ControlTest) SetTestDetails(procedure, expected string)

SetTestDetails sets test procedure and expected result.

func (*ControlTest) Status

func (c *ControlTest) Status() ControlTestStatus

func (*ControlTest) Tags

func (c *ControlTest) Tags() []string

func (*ControlTest) TenantID

func (c *ControlTest) TenantID() shared.ID

func (*ControlTest) TestProcedure

func (c *ControlTest) TestProcedure() string

func (*ControlTest) Update

func (c *ControlTest) Update(name, description, controlName, category string)

Update sets mutable fields.

func (*ControlTest) UpdatedAt

func (c *ControlTest) UpdatedAt() time.Time

type ControlTestFilter

type ControlTestFilter struct {
	TenantID  *shared.ID
	Framework *string
	Status    *string
	Search    *string
}

ControlTestFilter defines criteria for filtering control tests.

type ControlTestRepository

type ControlTestRepository interface {
	Create(ctx context.Context, ct *ControlTest) error
	GetByID(ctx context.Context, tenantID, id shared.ID) (*ControlTest, error)
	Update(ctx context.Context, ct *ControlTest) error
	Delete(ctx context.Context, tenantID, id shared.ID) error
	List(ctx context.Context, filter ControlTestFilter, page pagination.Pagination) (pagination.Result[*ControlTest], error)
	GetStatsByFramework(ctx context.Context, tenantID shared.ID) ([]FrameworkStats, error)
}

ControlTestRepository defines persistence for control tests.

type ControlTestStatus

type ControlTestStatus string

ControlTestStatus defines the test result status.

const (
	ControlTestStatusUntested      ControlTestStatus = "untested"
	ControlTestStatusPass          ControlTestStatus = "pass"
	ControlTestStatusFail          ControlTestStatus = "fail"
	ControlTestStatusPartial       ControlTestStatus = "partial"
	ControlTestStatusNotApplicable ControlTestStatus = "not_applicable"
)

type FrameworkStats

type FrameworkStats struct {
	Framework     string `json:"framework"`
	Total         int64  `json:"total"`
	Passed        int64  `json:"passed"`
	Failed        int64  `json:"failed"`
	Partial       int64  `json:"partial"`
	Untested      int64  `json:"untested"`
	NotApplicable int64  `json:"not_applicable"`
}

FrameworkStats holds aggregated control test statistics per framework.

type RunFilter

type RunFilter struct {
	TenantID     *shared.ID
	SimulationID *shared.ID
	Status       *RunStatus
}

RunFilter defines criteria for filtering simulation runs.

type RunRepository

type RunRepository interface {
	Create(ctx context.Context, run *SimulationRun) error
	GetByID(ctx context.Context, tenantID, id shared.ID) (*SimulationRun, error)
	Update(ctx context.Context, run *SimulationRun) error
	List(ctx context.Context, filter RunFilter, page pagination.Pagination) (pagination.Result[*SimulationRun], error)
}

RunRepository defines persistence for simulation runs.

type RunResult

type RunResult string

RunResult defines outcome of a simulation run.

const (
	RunResultDetected  RunResult = "detected"
	RunResultPrevented RunResult = "prevented"
	RunResultBypassed  RunResult = "bypassed"
	RunResultPartial   RunResult = "partial"
	RunResultError     RunResult = "error"
)

type RunStatus

type RunStatus string

RunStatus defines execution states.

const (
	RunStatusPending   RunStatus = "pending"
	RunStatusRunning   RunStatus = "running"
	RunStatusCompleted RunStatus = "completed"
	RunStatusFailed    RunStatus = "failed"
)

type Simulation

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

Simulation represents an attack simulation definition.

func NewSimulation

func NewSimulation(tenantID shared.ID, name string, simType SimulationType) (*Simulation, error)

NewSimulation creates a new simulation.

func ReconstituteSimulation

func ReconstituteSimulation(
	id, tenantID shared.ID,
	name, description string,
	simType SimulationType, status SimulationStatus,
	mitreTactic, mitreTechniqueID, mitreTechniqueName string,
	targetAssets []string, config map[string]any,
	scheduleCron string, lastRunAt, nextRunAt *time.Time,
	totalRuns int, lastResult string,
	detectionRate, preventionRate float64,
	tags []string, createdBy *shared.ID,
	createdAt, updatedAt time.Time,
) *Simulation

ReconstituteSimulation creates a Simulation from persisted data.

func (*Simulation) Activate

func (s *Simulation) Activate() error

Activate transitions simulation to active.

func (*Simulation) Config

func (s *Simulation) Config() map[string]any

func (*Simulation) CreatedAt

func (s *Simulation) CreatedAt() time.Time

func (*Simulation) CreatedBy

func (s *Simulation) CreatedBy() *shared.ID

func (*Simulation) Description

func (s *Simulation) Description() string

func (*Simulation) DetectionRate

func (s *Simulation) DetectionRate() float64

func (*Simulation) ID

func (s *Simulation) ID() shared.ID

Getters

func (*Simulation) LastResult

func (s *Simulation) LastResult() string

func (*Simulation) LastRunAt

func (s *Simulation) LastRunAt() *time.Time

func (*Simulation) MitreTactic

func (s *Simulation) MitreTactic() string

func (*Simulation) MitreTechniqueID

func (s *Simulation) MitreTechniqueID() string

func (*Simulation) MitreTechniqueName

func (s *Simulation) MitreTechniqueName() string

func (*Simulation) Name

func (s *Simulation) Name() string

func (*Simulation) NextRunAt

func (s *Simulation) NextRunAt() *time.Time

func (*Simulation) PreventionRate

func (s *Simulation) PreventionRate() float64

func (*Simulation) RecordRun

func (s *Simulation) RecordRun(result string, detectionRate, preventionRate float64)

RecordRun updates run statistics after a simulation run completes.

func (*Simulation) ScheduleCron

func (s *Simulation) ScheduleCron() string

func (*Simulation) SetConfig

func (s *Simulation) SetConfig(config map[string]any, targetAssets, tags []string) error

SetConfig sets simulation configuration after validating allowed keys.

func (*Simulation) SetCreatedBy

func (s *Simulation) SetCreatedBy(userID shared.ID)

SetCreatedBy sets the creator.

func (*Simulation) SetMITRE

func (s *Simulation) SetMITRE(tactic, techniqueID, techniqueName string)

SetMITRE sets ATT&CK mapping.

func (*Simulation) SetSchedule

func (s *Simulation) SetSchedule(cron string)

SetSchedule sets cron schedule.

func (*Simulation) SimulationType

func (s *Simulation) SimulationType() SimulationType

func (*Simulation) Status

func (s *Simulation) Status() SimulationStatus

func (*Simulation) Tags

func (s *Simulation) Tags() []string

func (*Simulation) TargetAssets

func (s *Simulation) TargetAssets() []string

func (*Simulation) TenantID

func (s *Simulation) TenantID() shared.ID

func (*Simulation) TotalRuns

func (s *Simulation) TotalRuns() int

func (*Simulation) Update

func (s *Simulation) Update(name, description string)

Update sets mutable fields.

func (*Simulation) UpdatedAt

func (s *Simulation) UpdatedAt() time.Time

type SimulationFilter

type SimulationFilter struct {
	TenantID       *shared.ID
	SimulationType *SimulationType
	Status         *SimulationStatus
	Search         *string
}

SimulationFilter defines criteria for filtering simulations.

type SimulationRepository

type SimulationRepository interface {
	Create(ctx context.Context, sim *Simulation) error
	GetByID(ctx context.Context, tenantID, id shared.ID) (*Simulation, error)
	Update(ctx context.Context, sim *Simulation) error
	Delete(ctx context.Context, tenantID, id shared.ID) error
	List(ctx context.Context, filter SimulationFilter, page pagination.Pagination) (pagination.Result[*Simulation], error)
}

SimulationRepository defines persistence for simulations.

type SimulationRun

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

SimulationRun represents a single execution of a simulation.

func NewSimulationRun

func NewSimulationRun(tenantID, simulationID shared.ID) *SimulationRun

NewSimulationRun creates a new run for a simulation.

func ReconstituteRun

func ReconstituteRun(
	id, tenantID, simulationID shared.ID,
	status RunStatus, result RunResult,
	detectionResult, preventionResult string,
	steps []map[string]any, output map[string]any,
	errorMessage string,
	startedAt, completedAt *time.Time, durationMs int,
	triggeredBy *shared.ID, createdAt time.Time,
) *SimulationRun

ReconstituteRun creates a run from persisted data.

func (*SimulationRun) Complete

func (r *SimulationRun) Complete(result RunResult, detection, prevention string, output map[string]any)

Complete marks the run as completed with results.

func (*SimulationRun) CompletedAt

func (r *SimulationRun) CompletedAt() *time.Time

func (*SimulationRun) CreatedAt

func (r *SimulationRun) CreatedAt() time.Time

func (*SimulationRun) DetectionResult

func (r *SimulationRun) DetectionResult() string

func (*SimulationRun) DurationMs

func (r *SimulationRun) DurationMs() int

func (*SimulationRun) ErrorMessage

func (r *SimulationRun) ErrorMessage() string

func (*SimulationRun) Fail

func (r *SimulationRun) Fail(errMsg string)

Fail marks the run as failed.

func (*SimulationRun) ID

func (r *SimulationRun) ID() shared.ID

Getters

func (*SimulationRun) Output

func (r *SimulationRun) Output() map[string]any

func (*SimulationRun) PreventionResult

func (r *SimulationRun) PreventionResult() string

func (*SimulationRun) Result

func (r *SimulationRun) Result() RunResult

func (*SimulationRun) SetTriggeredBy

func (r *SimulationRun) SetTriggeredBy(userID shared.ID)

SetTriggeredBy sets who triggered the run.

func (*SimulationRun) SimulationID

func (r *SimulationRun) SimulationID() shared.ID

func (*SimulationRun) Start

func (r *SimulationRun) Start()

Start marks the run as started.

func (*SimulationRun) StartedAt

func (r *SimulationRun) StartedAt() *time.Time

func (*SimulationRun) Status

func (r *SimulationRun) Status() RunStatus

func (*SimulationRun) Steps

func (r *SimulationRun) Steps() []map[string]any

func (*SimulationRun) TenantID

func (r *SimulationRun) TenantID() shared.ID

func (*SimulationRun) TriggeredBy

func (r *SimulationRun) TriggeredBy() *shared.ID

type SimulationStatus

type SimulationStatus string

SimulationStatus defines lifecycle states.

const (
	SimulationStatusDraft     SimulationStatus = "draft"
	SimulationStatusActive    SimulationStatus = "active"
	SimulationStatusPaused    SimulationStatus = "paused"
	SimulationStatusCompleted SimulationStatus = "completed"
	SimulationStatusArchived  SimulationStatus = "archived"
)

type SimulationType

type SimulationType string

SimulationType defines the kind of simulation.

const (
	SimulationTypeAtomic      SimulationType = "atomic"
	SimulationTypeCampaign    SimulationType = "campaign"
	SimulationTypeControlTest SimulationType = "control_test"
)

Jump to

Keyboard shortcuts

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