Documentation
¶
Overview ¶
Package session provides safe-mode style change journals with rollback.
Index ¶
- Constants
- func BuildInverse(command string, args []string, createdID string) []string
- func BuildRemoveInverse(removeCommand string, preState map[string]string) []string
- func BuildSetInverse(setCommand, id string, preState map[string]string, changedArgs []string) []string
- func ChangedSetKeys(args []string) []string
- func DefaultDir() string
- func IsReadOnlyField(key string) bool
- func Watch(ctx context.Context, store *Store, sess *Session, cfg WatchConfig) error
- type Change
- type ProbeFunc
- type RollbackFunc
- type Session
- type Store
- func (s *Store) Active(device string) (*Session, error)
- func (s *Store) AppendChange(sess *Session, change Change) error
- func (s *Store) Begin(device string, safe bool) (*Session, error)
- func (s *Store) ClearAutoRollbackPending(sess *Session) error
- func (s *Store) Commit(sess *Session) error
- func (s *Store) Get(id string) (*Session, error)
- func (s *Store) MarkAutoRollbackPending(sess *Session) error
- func (s *Store) MarkRolledBack(sess *Session) error
- type WatchConfig
Constants ¶
const ( StatusActive = "active" StatusCommitted = "committed" StatusRolledBack = "rolled_back" )
Variables ¶
This section is empty.
Functions ¶
func BuildInverse ¶
BuildInverse constructs a simple inverse for common RouterOS mutations. Returns command + args for the inverse, or empty if unknown.
func BuildRemoveInverse ¶ added in v0.3.0
BuildRemoveInverse recreates a removed row via /add using printable writable fields.
func BuildSetInverse ¶ added in v0.3.0
func BuildSetInverse(setCommand, id string, preState map[string]string, changedArgs []string) []string
BuildSetInverse restores previously changed properties via /set. changedArgs are the =key=value pairs from the original set (excluding .id). When id is empty (singleton menus like /ip/cloud), the inverse omits =.id=.
func ChangedSetKeys ¶ added in v0.3.0
ChangedSetKeys extracts property keys from set args (excluding .id).
func IsReadOnlyField ¶ added in v0.3.0
IsReadOnlyField reports whether a printed field should be omitted from restore args.
Types ¶
type Change ¶
type Change struct {
ID string `json:"id"`
Command string `json:"command"`
Args []string `json:"args"`
Inverse []string `json:"inverse"` // first element is command, rest are args
PreState map[string]string `json:"pre_state,omitempty"`
AppliedAt time.Time `json:"applied_at"`
Note string `json:"note,omitempty"`
}
Change records a single mutating operation and how to undo it.
type RollbackFunc ¶ added in v0.3.0
RollbackFunc applies journal inverses for the session.
type Session ¶
type Session struct {
ID string `json:"id"`
Device string `json:"device"`
Safe bool `json:"safe"`
Status string `json:"status"`
AutoRollbackPending bool `json:"auto_rollback_pending,omitempty"`
StartedAt time.Time `json:"started_at"`
UpdatedAt time.Time `json:"updated_at"`
Changes []Change `json:"changes"`
}
Session is a journal of pending changes for a device.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists sessions to disk under a base directory.
func (*Store) AppendChange ¶
AppendChange records a change on an active session.
func (*Store) Begin ¶
Begin starts a new active session for a device. Only one active session per device.
func (*Store) ClearAutoRollbackPending ¶ added in v0.3.0
ClearAutoRollbackPending clears the pending flag after a successful or abandoned rollback.
func (*Store) MarkAutoRollbackPending ¶ added in v0.3.0
MarkAutoRollbackPending flags the session so the next connect can finish rollback.
func (*Store) MarkRolledBack ¶
MarkRolledBack marks the session rolled back and clears the active lock.
type WatchConfig ¶ added in v0.3.0
type WatchConfig struct {
Interval time.Duration
FailThreshold int
Probe ProbeFunc
Rollback RollbackFunc
OnLinkLost func(sess *Session)
OnRolledBack func(sess *Session, err error)
}
WatchConfig controls heartbeat behavior.