storage

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package storage provides persistent storage for agent data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InstallationRecord

type InstallationRecord struct {
	Key              string
	AgentID          string
	AgentName        string
	InstallMethod    string
	InstalledVersion string
	LatestVersion    string
	ExecutablePath   string
	InstallPath      string
	FirstDetectedAt  time.Time
	LastCheckedAt    time.Time
	LastUpdatedAt    *time.Time
	Metadata         map[string]string
}

InstallationRecord represents a stored installation record.

func FromInstallation

func FromInstallation(inst *agent.Installation) *InstallationRecord

FromInstallation creates an InstallationRecord from an agent.Installation.

func (*InstallationRecord) ToInstallation

func (r *InstallationRecord) ToInstallation() *agent.Installation

ToInstallation converts an InstallationRecord to an agent.Installation.

type SQLiteStore

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

SQLiteStore implements Store using SQLite.

func NewSQLiteStore

func NewSQLiteStore(dataDir string) (*SQLiteStore, error)

NewSQLiteStore creates a new SQLite store at the given path.

func (*SQLiteStore) ClearDetectionCache

func (s *SQLiteStore) ClearDetectionCache(ctx context.Context) error

ClearDetectionCache removes the detection cache.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close closes the database connection.

func (*SQLiteStore) DeleteInstallation

func (s *SQLiteStore) DeleteInstallation(ctx context.Context, key string) error

DeleteInstallation removes an installation record.

func (*SQLiteStore) DeleteSetting

func (s *SQLiteStore) DeleteSetting(ctx context.Context, key string) error

DeleteSetting removes a setting.

func (*SQLiteStore) GetCatalogCache

func (s *SQLiteStore) GetCatalogCache(ctx context.Context) ([]byte, string, time.Time, error)

GetCatalogCache retrieves the cached catalog.

func (*SQLiteStore) GetDetectionCache

func (s *SQLiteStore) GetDetectionCache(ctx context.Context) ([]*agent.Installation, time.Time, error)

GetDetectionCache retrieves the cached detected agents.

func (*SQLiteStore) GetDetectionCacheTime

func (s *SQLiteStore) GetDetectionCacheTime(ctx context.Context) (time.Time, error)

GetDetectionCacheTime returns when the detection cache was last updated.

func (*SQLiteStore) GetInstallation

func (s *SQLiteStore) GetInstallation(ctx context.Context, key string) (*agent.Installation, error)

GetInstallation retrieves an installation by key.

func (*SQLiteStore) GetLastUpdateCheckTime

func (s *SQLiteStore) GetLastUpdateCheckTime(ctx context.Context) (time.Time, error)

GetLastUpdateCheckTime returns when updates were last checked.

func (*SQLiteStore) GetSetting

func (s *SQLiteStore) GetSetting(ctx context.Context, key string) (string, error)

GetSetting retrieves a setting value.

func (*SQLiteStore) GetUpdateHistory

func (s *SQLiteStore) GetUpdateHistory(ctx context.Context, agentID string, limit int) ([]*UpdateEvent, error)

GetUpdateHistory retrieves update history for an agent.

func (*SQLiteStore) Initialize

func (s *SQLiteStore) Initialize(ctx context.Context) error

Initialize opens the database and runs migrations.

func (*SQLiteStore) ListInstallations

func (s *SQLiteStore) ListInstallations(ctx context.Context, filter *agent.Filter) ([]*agent.Installation, error)

ListInstallations returns all installations matching the filter.

func (*SQLiteStore) SaveCatalogCache

func (s *SQLiteStore) SaveCatalogCache(ctx context.Context, data []byte, etag string) error

SaveCatalogCache stores the catalog cache.

func (*SQLiteStore) SaveDetectionCache

func (s *SQLiteStore) SaveDetectionCache(ctx context.Context, installations []*agent.Installation) error

SaveDetectionCache stores the detected agents cache.

func (*SQLiteStore) SaveInstallation

func (s *SQLiteStore) SaveInstallation(ctx context.Context, inst *agent.Installation) error

SaveInstallation saves or updates an installation record.

func (*SQLiteStore) SaveUpdateEvent

func (s *SQLiteStore) SaveUpdateEvent(ctx context.Context, event *UpdateEvent) error

SaveUpdateEvent records an update event.

func (*SQLiteStore) SetLastUpdateCheckTime

func (s *SQLiteStore) SetLastUpdateCheckTime(ctx context.Context, t time.Time) error

SetLastUpdateCheckTime stores when updates were last checked.

func (*SQLiteStore) SetSetting

func (s *SQLiteStore) SetSetting(ctx context.Context, key, value string) error

SetSetting stores a setting value.

type Store

type Store interface {
	// Initialize sets up the database and runs migrations.
	Initialize(ctx context.Context) error

	// Close closes the storage connection.
	Close() error

	// Installation operations
	SaveInstallation(ctx context.Context, inst *agent.Installation) error
	GetInstallation(ctx context.Context, key string) (*agent.Installation, error)
	ListInstallations(ctx context.Context, filter *agent.Filter) ([]*agent.Installation, error)
	DeleteInstallation(ctx context.Context, key string) error

	// Update history operations
	SaveUpdateEvent(ctx context.Context, event *UpdateEvent) error
	GetUpdateHistory(ctx context.Context, agentID string, limit int) ([]*UpdateEvent, error)

	// Catalog cache operations
	SaveCatalogCache(ctx context.Context, data []byte, etag string) error
	GetCatalogCache(ctx context.Context) ([]byte, string, time.Time, error)

	// Detection cache operations
	SaveDetectionCache(ctx context.Context, installations []*agent.Installation) error
	GetDetectionCache(ctx context.Context) ([]*agent.Installation, time.Time, error)
	ClearDetectionCache(ctx context.Context) error
	GetDetectionCacheTime(ctx context.Context) (time.Time, error)
	SetLastUpdateCheckTime(ctx context.Context, t time.Time) error
	GetLastUpdateCheckTime(ctx context.Context) (time.Time, error)

	// Settings operations
	GetSetting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, key, value string) error
	DeleteSetting(ctx context.Context, key string) error
}

Store defines the storage interface for agent data.

type UpdateEvent

type UpdateEvent struct {
	ID            int64
	AgentID       string
	AgentName     string
	InstallMethod string
	FromVersion   string
	ToVersion     string
	Status        UpdateStatus
	ErrorMessage  string
	StartedAt     time.Time
	CompletedAt   *time.Time
}

UpdateEvent represents a recorded update event.

type UpdateStatus

type UpdateStatus string

UpdateStatus represents the status of an update.

const (
	UpdateStatusPending   UpdateStatus = "pending"
	UpdateStatusRunning   UpdateStatus = "running"
	UpdateStatusCompleted UpdateStatus = "completed"
	UpdateStatusFailed    UpdateStatus = "failed"
	UpdateStatusCancelled UpdateStatus = "cancelled"
)

Jump to

Keyboard shortcuts

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