Documentation
¶
Overview ¶
Package vault manages the on-disk vault layout, secret records, and recipient lists stored inside the Git repository.
Index ¶
- Constants
- Variables
- func AddRecipient(repoRoot string, r Recipient) (err error)
- func IsInitialized(repoRoot string) bool
- func MergeStores(base, ours, theirs *Store) (*Store, []MergeWarning, []MergeConflict)
- func RemoveRecipient(repoRoot, id string) error
- func SaveStore(repoRoot string, s *Store) error
- type Config
- type Entry
- type EntryKind
- type EnvVar
- type MergeConflict
- type MergeWarning
- type Recipient
- type Store
- type StoreChanges
Constants ¶
const DirName = ".envault"
DirName is the vault directory created inside the repository root.
Variables ¶
var ErrAlreadyInitialized = errors.New("vault already initialized (use --force to reinitialize)")
ErrAlreadyInitialized is returned by Init when the vault already exists and force is false.
var ErrRecipientAlreadyExists = errors.New("recipient already exists for this id")
ErrRecipientAlreadyExists is returned by AddRecipient when an entry with the same ID is already present in the recipients file.
var ErrRecipientNotFound = errors.New("recipient not found")
ErrRecipientNotFound is returned by RemoveRecipient when no entry matches the given ID.
Functions ¶
func AddRecipient ¶
AddRecipient appends r to the recipients file inside repoRoot. Returns ErrRecipientAlreadyExists if an entry with the same ID is already present.
func IsInitialized ¶
IsInitialized reports whether a vault directory exists inside repoRoot.
func MergeStores ¶
func MergeStores(base, ours, theirs *Store) (*Store, []MergeWarning, []MergeConflict)
MergeStores performs a secret-level 3-way merge of base, ours, and theirs. Entry identity is (Name, Kind); equality is determined by UpdatedAt timestamp.
Merge rules:
- Only ours added → keep ours
- Only theirs added → keep theirs
- Both added, same UpdatedAt → keep (idempotent)
- Both added, different → conflict
- Only ours changed → keep ours; warn if recipient dropped
- Only theirs changed → keep theirs; warn if recipient dropped
- Both changed to same UpdatedAt → keep
- Both changed differently → conflict
- Ours unchanged, theirs deleted → delete
- Theirs unchanged, ours deleted → delete
- Both deleted → delete
- Ours modified, theirs deleted → conflict
- Theirs modified, ours deleted → conflict
If len(conflicts) > 0, the caller must abort the merge.
func RemoveRecipient ¶
RemoveRecipient removes the entry with the given id from the recipients file. Returns ErrRecipientNotFound if no entry matches.
Types ¶
type Entry ¶
type Entry struct {
Name string `json:"name"`
Kind EntryKind `json:"kind"`
Algorithm envcrypto.CipherSuite `json:"algorithm"`
Recipients []string `json:"recipients"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Envelope *envcrypto.Envelope `json:"envelope"`
}
Entry is one sealed secret or file together with its self-describing metadata: the ciphertext carries its own timestamp, algorithm and recipient set.
type EntryKind ¶
type EntryKind string
EntryKind distinguishes a secret sourced from an env var from an arbitrary file.
type EnvVar ¶
EnvVar is a single key/value pair parsed from a dotenv file.
func ParseDotenv ¶
ParseDotenv parses dotenv content: one KEY=VALUE per line. Blank lines and comments (lines starting with '#') are skipped, an optional leading "export " is honored, and a value wrapped in matching single or double quotes is unquoted. Inline comments are intentionally not stripped so values may contain '#'.
type MergeConflict ¶
MergeConflict describes an entry-level conflict that could not be auto-resolved. The caller must surface this to the user and abort the merge.
type MergeWarning ¶
MergeWarning describes an auto-resolved change that should be surfaced to the user — most commonly a recipient losing access on one side of the merge.
type Recipient ¶
Recipient is a vault member identified by an ID and their X25519 public key.
func ListRecipients ¶
ListRecipients reads all recipients from the recipients file inside repoRoot. Returns an empty slice (not an error) when the file does not exist.
func ParseRecipientLine ¶
ParseRecipientLine parses a "<id> <hex-pubkey>" string as written by AddRecipient and produced by "envault key export --public".
type Store ¶
Store is the on-disk collection of sealed entries (.envault/secrets.enc).
func LoadStore ¶
LoadStore reads the secrets store from repoRoot. It returns an empty store (not an error) when the file does not yet exist.
func ParseStore ¶
ParseStore decodes a JSON-encoded secrets store from raw bytes. Returns an error if the bytes are not valid JSON or the version is unsupported.
func (*Store) Delete ¶
Delete returns a new Store with the entry of the given name and kind removed. If no matching entry exists, the store is returned unchanged. The receiver is never mutated.
type StoreChanges ¶
type StoreChanges struct {
Added []string // entries present in after but not in before
Removed []string // entries present in before but not in after
Rotated []string // entries present in both but with a newer UpdatedAt
}
StoreChanges describes what changed between two snapshots of a Store.
func DiffStores ¶
func DiffStores(before, after *Store) StoreChanges
DiffStores computes what changed between before and after. Comparison is by entry name only (kind is ignored for reporting).
func (StoreChanges) IsEmpty ¶
func (c StoreChanges) IsEmpty() bool
IsEmpty reports whether there are no changes.
func (StoreChanges) Total ¶
func (c StoreChanges) Total() int
Total returns the total number of changed entries.