db

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBPath

func DBPath() (string, error)

DBPath returns the path to the database file

func DecodeTags added in v1.0.4

func DecodeTags(raw string) []string

DecodeTags decodes tags from DB storage (JSON preferred, comma fallback).

func Delete

func Delete() error

Delete removes the database file (destructive).

func EncodeTags added in v1.0.4

func EncodeTags(tags []string) (string, error)

EncodeTags encodes canonical tags for DB storage.

func Exists

func Exists() (bool, error)

Exists checks if the database file exists

func NormalizeTagToken added in v1.0.4

func NormalizeTagToken(token string) string

NormalizeTagToken converts a raw tag token to canonical lowercase alphanumeric form.

func NormalizeTags added in v1.0.4

func NormalizeTags(tags []string) []string

NormalizeTags normalizes and de-duplicates tag tokens.

func ParseTagInput added in v1.0.4

func ParseTagInput(input string) []string

ParseTagInput parses comma-separated user input into canonical tags.

Types

type GroupModel added in v1.0.2

type GroupModel struct {
	Name      string
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

GroupModel represents a named group used to organize hosts. Groups are identified by Name (case-insensitive uniqueness in DB). Deleted groups are tombstoned via DeletedAt and may be garbage collected later.

type HostModel

type HostModel struct {
	ID            int
	Label         string
	GroupName     string
	Tags          []string
	Hostname      string
	Username      string
	Port          int
	KeyData       string // Encrypted blob
	KeyType       string
	CreatedAt     time.Time
	UpdatedAt     time.Time
	LastConnected *time.Time
}

HostModel mirrors the Host struct but for DB interactions

type MountState

type MountState struct {
	HostID     int
	LocalPath  string
	RemotePath string
	MountedAt  time.Time
}

type Store

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

Store handles database operations

func Init

func Init(password string) (*Store, error)

Init opens the database and initializes the schema. It derives the master key from the password and uses it for SQLCipher encryption.

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection

func (*Store) CreateHost

func (s *Store) CreateHost(h *HostModel, plainKey string) error

CreateHost adds a new host

func (*Store) CreateHostWithID

func (s *Store) CreateHostWithID(h *HostModel, encryptedKeyData string) error

CreateHostWithID creates a host with a specific ID (used for sync import). The keyData should already be encrypted.

func (*Store) DeleteAllMountStates

func (s *Store) DeleteAllMountStates() error

func (*Store) DeleteGroup added in v1.0.2

func (s *Store) DeleteGroup(name string) error

DeleteGroup tombstones a group and ungroups all hosts assigned to it.

func (*Store) DeleteHost

func (s *Store) DeleteHost(id int) error

DeleteHost deletes a host

func (*Store) DeleteMountState

func (s *Store) DeleteMountState(hostID int) error

func (*Store) GetGroups added in v1.0.2

func (s *Store) GetGroups() ([]string, error)

GetGroups returns all non-deleted groups (names only), ordered alphabetically.

func (*Store) GetGroupsForSync added in v1.0.2

func (s *Store) GetGroupsForSync(retention time.Duration) ([]GroupModel, error)

GetGroupsForSync returns groups including recent tombstones. Tombstones older than retention are excluded (they should be garbage-collected separately).

func (*Store) GetHostByID added in v1.0.5

func (s *Store) GetHostByID(id int) (*HostModel, error)

GetHostByID returns one host by stable integer ID.

func (*Store) GetHostKey

func (s *Store) GetHostKey(id int) (string, error)

GetHostKey retrieves the decrypted private key for a host. Deprecated: use GetHostSecret when reading host auth secrets.

func (*Store) GetHostSecret added in v1.0.3

func (s *Store) GetHostSecret(id int) (string, error)

GetHostSecret retrieves decrypted key_data for a host. For key auth this is the private key; for password auth this is the stored password.

func (*Store) GetHosts

func (s *Store) GetHosts() ([]HostModel, error)

GetHosts returns all hosts

func (*Store) GetMountStates

func (s *Store) GetMountStates() ([]MountState, error)

func (*Store) GetSalt

func (s *Store) GetSalt() (string, error)

GetSalt returns the encryption salt for this database (hex encoded)

func (*Store) PurgeDeletedGroups added in v1.0.2

func (s *Store) PurgeDeletedGroups(olderThan time.Duration) error

PurgeDeletedGroups permanently removes tombstoned groups older than the given age.

func (*Store) ReencryptKeyData

func (s *Store) ReencryptKeyData(encryptedData string, sourceSaltHex string, password string) (string, error)

ReencryptKeyData decrypts key data using a source salt and re-encrypts with local salt. This is used during sync import when the source database had a different salt.

func (*Store) RenameGroup added in v1.0.2

func (s *Store) RenameGroup(oldName, newName string) error

RenameGroup renames a group and moves any hosts assigned to it. The old name is tombstoned so the deletion propagates via sync.

func (*Store) UpdateHost

func (s *Store) UpdateHost(h *HostModel) error

UpdateHost updates a host's metadata (without changing the key)

func (*Store) UpdateHostFromSync

func (s *Store) UpdateHostFromSync(h *HostModel, encryptedKeyData string, updatedAt time.Time) error

UpdateHostFromSync updates a host with sync data, preserving exact timestamps. The keyData should already be encrypted.

func (*Store) UpdateHostWithKey

func (s *Store) UpdateHostWithKey(h *HostModel, plainKey string) error

UpdateHostWithKey updates a host including the encrypted key data

func (*Store) UpdateLastConnected

func (s *Store) UpdateLastConnected(id int) error

UpdateLastConnected updates the last_connected timestamp for a host

func (*Store) UpsertGroup added in v1.0.2

func (s *Store) UpsertGroup(name string) error

UpsertGroup creates or revives a group, updating timestamps.

func (*Store) UpsertGroupFromSync added in v1.0.2

func (s *Store) UpsertGroupFromSync(name string, createdAt, updatedAt time.Time, deletedAt *time.Time) error

UpsertGroupFromSync applies group state from a sync payload, preserving timestamps. If deletedAt is non-nil, hosts assigned to the group are ungrouped (hosts updated_at is set to now).

func (*Store) UpsertMountState

func (s *Store) UpsertMountState(hostID int, localPath, remotePath string) error

Jump to

Keyboard shortcuts

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