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
- Variables
- func FilterForProject(files map[string][]byte, project string) (map[string][]byte, []string, error)
- func PassphraseOK(pass string, minLen int) bool
- func RenameProject(files map[string][]byte, from, to string) (map[string][]byte, error)
- type Archive
- type FileEntry
- type Limits
- type Manifest
- type SecretPayload
- type Writer
Constants ¶
const ( FormatVersion = 2 FormatKind = "levelrail.project-archive" ManifestName = "manifest.json" SecretsName = "secrets.enc" SpecPrefix = "spec/" DataPrefix = "data/" )
Format identifiers written into every manifest.
const (
MinPassphraseFloor = 12
)
MinPassphraseFloor is the shortest passphrase, in characters, no setting can lower.
Variables ¶
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.
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.
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 ¶
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 ¶
PassphraseOK reports whether pass has at least minLen characters, counted as runes, and never fewer than MinPassphraseFloor.
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 ¶
Read parses r and verifies the manifest and every checksum. Any extra, missing or altered entry is an error.
func ReadWithLimits ¶
ReadWithLimits is Read with caller supplied size limits.
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 (*Writer) AddStream ¶
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) SetSecrets ¶
SetSecrets queues the secrets payload, sealed on Close and bound to the manifest.