store

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(b int64) string

FormatBytes formats bytes into human-readable string.

Types

type AuditStore added in v0.0.10

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

AuditStore handles audit log persistence.

func NewAuditStore added in v0.0.10

func NewAuditStore(db *sql.DB) *AuditStore

NewAuditStore creates a new AuditStore.

func (*AuditStore) CleanOld added in v0.0.10

func (s *AuditStore) CleanOld(ctx context.Context, olderThan time.Duration) (int, error)

CleanOld removes audit entries older than the given duration.

func (*AuditStore) Insert added in v0.0.10

func (s *AuditStore) Insert(ctx context.Context, user, action, detail string) error

Insert adds a new audit entry.

func (*AuditStore) List added in v0.0.10

func (s *AuditStore) List(ctx context.Context, limit, offset int) ([]model.AuditEntry, error)

List returns audit entries ordered by timestamp descending, with pagination.

type Backup

type Backup struct {
	Filename  string `json:"filename"`
	Size      int64  `json:"size"`
	CreatedAt string `json:"created_at"`
	Checksum  string `json:"checksum,omitempty"`
	Encrypted bool   `json:"encrypted"`
}

Backup represents a backup file record.

type BackupStore

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

BackupStore handles backup management (listing, creation, deletion). It works with the filesystem in the configured backups directory.

func NewBackupStore

func NewBackupStore(baseDir string, encryptionKey ...[]byte) *BackupStore

NewBackupStore creates a new BackupStore. encryptionKey is optional (nil = no encryption).

func (*BackupStore) CleanOld added in v0.0.10

func (s *BackupStore) CleanOld(ctx context.Context, maxAge time.Duration) (int, error)

CleanOld removes backup files older than maxAge. Returns the number of deleted files.

func (*BackupStore) Create

func (s *BackupStore) Create(ctx context.Context) (Backup, error)

Create generates a new backup of the core application data.

func (*BackupStore) Delete

func (s *BackupStore) Delete(ctx context.Context, filename string) error

Delete removes a backup file.

func (*BackupStore) EncryptionEnabled added in v0.0.10

func (s *BackupStore) EncryptionEnabled() bool

EncryptionEnabled reports whether backup encryption is configured.

func (*BackupStore) GetPath

func (s *BackupStore) GetPath(filename string) string

GetPath returns the full path to a backup file.

func (*BackupStore) List

func (s *BackupStore) List(ctx context.Context) ([]Backup, error)

List returns all backup files, newest first.

func (*BackupStore) Restore

func (s *BackupStore) Restore(ctx context.Context, filename string) error

Restore restores data from the specified backup file.

type GeoblockCacheStore

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

GeoblockCacheStore handles geo-block CIDR cache tracking.

func NewGeoblockCacheStore

func NewGeoblockCacheStore(db *sql.DB) *GeoblockCacheStore

NewGeoblockCacheStore creates a new GeoblockCacheStore.

func (*GeoblockCacheStore) GetCache

func (s *GeoblockCacheStore) GetCache(ctx context.Context, code string) (filePath string, downloadedAt int64, err error)

GetCache returns cached info for a country.

func (*GeoblockCacheStore) SetCache

func (s *GeoblockCacheStore) SetCache(ctx context.Context, code, filePath string) error

SetCache updates the cache info for a country.

type InstanceStore

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

InstanceStore handles instance persistence.

func NewInstanceStore

func NewInstanceStore(db *sql.DB) *InstanceStore

NewInstanceStore creates a new InstanceStore.

func (*InstanceStore) Count added in v0.0.2

func (s *InstanceStore) Count(ctx context.Context) (int, error)

Count returns the total number of instances.

func (*InstanceStore) Create

func (s *InstanceStore) Create(ctx context.Context, inst *model.Instance) error

Create inserts a new instance.

func (*InstanceStore) Delete

func (s *InstanceStore) Delete(ctx context.Context, port int) error

Delete removes an instance by port.

func (*InstanceStore) EnsureDefaultInstance added in v0.0.2

func (s *InstanceStore) EnsureDefaultInstance(ctx context.Context, proxyPort, metricsPort int) error

EnsureDefaultInstance checks if instances table is empty and seeds it from settings.

func (*InstanceStore) GetByPort

func (s *InstanceStore) GetByPort(ctx context.Context, port int) (*model.Instance, error)

GetByPort returns a single instance by port.

func (*InstanceStore) List

func (s *InstanceStore) List(ctx context.Context) ([]model.Instance, error)

List returns all instances.

type Manifest added in v0.0.10

type Manifest struct {
	FormatVersion int      `json:"format_version"`
	AppVersion    string   `json:"app_version"`
	AppCommit     string   `json:"app_commit"`
	SchemaVersion int      `json:"schema_version"`
	CreatedAt     string   `json:"created_at"`
	Encryption    string   `json:"encryption"` // "aes-gcm" or "none"
	Tables        []string `json:"tables,omitempty"`
}

Manifest represents the backup manifest metadata.

type QuotaAlertStore

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

QuotaAlertStore handles quota alert deduplication.

func NewQuotaAlertStore

func NewQuotaAlertStore(db *sql.DB) *QuotaAlertStore

NewQuotaAlertStore creates a new QuotaAlertStore.

func (*QuotaAlertStore) ClearForLabel

func (s *QuotaAlertStore) ClearForLabel(ctx context.Context, label string) error

ClearForLabel removes quota alerts when traffic is reset.

func (*QuotaAlertStore) MarkAlerted

func (s *QuotaAlertStore) MarkAlerted(ctx context.Context, label string, percent int) error

MarkAlerted records that a quota alert was sent.

func (*QuotaAlertStore) WasAlerted

func (s *QuotaAlertStore) WasAlerted(ctx context.Context, label string, percent int) (bool, error)

WasAlerted checks if a quota alert was already sent for this label+percent combo.

type SchedulerStore added in v0.0.10

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

SchedulerStore handles scheduler persistence.

func NewSchedulerStore added in v0.0.10

func NewSchedulerStore(db *sql.DB) *SchedulerStore

NewSchedulerStore creates a new SchedulerStore.

func (*SchedulerStore) CleanOldHistory added in v0.0.10

func (s *SchedulerStore) CleanOldHistory(ctx context.Context, maxAge time.Duration) error

CleanOldHistory removes execution records older than maxAge.

func (*SchedulerStore) DeleteOverride added in v0.0.10

func (s *SchedulerStore) DeleteOverride(ctx context.Context, taskName string) error

DeleteOverride removes a task override (revert to default).

func (*SchedulerStore) GetLatestHistory added in v0.0.10

func (s *SchedulerStore) GetLatestHistory(ctx context.Context, taskName string) (*scheduler.ExecutionRecord, error)

GetLatestHistory returns the most recent execution record for a task.

func (*SchedulerStore) GetOverride added in v0.0.10

func (s *SchedulerStore) GetOverride(ctx context.Context, taskName string) (*scheduler.TaskOverride, error)

GetOverride returns a single task override.

func (*SchedulerStore) GetOverrides added in v0.0.10

func (s *SchedulerStore) GetOverrides(ctx context.Context) ([]scheduler.TaskOverride, error)

GetOverrides returns all task overrides.

func (*SchedulerStore) InsertHistory added in v0.0.10

func (s *SchedulerStore) InsertHistory(ctx context.Context, rec *scheduler.ExecutionRecord) error

InsertHistory persists a task execution record.

func (*SchedulerStore) ListHistory added in v0.0.10

func (s *SchedulerStore) ListHistory(ctx context.Context, limit, offset int) ([]scheduler.ExecutionRecord, error)

ListHistory returns recent execution history for all tasks.

func (*SchedulerStore) ListHistoryByTask added in v0.0.10

func (s *SchedulerStore) ListHistoryByTask(ctx context.Context, taskName string, limit, offset int) ([]scheduler.ExecutionRecord, error)

ListHistoryByTask returns recent execution history for a specific task.

func (*SchedulerStore) UpsertOverride added in v0.0.10

func (s *SchedulerStore) UpsertOverride(ctx context.Context, o *scheduler.TaskOverride) error

UpsertOverride inserts or updates a task override.

type SecretStore

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

SecretStore handles secret persistence in SQLite.

func NewSecretStore

func NewSecretStore(db *sql.DB) *SecretStore

NewSecretStore creates a new SecretStore.

func (*SecretStore) Archive added in v0.0.10

func (s *SecretStore) Archive(ctx context.Context, label string) error

Archive sets archived_at on a secret, effectively hiding it.

func (*SecretStore) BulkExtendExpiry added in v0.0.10

func (s *SecretStore) BulkExtendExpiry(ctx context.Context, labels []string, expiresAt string, reenable bool) (int, error)

BulkExtendExpiry extends expiry for multiple labels by setting a new date.

func (*SecretStore) BulkRotateKeys added in v0.0.10

func (s *SecretStore) BulkRotateKeys(ctx context.Context, labels []string, keys map[string]string) (int, error)

BulkRotateKeys rotates keys for multiple labels.

func (*SecretStore) BulkSetLimits added in v0.0.10

func (s *SecretStore) BulkSetLimits(ctx context.Context, labels []string, maxConns, maxIPs int, quotaBytes int64, expiresAt string) (int, error)

BulkSetLimits sets the same limits for multiple secrets by labels.

func (*SecretStore) BulkToggleEnabled added in v0.0.10

func (s *SecretStore) BulkToggleEnabled(ctx context.Context, labels []string, enable bool) (int, error)

BulkToggleEnabled enables or disables multiple secrets by labels.

func (*SecretStore) CloneSecret added in v0.0.10

func (s *SecretStore) CloneSecret(ctx context.Context, srcLabel, newLabel, newKey string) (*model.Secret, error)

CloneSecret creates a copy of an existing secret with a new label.

func (*SecretStore) Count

func (s *SecretStore) Count(ctx context.Context) (int, error)

Count returns total number of secrets.

func (*SecretStore) CountEnabled

func (s *SecretStore) CountEnabled(ctx context.Context) (int, error)

CountEnabled returns the count of enabled secrets.

func (*SecretStore) CountEnabledByLabels added in v0.0.10

func (s *SecretStore) CountEnabledByLabels(ctx context.Context, labels []string) (int, error)

CountEnabledByLabels returns the count of enabled secrets among the given labels.

func (*SecretStore) Create

func (s *SecretStore) Create(ctx context.Context, sec *model.Secret) error

Create inserts a new secret.

func (*SecretStore) Delete

func (s *SecretStore) Delete(ctx context.Context, label string) error

Delete removes a secret by label.

func (*SecretStore) DisableExpired added in v0.0.10

func (s *SecretStore) DisableExpired(ctx context.Context) (int, error)

DisableExpired disables all secrets whose expiry is in the past. Returns the number of secrets disabled. Never disables the last enabled secret.

func (*SecretStore) ExtendExpiry added in v0.0.10

func (s *SecretStore) ExtendExpiry(ctx context.Context, label, expiresAt string, reenable bool) error

ExtendExpiry sets a new expiry date for a secret, optionally re-enabling it.

func (*SecretStore) GetByLabel

func (s *SecretStore) GetByLabel(ctx context.Context, label string) (*model.Secret, error)

GetByLabel returns a single secret by label.

func (*SecretStore) LabelsByTag added in v0.0.10

func (s *SecretStore) LabelsByTag(ctx context.Context, tag string) ([]string, error)

LabelsByTag returns labels of secrets that have the given tag.

func (*SecretStore) List

func (s *SecretStore) List(ctx context.Context) ([]model.Secret, error)

List returns all secrets, optionally with traffic data.

func (*SecretStore) ListAllTags added in v0.0.10

func (s *SecretStore) ListAllTags(ctx context.Context) ([]string, error)

ListAllTags returns all unique tags across all secrets.

func (*SecretStore) ListByTag added in v0.0.10

func (s *SecretStore) ListByTag(ctx context.Context, tag string) ([]model.Secret, error)

ListByTag returns secrets that contain the given tag.

func (*SecretStore) ListEnabledLabels

func (s *SecretStore) ListEnabledLabels(ctx context.Context) ([]string, error)

ListEnabledLabels returns labels of all enabled secrets.

func (*SecretStore) RenameLabel added in v0.0.10

func (s *SecretStore) RenameLabel(ctx context.Context, oldLabel, newLabel string) error

RenameLabel changes the label of a secret and its traffic row.

func (*SecretStore) ResetAllTraffic

func (s *SecretStore) ResetAllTraffic(ctx context.Context) error

ResetAllTraffic clears traffic for all users.

func (*SecretStore) ResetTraffic

func (s *SecretStore) ResetTraffic(ctx context.Context, label string) error

ResetTraffic clears traffic for a specific user.

func (*SecretStore) Search added in v0.0.10

func (s *SecretStore) Search(ctx context.Context, query string) ([]model.Secret, error)

Search returns secrets matching a text query in label or notes.

func (*SecretStore) Top added in v0.0.10

func (s *SecretStore) Top(ctx context.Context, limit int) ([]model.Secret, error)

Top returns secrets ordered by total traffic descending.

func (*SecretStore) Unarchive added in v0.0.10

func (s *SecretStore) Unarchive(ctx context.Context, label string) error

Unarchive clears archived_at on a secret.

func (*SecretStore) Update

func (s *SecretStore) Update(ctx context.Context, sec *model.Secret) error

Update modifies an existing secret.

func (*SecretStore) UpdateTags added in v0.0.10

func (s *SecretStore) UpdateTags(ctx context.Context, label, tags string) error

UpdateTags sets the tags string for a secret.

func (*SecretStore) UpdateTraffic

func (s *SecretStore) UpdateTraffic(ctx context.Context, label string, deltaIn, deltaOut int64) error

UpdateTraffic increments the traffic counter for a user.

type SettingsStore

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

SettingsStore handles settings persistence.

func NewSettingsStore

func NewSettingsStore(db *sql.DB) *SettingsStore

NewSettingsStore creates a new SettingsStore.

func (*SettingsStore) Get

func (s *SettingsStore) Get(ctx context.Context, key string) (string, error)

Get reads a single setting value.

func (*SettingsStore) GetAuthPasswordHash

func (s *SettingsStore) GetAuthPasswordHash(ctx context.Context) (string, error)

GetAuthPasswordHash returns the stored bcrypt password hash.

func (*SettingsStore) GetJWTSecret

func (s *SettingsStore) GetJWTSecret(ctx context.Context) (string, error)

GetJWTSecret returns the JWT signing secret, generating one if empty.

func (*SettingsStore) Load

func (s *SettingsStore) Load(ctx context.Context) (*model.Settings, error)

Load reads all settings from the database into a Settings struct.

func (*SettingsStore) Save

func (s *SettingsStore) Save(ctx context.Context, updates map[string]string) error

Save writes a partial set of settings to the database.

func (*SettingsStore) SetAuthPasswordHash

func (s *SettingsStore) SetAuthPasswordHash(ctx context.Context, hash string) error

SetAuthPasswordHash stores the bcrypt password hash.

type SlaveStore

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

SlaveStore handles replication slave persistence.

func NewSlaveStore

func NewSlaveStore(db *sql.DB) *SlaveStore

NewSlaveStore creates a new SlaveStore.

func (*SlaveStore) Create

func (s *SlaveStore) Create(ctx context.Context, sl *model.Slave) error

Create inserts a new slave.

func (*SlaveStore) Delete

func (s *SlaveStore) Delete(ctx context.Context, host string) error

Delete removes a slave by host.

func (*SlaveStore) GetByHost

func (s *SlaveStore) GetByHost(ctx context.Context, host string) (*model.Slave, error)

GetByHost returns a single slave by host.

func (*SlaveStore) List

func (s *SlaveStore) List(ctx context.Context) ([]model.Slave, error)

List returns all slaves.

func (*SlaveStore) UpdateStatus

func (s *SlaveStore) UpdateStatus(ctx context.Context, host, status string, lastSync int64) error

UpdateStatus updates a slave's sync status.

type TemplateStore added in v0.0.10

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

TemplateStore handles secret template persistence.

func NewTemplateStore added in v0.0.10

func NewTemplateStore(db *sql.DB) *TemplateStore

NewTemplateStore creates a new TemplateStore.

func (*TemplateStore) Create added in v0.0.10

Create inserts a new template.

func (*TemplateStore) Delete added in v0.0.10

func (s *TemplateStore) Delete(ctx context.Context, name string) error

Delete removes a template by name.

func (*TemplateStore) GetByName added in v0.0.10

func (s *TemplateStore) GetByName(ctx context.Context, name string) (*model.SecretTemplate, error)

GetByName returns a template by name.

func (*TemplateStore) List added in v0.0.10

List returns all templates.

type TokenBlocklistStore

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

TokenBlocklistStore handles JWT token revocation.

func NewTokenBlocklistStore

func NewTokenBlocklistStore(db *sql.DB) *TokenBlocklistStore

NewTokenBlocklistStore creates a new TokenBlocklistStore.

func (*TokenBlocklistStore) Add

func (s *TokenBlocklistStore) Add(ctx context.Context, jti string, expiresAt int64) error

Add adds a token JTI to the blocklist.

func (*TokenBlocklistStore) Cleanup

func (s *TokenBlocklistStore) Cleanup(ctx context.Context) error

Cleanup removes expired entries from the blocklist.

func (*TokenBlocklistStore) IsBlocked

func (s *TokenBlocklistStore) IsBlocked(ctx context.Context, jti string) (bool, error)

IsBlocked checks if a token JTI is in the blocklist.

type TrafficStore

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

TrafficStore handles cumulative traffic persistence.

func NewTrafficStore

func NewTrafficStore(db *sql.DB) *TrafficStore

NewTrafficStore creates a new TrafficStore.

func (*TrafficStore) CleanOldHistory added in v0.0.10

func (s *TrafficStore) CleanOldHistory(ctx context.Context, maxAge time.Duration) error

CleanOldHistory deletes traffic history records older than maxAge.

func (*TrafficStore) FlushTraffic

func (s *TrafficStore) FlushTraffic(ctx context.Context, global model.TrafficSnapshot, users map[string]model.TrafficSnapshot) error

FlushTraffic persists all traffic deltas in a single transaction.

func (*TrafficStore) GetAggregatedHistory added in v0.0.10

func (s *TrafficStore) GetAggregatedHistory(ctx context.Context, start, end int64, label string, groupSeconds int64) ([]model.TrafficHistoryRecord, error)

GetAggregatedHistory returns traffic history aggregated by hour or day.

func (*TrafficStore) GetAllUserSnapshots added in v0.0.4

func (s *TrafficStore) GetAllUserSnapshots(ctx context.Context) (map[string][2]int64, error)

GetAllUserSnapshots returns all user snapshots in a single query.

func (*TrafficStore) GetGlobal

func (s *TrafficStore) GetGlobal(ctx context.Context) (*model.TrafficSnapshot, error)

GetGlobal returns cumulative global traffic.

func (*TrafficStore) GetHistory added in v0.0.10

func (s *TrafficStore) GetHistory(ctx context.Context, start, end int64, label string) ([]model.TrafficHistoryRecord, error)

GetHistory returns traffic history records for the given time range and label.

func (*TrafficStore) GetUserSnapshot

func (s *TrafficStore) GetUserSnapshot(ctx context.Context, label string) (snapIn, snapOut int64, err error)

GetUserSnapshot returns the raw Prometheus snapshot for a user.

func (*TrafficStore) GetUserTraffic

func (s *TrafficStore) GetUserTraffic(ctx context.Context, label string) (*model.UserTraffic, error)

GetUserTraffic returns traffic for a specific user.

func (*TrafficStore) InsertHistoryBatch added in v0.0.10

func (s *TrafficStore) InsertHistoryBatch(ctx context.Context, ts int64, globalIn, globalOut int64, users map[string][2]int64) error

InsertHistoryBatch persists traffic deltas as history records in a single transaction.

func (*TrafficStore) ListUserTraffic

func (s *TrafficStore) ListUserTraffic(ctx context.Context) ([]model.UserTraffic, error)

ListUserTraffic returns all per-user traffic stats.

func (*TrafficStore) ResetGlobal

func (s *TrafficStore) ResetGlobal(ctx context.Context) error

ResetGlobal clears global traffic counters.

func (*TrafficStore) UpdateGlobal

func (s *TrafficStore) UpdateGlobal(ctx context.Context, deltaIn, deltaOut, snapIn, snapOut int64) error

UpdateGlobal adds deltas to global traffic and updates the snapshot.

func (*TrafficStore) UpdateUserTraffic

func (s *TrafficStore) UpdateUserTraffic(ctx context.Context, label string, deltaIn, deltaOut, snapIn, snapOut int64) error

UpdateUserTraffic adds deltas to a user's traffic and updates the snapshot.

type UpstreamStore

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

UpstreamStore handles upstream persistence.

func NewUpstreamStore

func NewUpstreamStore(db *sql.DB) *UpstreamStore

NewUpstreamStore creates a new UpstreamStore.

func (*UpstreamStore) ClearHealth added in v0.0.10

func (s *UpstreamStore) ClearHealth(ctx context.Context, name string) error

ClearHealth resets all health-related fields to their default values.

func (*UpstreamStore) Create

func (s *UpstreamStore) Create(ctx context.Context, u *model.Upstream) error

Create inserts a new upstream.

func (*UpstreamStore) Delete

func (s *UpstreamStore) Delete(ctx context.Context, name string) error

Delete removes an upstream by name.

func (*UpstreamStore) GetByName

func (s *UpstreamStore) GetByName(ctx context.Context, name string) (*model.Upstream, error)

GetByName returns a single upstream by name.

func (*UpstreamStore) List

func (s *UpstreamStore) List(ctx context.Context) ([]model.Upstream, error)

List returns all upstreams.

func (*UpstreamStore) ListEnabled added in v0.0.10

func (s *UpstreamStore) ListEnabled(ctx context.Context) ([]model.Upstream, error)

ListEnabled returns only enabled upstreams.

func (*UpstreamStore) Update added in v0.0.7

func (s *UpstreamStore) Update(ctx context.Context, name string, u *model.Upstream) error

Update modifies an existing upstream identified by name.

func (*UpstreamStore) UpdateEnabled

func (s *UpstreamStore) UpdateEnabled(ctx context.Context, name string, enabled bool) error

UpdateEnabled toggles an upstream's enabled state.

func (*UpstreamStore) UpdateHealth added in v0.0.10

func (s *UpstreamStore) UpdateHealth(ctx context.Context, name string, ok bool, latencyMs int64, errMsg string) error

UpdateHealth updates health status fields for an upstream.

Jump to

Keyboard shortcuts

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