Documentation
¶
Overview ¶
Package observation implements the SOC 2 Type II observation period framework. It tracks the observation lifecycle (start, monitor, complete), accumulates timestamped evidence, records control deviations, and generates observation period reports with control effectiveness statistics.
Index ¶
- Constants
- type CheckFunc
- type CheckResult
- type ControlEffectiveness
- type Deviation
- type DeviationStatus
- type DeviationTracker
- func (t *DeviationTracker) All() []Deviation
- func (t *DeviationTracker) Count() int
- func (t *DeviationTracker) ForControl(controlID string) []Deviation
- func (t *DeviationTracker) Open() []Deviation
- func (t *DeviationTracker) OpenCount() int
- func (t *DeviationTracker) Record(d Deviation) error
- func (t *DeviationTracker) Resolve(id string, status DeviationStatus, remediation string, resolvedBy string, ...) error
- type EvidenceAccumulator
- func (a *EvidenceAccumulator) Add(e EvidenceItem) error
- func (a *EvidenceAccumulator) All() []EvidenceItem
- func (a *EvidenceAccumulator) ControlIDs() []string
- func (a *EvidenceAccumulator) Count() int
- func (a *EvidenceAccumulator) CountForControl(controlID string) int
- func (a *EvidenceAccumulator) ForControl(controlID string) []EvidenceItem
- type EvidenceItem
- type Milestone
- type Monitor
- func (m *Monitor) Checks() []ScheduledCheck
- func (m *Monitor) Register(sc ScheduledCheck) error
- func (m *Monitor) Results() []CheckResult
- func (m *Monitor) ResultsForControl(controlID string) []CheckResult
- func (m *Monitor) RunAll(now time.Time) []CheckResult
- func (m *Monitor) RunDue(now time.Time) []CheckResult
- type Period
- func (p *Period) AddMilestone(m Milestone) error
- func (p *Period) Complete(now time.Time) error
- func (p *Period) CompleteMilestone(name string, completedAt time.Time) error
- func (p *Period) Elapsed(now time.Time) time.Duration
- func (p *Period) EndDate() time.Time
- func (p *Period) Milestones() []Milestone
- func (p *Period) Phase() Phase
- func (p *Period) RemainingDays(now time.Time) int
- func (p *Period) Start(start time.Time, duration time.Duration) error
- func (p *Period) StartDate() time.Time
- type Phase
- type Report
- type ScheduledCheck
- type Severity
Constants ¶
const MinimumDuration = 6 * 30 * 24 * time.Hour // ~180 days
MinimumDuration is the minimum observation period required for SOC 2 Type II (6 months).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckFunc ¶
CheckFunc is a function that evaluates whether a control is operating effectively. It returns true if the control passed and an optional description of the result.
type CheckResult ¶
CheckResult captures the outcome of a single control monitoring check.
type ControlEffectiveness ¶
type ControlEffectiveness struct {
ControlID string
TotalChecks int
PassedChecks int
FailedChecks int
EffectivenessRate float64 // 0.0 to 1.0
Deviations int
EvidenceCount int
}
ControlEffectiveness summarizes a control's effectiveness over the observation period.
type Deviation ¶
type Deviation struct {
ID string
ControlID string
Severity Severity
Status DeviationStatus
Description string
RootCause string
Remediation string
DetectedAt time.Time
ResolvedAt time.Time
ResolvedBy string
}
Deviation records a control failure or exception observed during the observation period.
type DeviationStatus ¶
type DeviationStatus string
DeviationStatus tracks the remediation state of a deviation.
const ( DeviationOpen DeviationStatus = "open" DeviationMitigated DeviationStatus = "mitigated" DeviationRemediated DeviationStatus = "remediated" DeviationAccepted DeviationStatus = "accepted" // risk accepted )
type DeviationTracker ¶
type DeviationTracker struct {
// contains filtered or unexported fields
}
DeviationTracker records and manages control deviations during the observation period.
func NewDeviationTracker ¶
func NewDeviationTracker() *DeviationTracker
NewDeviationTracker creates a new deviation tracker.
func (*DeviationTracker) All ¶
func (t *DeviationTracker) All() []Deviation
All returns all deviations.
func (*DeviationTracker) Count ¶
func (t *DeviationTracker) Count() int
Count returns the total number of deviations.
func (*DeviationTracker) ForControl ¶
func (t *DeviationTracker) ForControl(controlID string) []Deviation
ForControl returns deviations for a specific control.
func (*DeviationTracker) Open ¶
func (t *DeviationTracker) Open() []Deviation
Open returns all deviations that have not been resolved.
func (*DeviationTracker) OpenCount ¶
func (t *DeviationTracker) OpenCount() int
OpenCount returns the number of open deviations.
func (*DeviationTracker) Record ¶
func (t *DeviationTracker) Record(d Deviation) error
Record adds a new deviation. Returns an error if the ID or ControlID is empty.
func (*DeviationTracker) Resolve ¶
func (t *DeviationTracker) Resolve(id string, status DeviationStatus, remediation string, resolvedBy string, resolvedAt time.Time) error
Resolve updates the status and resolution details of a deviation. Returns an error if the deviation is not found.
type EvidenceAccumulator ¶
type EvidenceAccumulator struct {
// contains filtered or unexported fields
}
EvidenceAccumulator collects timestamped evidence over the observation period. Evidence is indexed by control ID for efficient retrieval during report generation.
func NewEvidenceAccumulator ¶
func NewEvidenceAccumulator() *EvidenceAccumulator
NewEvidenceAccumulator creates an empty evidence accumulator.
func (*EvidenceAccumulator) Add ¶
func (a *EvidenceAccumulator) Add(e EvidenceItem) error
Add stores a new evidence item. The hash is computed automatically from the content. Returns an error if the ID or ControlID is empty.
func (*EvidenceAccumulator) All ¶
func (a *EvidenceAccumulator) All() []EvidenceItem
All returns all evidence items in collection order.
func (*EvidenceAccumulator) ControlIDs ¶
func (a *EvidenceAccumulator) ControlIDs() []string
ControlIDs returns the set of control IDs that have evidence.
func (*EvidenceAccumulator) Count ¶
func (a *EvidenceAccumulator) Count() int
Count returns the total number of evidence items.
func (*EvidenceAccumulator) CountForControl ¶
func (a *EvidenceAccumulator) CountForControl(controlID string) int
CountForControl returns the number of evidence items for a given control.
func (*EvidenceAccumulator) ForControl ¶
func (a *EvidenceAccumulator) ForControl(controlID string) []EvidenceItem
ForControl returns all evidence items for a given control ID.
type EvidenceItem ¶
type EvidenceItem struct {
ID string
ControlID string
Description string
Collector string
CollectedAt time.Time
Hash string // SHA-256 of content
Content []byte
Tags []string
}
EvidenceItem represents a timestamped evidence artifact collected during the observation period. Unlike the base compliance.Evidence, this is specifically scoped to a point in the observation timeline.
type Milestone ¶
type Milestone struct {
Name string
Description string
DueDate time.Time
CompletedAt time.Time
Completed bool
}
Milestone marks a significant event during the observation period.
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor performs continuous control monitoring with scheduled checks during the observation period. It records all check results for the observation report.
func (*Monitor) Checks ¶
func (m *Monitor) Checks() []ScheduledCheck
Checks returns a copy of all registered scheduled checks.
func (*Monitor) Register ¶
func (m *Monitor) Register(sc ScheduledCheck) error
Register adds a scheduled check for a control. Returns an error if the control ID or check function is nil.
func (*Monitor) Results ¶
func (m *Monitor) Results() []CheckResult
Results returns all check results recorded so far.
func (*Monitor) ResultsForControl ¶
func (m *Monitor) ResultsForControl(controlID string) []CheckResult
ResultsForControl returns check results for a specific control.
type Period ¶
type Period struct {
// contains filtered or unexported fields
}
Period tracks the SOC 2 Type II observation period lifecycle.
func NewPeriod ¶
func NewPeriod() *Period
NewPeriod creates a new observation period that has not yet started.
func (*Period) AddMilestone ¶
AddMilestone adds a milestone to the observation period. Returns an error if the period is not active.
func (*Period) Complete ¶
Complete marks the observation period as completed. It returns an error if the period is not active or the minimum duration has not elapsed.
func (*Period) CompleteMilestone ¶
CompleteMilestone marks a milestone as completed by name. Returns an error if the milestone is not found.
func (*Period) Elapsed ¶
Elapsed returns the time elapsed since the observation period started. Returns zero if the period has not started.
func (*Period) Milestones ¶
Milestones returns a copy of all milestones.
func (*Period) RemainingDays ¶
RemainingDays returns the number of days remaining until the scheduled end date. Returns 0 if the period is completed or past the end date.
type Report ¶
type Report struct {
Title string
GeneratedAt time.Time
PeriodStart time.Time
PeriodEnd time.Time
Phase Phase
DurationDays int
Milestones []Milestone
Controls []ControlEffectiveness
TotalChecks int
TotalPassed int
TotalFailed int
TotalDeviations int
OpenDeviations int
TotalEvidence int
OverallEffectiveness float64
}
Report captures the full observation period summary, including control effectiveness statistics, deviations, and evidence coverage.
func GenerateReport ¶
func GenerateReport(period *Period, monitor *Monitor, evidence *EvidenceAccumulator, deviations *DeviationTracker) Report
GenerateReport produces an observation period report from the tracker, monitor, evidence accumulator, and deviation tracker.