snapshots

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package snapshots manages point-in-time snapshots of deployed services, capturing the Docker image tag, environment variables, and resource config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateRequest

type CreateRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

CreateRequest holds the user-supplied fields for creating a snapshot.

type ListFilter

type ListFilter struct {
	ServiceID string // exact match on service_id
	Name      string // substring match on name (LIKE %name%)
	Since     int64  // filter created_at >= since (unix timestamp)
}

ListFilter holds optional filter parameters for listing snapshots.

type Manager

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

Manager provides snapshot CRUD backed by SQLite and Docker.

func NewManager

func NewManager(db *sql.DB, docker docker.Client, masterKey []byte) *Manager

NewManager creates a snapshot Manager.

func (*Manager) CleanExpired

func (m *Manager) CleanExpired(ctx context.Context, maxPerService int, maxAge time.Duration) (int, error)

CleanExpired removes snapshots that exceed per-service count or age limits. It deletes the oldest snapshots first when over the count limit and removes any snapshot older than maxAge. Returns the number of snapshots removed.

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, tenantID, serviceID string, req CreateRequest) (*Snapshot, error)

Create captures a snapshot from a running service. It tags the service's Docker image, copies encrypted env vars, and stores resource config.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, tenantID, snapshotID string) error

Delete removes a snapshot and attempts to untag the associated Docker image.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, tenantID, snapshotID string) (*Snapshot, error)

Get returns a single snapshot, verifying tenant ownership.

func (*Manager) GetEnvKeys

func (m *Manager) GetEnvKeys(ctx context.Context, tenantID, snapshotID string) (map[string]string, error)

GetEnvKeys returns the env var keys stored in a snapshot with masked values. This allows callers to see which env vars exist without revealing their values.

func (*Manager) List

func (m *Manager) List(ctx context.Context, tenantID string, limit, offset int, filter *ListFilter) ([]*Snapshot, error)

List returns snapshots for a tenant with pagination and optional filters.

func (*Manager) RestoreEnvVars

func (m *Manager) RestoreEnvVars(ctx context.Context, tenantID, snapshotID string) (map[string]string, error)

RestoreEnvVars decrypts and returns the environment variables stored in a snapshot. Requires tenantID for tenant isolation — never call without it.

type Snapshot

type Snapshot struct {
	ID             string `json:"id"`
	TenantID       string `json:"tenant_id"`
	ServiceID      string `json:"service_id"`
	Name           string `json:"name"`
	Description    string `json:"description,omitempty"`
	ImageRef       string `json:"image_ref"`
	ResourceConfig string `json:"resource_config,omitempty"`
	Port           int    `json:"port"`
	CreatedAt      int64  `json:"created_at"`
}

Snapshot represents a point-in-time capture of a service's image, port, and resource configuration.

Jump to

Keyboard shortcuts

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