storage

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionLog

type ActionLog struct {
	Timestamp    time.Time `json:"timestamp"`
	AgentIDHash  string    `json:"agent_id_hash"`
	Method       string    `json:"method"`
	Direction    string    `json:"direction"`
	Success      bool      `json:"success"`
	LatencyMs    float64   `json:"latency_ms"`
	PayloadSize  int       `json:"payload_size"`
	AuthStatus   string    `json:"auth"`
	ErrorCode    string    `json:"error_code"`
	IPAddress    string    `json:"ip"`
	UpstreamName string    `json:"upstream_name"`
}

ActionLog represents a single intercepted message log entry.

type AgentKey added in v1.0.0

type AgentKey struct {
	ID        string `json:"id"`
	PublicKey string `json:"public_key"`
	Label     string `json:"label"`
	CreatedAt string `json:"created_at"`
	Active    bool   `json:"active"`
}

AgentKey represents a registered agent public key.

type DB

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

DB wraps a SQLite connection.

func Open

func Open(path string) (*DB, error)

Open opens (or creates) a SQLite database at path, enables WAL mode, and runs migrations.

func (*DB) Close

func (db *DB) Close() error

Close closes the underlying database connection.

func (*DB) Conn added in v0.2.0

func (db *DB) Conn() *sql.DB

Conn returns the underlying *sql.DB connection.

func (*DB) DeleteAgentKey added in v1.0.0

func (db *DB) DeleteAgentKey(id string) error

DeleteAgentKey soft-deletes an agent key by setting active=0.

func (*DB) DeleteUpstream added in v1.0.0

func (db *DB) DeleteUpstream(name string) error

DeleteUpstream soft-deletes an upstream.

func (*DB) GetAgentKey added in v1.0.0

func (db *DB) GetAgentKey(id string) (*AgentKey, error)

GetAgentKey retrieves a single active agent key by ID.

func (*DB) Insert

func (db *DB) Insert(log ActionLog) error

Insert stores a single ActionLog entry.

func (*DB) InsertAgentKey added in v1.0.0

func (db *DB) InsertAgentKey(id, publicKey, label string) error

InsertAgentKey stores a new agent public key.

func (*DB) InsertUpstream added in v1.0.0

func (db *DB) InsertUpstream(u UpstreamRow) error

InsertUpstream adds a new upstream.

func (*DB) ListAgentKeys added in v1.0.0

func (db *DB) ListAgentKeys(includeInactive bool) ([]AgentKey, error)

ListAgentKeys returns all agent keys, optionally including inactive ones.

func (*DB) ListUpstreams added in v1.0.0

func (db *DB) ListUpstreams() ([]UpstreamRow, error)

ListUpstreams returns all active upstreams.

func (*DB) LoadConfig added in v1.0.0

func (db *DB) LoadConfig(key string) (string, error)

LoadConfig retrieves a single value from admin_config by key.

func (*DB) LoadConfigPrefix added in v1.0.0

func (db *DB) LoadConfigPrefix(prefix string) (map[string]string, error)

LoadConfigPrefix returns all admin_config entries whose key starts with prefix.

func (*DB) Purge

func (db *DB) Purge(retentionDays int) (int64, error)

Purge deletes log entries older than retentionDays days. Returns the number of rows deleted.

func (*DB) QueryLogs

func (db *DB) QueryLogs(opts QueryOptions) ([]ActionLog, error)

QueryLogs returns log entries matching opts, ordered newest-first.

func (*DB) SaveConfig added in v1.0.0

func (db *DB) SaveConfig(key, value string) error

SaveConfig stores a key-value pair in the admin_config table.

func (*DB) SchemaVersion

func (db *DB) SchemaVersion() (int, error)

SchemaVersion returns the current schema version (for diagnostics).

func (*DB) UpdateUpstream added in v1.0.0

func (db *DB) UpdateUpstream(name string, u UpstreamRow) error

UpdateUpstream modifies an existing upstream.

type QueryOptions

type QueryOptions struct {
	Last         int
	AgentHash    string
	Since        time.Duration
	Method       string
	UpstreamName string
}

QueryOptions controls which log entries are returned by QueryLogs.

type UpstreamRow added in v1.0.0

type UpstreamRow struct {
	Name          string `json:"name"`
	URL           string `json:"url"`
	MatchHost     string `json:"match_host"`
	MatchPrefix   string `json:"match_prefix"`
	StripPrefix   bool   `json:"strip_prefix"`
	Transport     string `json:"transport"`
	TLSSkipVerify bool   `json:"tls_skip_verify"`
	Active        bool   `json:"active"`
	CreatedAt     string `json:"created_at"`
}

UpstreamRow represents a row in the upstreams table.

Jump to

Keyboard shortcuts

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