Documentation
¶
Index ¶
- Variables
- type CheckResult
- type DisableInput
- type EnableInput
- type MemoryStore
- func (s *MemoryStore) Check(ctx context.Context) (CheckResult, error)
- func (s *MemoryStore) Disable(ctx context.Context, input DisableInput) (State, error)
- func (s *MemoryStore) Enable(ctx context.Context, input EnableInput) (State, error)
- func (s *MemoryStore) Read(ctx context.Context) (State, error)
- type MemoryStoreOption
- type SafeState
- type State
- type Store
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidInput = errors.New("invalid maintenance input")
)
Functions ¶
This section is empty.
Types ¶
type CheckResult ¶
type DisableInput ¶
type DisableInput struct {
Actor string
}
func NormalizeDisableInput ¶
func NormalizeDisableInput(input DisableInput) (DisableInput, error)
NormalizeDisableInput validates optional disable metadata even though the current state model clears the active window. This gives CLI and PostgreSQL stores one shared validation rule for future audit/history fields.
type EnableInput ¶
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
func NewMemoryStore ¶
func NewMemoryStore(opts ...MemoryStoreOption) *MemoryStore
NewMemoryStore returns a process-local maintenance store for standalone deployments and tests. PostgreSQL-backed deployments will replace this store in a later task so every OpenCook process observes the same write gate.
func (*MemoryStore) Check ¶
func (s *MemoryStore) Check(ctx context.Context) (CheckResult, error)
Check evaluates whether the current maintenance state should block writes at the current clock instant. Expired windows are reported as inactive while the stored state remains readable for truthful operator diagnostics.
func (*MemoryStore) Disable ¶
func (s *MemoryStore) Disable(ctx context.Context, input DisableInput) (State, error)
Disable clears the active maintenance state. The operation is intentionally idempotent because operators should be able to safely retry cleanup steps.
func (*MemoryStore) Enable ¶
func (s *MemoryStore) Enable(ctx context.Context, input EnableInput) (State, error)
Enable validates and stores a normalized active maintenance state. The update is all-or-nothing so invalid enable attempts cannot erase an existing window.
func (*MemoryStore) Read ¶
func (s *MemoryStore) Read(ctx context.Context) (State, error)
Read returns the current raw maintenance state without applying expiration. Keeping expired state visible lets status and admin output explain why writes are no longer blocked instead of silently losing operator context.
type MemoryStoreOption ¶
type MemoryStoreOption func(*MemoryStore)
func WithClock ¶
func WithClock(now func() time.Time) MemoryStoreOption
WithClock injects a deterministic clock for expiration tests and future admin-command tests that need stable maintenance timestamps.
type SafeState ¶
type SafeState struct {
Enabled bool `json:"enabled"`
Mode string `json:"mode,omitempty"`
Reason string `json:"reason,omitempty"`
ReasonTruncated bool `json:"reason_truncated,omitempty"`
Actor string `json:"actor,omitempty"`
ActorTruncated bool `json:"actor_truncated,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
type State ¶
type State struct {
Enabled bool `json:"enabled"`
Mode string `json:"mode,omitempty"`
Reason string `json:"reason,omitempty"`
Actor string `json:"actor,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
func CloneState ¶
CloneState returns a deep copy of maintenance state. PostgreSQL repositories use it to protect cached inactive-state values the same way MemoryStore protects values returned to callers.
func NormalizeEnableInput ¶
func NormalizeEnableInput(input EnableInput, fallbackNow time.Time) (State, error)
NormalizeEnableInput canonicalizes operator-provided maintenance state before it is stored. The store keeps the full reason for auditability, while SafeStatus returns a bounded display copy for status surfaces.
func (State) ActiveAt ¶
ActiveAt reports whether the state should block mutating Chef-facing writes at the supplied time. It treats expiration as authoritative but does not mutate or clear the stored state.
func (State) ExpiredAt ¶
ExpiredAt reports whether an enabled maintenance window has reached its expiration time. Disabled states are never considered expired.
func (State) SafeStatus ¶
SafeStatus returns a display-safe copy of maintenance state for status and admin output. It removes control-style whitespace and bounds operator text so future Chef-facing responses do not leak long notes or provider details.