projectarchive

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package projectarchive reads and writes the .lrx project archive: a gzip tar holding declarative spec files, optional encrypted secrets and optional data dumps, sealed by a manifest of checksums.

Index

Constants

View Source
const (
	FormatVersion = 2
	FormatKind    = "levelrail.project-archive"
	ManifestName  = "manifest.json"
	SecretsName   = "secrets.enc"
	SpecPrefix    = "spec/"
	DataPrefix    = "data/"
)

Format identifiers written into every manifest.

View Source
const (
	MinPassphraseFloor = 12
)

MinPassphraseFloor is the shortest passphrase, in characters, no setting can lower.

Variables

View Source
var (
	ErrChecksum = errors.New("projectarchive: checksum mismatch, the archive was changed or damaged")
	ErrFormat   = errors.New("projectarchive: not a project archive or an unsupported format version")
)

Errors a caller can map to a response.

View Source
var ErrManifestMismatch = errors.New("projectarchive: wrong passphrase, or the sealed secrets do not belong to this archive")

ErrManifestMismatch means the sealed secrets do not belong to this manifest.

View Source
var ErrWrongPassphrase = errors.New("projectarchive: wrong passphrase or damaged secrets")

ErrWrongPassphrase covers a wrong passphrase and a damaged secrets blob, which AES-GCM cannot tell apart.

Functions

func FilterForProject

func FilterForProject(files map[string][]byte, project string) (map[string][]byte, []string, error)

FilterForProject keeps only the documents an import may create inside project: its own project, environments, apps and databases, plus the domains, cron jobs, alert rules, pipelines and load balancers of apps contained in the archive, and the tags those apps use. Everything else is returned in skipped as "Kind name" so the plan can show it.

func PassphraseOK

func PassphraseOK(pass string, minLen int) bool

PassphraseOK reports whether pass has at least minLen characters, counted as runes, and never fewer than MinPassphraseFloor.

func RenameProject

func RenameProject(files map[string][]byte, from, to string) (map[string][]byte, error)

RenameProject rewrites the project name in every spec file: the Project document itself and the spec.project reference of the rest.

Types

type Archive

type Archive struct {
	Manifest Manifest
	// Spec maps each spec file name, without the prefix, to its bytes.
	Spec map[string][]byte
	// Secrets is the sealed secrets blob, empty when none were included.
	Secrets []byte
}

Archive is a verified archive. Data entries are checksummed while reading and not kept, a restore streams them from the original file.

func Read

func Read(r io.Reader) (*Archive, error)

Read parses r and verifies the manifest and every checksum. Any extra, missing or altered entry is an error.

func ReadWithLimits

func ReadWithLimits(r io.Reader, lim Limits) (*Archive, error)

ReadWithLimits is Read with caller supplied size limits.

func (*Archive) OpenSecrets

func (a *Archive) OpenSecrets(pass string) ([]byte, error)

OpenSecrets verifies the seal against this archive's manifest, then decrypts the secrets payload.

type FileEntry

type FileEntry struct {
	Name   string `json:"name"`
	SHA256 string `json:"sha256"`
	Size   int64  `json:"size"`
}

FileEntry is one archived file as the manifest records it.

type Limits

type Limits struct {
	// MaxTotalBytes caps the decompressed size of the whole archive.
	MaxTotalBytes int64
	// MaxEntries caps the number of tar entries.
	MaxEntries int64
	// MaxSpecBytes caps the in-memory size of spec and secret entries.
	MaxSpecBytes int64
}

Limits caps what Read accepts. Zero fields fall back to DefaultLimits, so a caller passes only what it overrides; the server fills them from runtime settings.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits are used when a caller sets none, such as the CLI's own check.

type Manifest

type Manifest struct {
	Format          int         `json:"format"`
	Kind            string      `json:"kind"`
	SourceVersion   string      `json:"source_version"`
	Project         string      `json:"project"`
	CreatedAt       string      `json:"created_at"`
	Apps            []string    `json:"apps,omitempty"`
	SecretsIncluded bool        `json:"secrets_included"`
	DataIncluded    bool        `json:"data_included"`
	Warnings        []string    `json:"warnings,omitempty"`
	Files           []FileEntry `json:"files"`
}

Manifest is the last entry of the archive and covers every other entry. Entries under data/ are stored as they came, plaintext, even when secrets are sealed: protect the archive file itself when it holds data.

type SecretPayload

type SecretPayload struct {
	Secrets map[string]string `json:"secrets"`
	Vars    map[string]string `json:"vars,omitempty"`
}

SecretPayload is what secrets.enc holds once opened: stored secret values keyed "app/NAME", and ${{ env.NAME }} placeholder values keyed by name.

type Writer

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

Writer streams entries into a gzip tar and finishes with the manifest.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter starts an archive on w.

func (*Writer) AddBytes

func (w *Writer) AddBytes(name string, b []byte) error

AddBytes writes one small entry.

func (*Writer) AddStream

func (w *Writer) AddStream(name string, r io.Reader) error

AddStream spools r to a temp file first because a tar header needs the size, then copies it in, so a large dump never sits in memory.

func (*Writer) Close

func (w *Writer) Close(m Manifest) error

Close writes the manifest last and flushes the archive.

func (*Writer) SetSecrets

func (w *Writer) SetSecrets(pass string, plain []byte)

SetSecrets queues the secrets payload, sealed on Close and bound to the manifest.

Jump to

Keyboard shortcuts

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