contract

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package contract defines the recovery contract schema for RestoreLab. A contract describes what to restore, how to restore it, and how to verify it works. Contracts are YAML files parsed into these types.

Index

Constants

View Source
const (
	KiB ByteSize = 1024
	MiB          = 1024 * KiB
	GiB          = 1024 * MiB
)
View Source
const (
	SupportedVersion  = 1
	SupportedProvider = "restic"
	SupportedEngine   = "postgres"
	SupportedFormat   = "custom"
	SupportedNetwork  = "internal"
)

Variables

This section is empty.

Functions

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses durations like "30m", "1h", "90s". Delegates to time.ParseDuration.

Types

type ByteSize

type ByteSize int64

ByteSize is a size in bytes.

func ParseByteSize

func ParseByteSize(s string) (ByteSize, error)

ParseByteSize parses strings like "20GiB", "512MiB", "100MiB". Supported suffixes: KiB, MiB, GiB. No suffix means bytes.

type Check

type Check struct {
	Name   string      `yaml:"name"`
	Type   string      `yaml:"type"`
	Query  string      `yaml:"query"`
	Expect CheckExpect `yaml:"expect"`
}

Check is a single SQL validation step.

type CheckExpect

type CheckExpect struct {
	Value       any    `yaml:"value,omitempty"`
	Type        string `yaml:"type,omitempty"`
	GreaterThan *int   `yaml:"greater_than,omitempty"`
}

CheckExpect describes the expected outcome of a check.

type Cleanup

type Cleanup struct {
	Always        bool `yaml:"always"`
	RemoveVolumes bool `yaml:"remove_volumes"`
	ForceRemove   bool `yaml:"force_remove"`
}

Cleanup describes how to clean up after the test.

type Contract

type Contract struct {
	Version     int       `yaml:"version"`
	Name        string    `yaml:"name"`
	Description string    `yaml:"description,omitempty"`
	Source      Source    `yaml:"source"`
	Restore     Restore   `yaml:"restore"`
	Test        Test      `yaml:"test"`
	Isolation   Isolation `yaml:"isolation"`
	Limits      Limits    `yaml:"limits"`
	Cleanup     Cleanup   `yaml:"cleanup"`
}

Contract is the root of a recovery contract YAML document.

func Parse

func Parse(data []byte) (*Contract, error)

Parse unmarshals YAML bytes into a Contract.

func ParseFile

func ParseFile(path string) (*Contract, error)

ParseFile reads a contract file from disk and parses it. It returns an error if the file cannot be read or if the YAML is malformed. It does NOT validate semantic correctness — call Contract.Validate for that.

func (*Contract) Validate

func (c *Contract) Validate() error

Validate performs strict schema validation on a contract. It returns the first error encountered. It does not check the runtime environment (environment variables, file permissions) — that is done by the preflight package.

type Isolation

type Isolation struct {
	Network              string `yaml:"network"`
	PublishPorts         bool   `yaml:"publish_ports"`
	BlockExternalNetwork bool   `yaml:"block_external_network"`
	InspectOnly          bool   `yaml:"inspect_only,omitempty"`
}

Isolation describes network and sandbox isolation requirements.

type Limits

type Limits struct {
	MaxArtifactSize string `yaml:"max_artifact_size"`
	Timeout         string `yaml:"timeout"`
	Memory          string `yaml:"memory"`
	Pids            int    `yaml:"pids"`
	ShmSize         string `yaml:"shm_size,omitempty"`
}

Limits describes resource constraints for the sandbox.

type Restore

type Restore struct {
	Format string `yaml:"format"`
}

Restore describes the format of the artifact to restore.

type Source

type Source struct {
	Provider        string `yaml:"provider"`
	RepositoryEnv   string `yaml:"repository_env"`
	PasswordFileEnv string `yaml:"password_file_env"`
	Snapshot        string `yaml:"snapshot"`
	Path            string `yaml:"path"`
	NoLock          bool   `yaml:"no_lock,omitempty"`
}

Source describes where the backup lives and how to access it.

type Test

type Test struct {
	Engine         string   `yaml:"engine"`
	Image          string   `yaml:"image"`
	Database       string   `yaml:"database"`
	Username       string   `yaml:"username"`
	PasswordEnv    string   `yaml:"password_env"`
	RestoreOptions []string `yaml:"restore_options,omitempty"`
	Checks         []Check  `yaml:"checks"`
}

Test describes how to validate the restored database.

Jump to

Keyboard shortcuts

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