Documentation
¶
Overview ¶
Package exportpkg is the format of an export package: a directory (or archive) with a manifest, one JSON Lines file per collection in the API representation, the files the documents reference and the wrapped keys of encrypted fields. The server streams the parts and the CLI writes them; import reads them back.
Index ¶
- Constants
- func AuthPart(collection string) string
- func CollectionPart(database, collection string) string
- func DecodeDocument(line []byte) (map[string]any, error)
- func EncodeDocument(doc map[string]any) ([]byte, error)
- func FilePart(database, fileID string) string
- func ReadDocuments(r io.Reader, fn func(line int, doc map[string]any) error) error
- func SafePart(p string) bool
- func Select(doc map[string]any, paths []string) map[string]any
- func WriteCSV(src io.ReadSeeker, w io.Writer, fields []string) (int64, error)
- type Collection
- type Database
- type EncryptedField
- type Exclusion
- type Flags
- type Hasher
- type Manifest
Constants ¶
const ( ManifestName = "manifest.json" DataKeysName = "_system/data_keys.jsonl" FilesDir = "_files" )
Fixed names inside a package.
const ( FormCiphertext = "ciphertext" FormPlaintext = "plaintext" )
Form says whether an encrypted field's values travel as they are stored or decrypted.
const FormatVersion = 1
FormatVersion is the version of the package layout; import refuses other versions.
Variables ¶
This section is empty.
Functions ¶
func CollectionPart ¶
CollectionPart is the package path of a collection's documents.
func DecodeDocument ¶
DecodeDocument reads a line EncodeDocument wrote: integers come back as int64, other numbers as float64, and Extended JSON dates and binary as time.Time and []byte (an encrypted value, binary of subtype 6, as fieldcrypt.Ciphertext).
func EncodeDocument ¶
EncodeDocument renders a document as one line of JSON in the API representation, with typed values in MongoDB Extended JSON (relaxed): a date is {"$date": "…"}, binary is {"$binary": {"base64": "…", "subType": "00"}}. The line has no newline.
func ReadDocuments ¶
ReadDocuments calls fn with every document of a JSON Lines stream, with its line number.
func SafePart ¶
SafePart reports whether a package path is one this package would write: relative, with no dot segments, so a hostile archive or manifest can't name a file outside the package.
func Select ¶
Select keeps of a document its id and the given field paths ("a", "a.b", "_meta.owner"): a path naming an object keeps all of it, one that is missing in the document adds nothing. "_meta" is only present when a path asks for it.
func WriteCSV ¶
WriteCSV turns a JSON Lines stream of documents into one RFC 4180 table, and returns how many rows it wrote. The columns are the union of every document's flattened paths: nested objects become "a.b" columns, `_meta` becomes "_meta.owner" and so on, arrays become JSON text in one cell, dates RFC 3339 text, binary values (ciphertext) base64 text, null and missing empty. "id" comes first; then the columns of fields in the order given (all of them, sorted, when none is), `_meta` last. It reads the stream twice (columns, then rows), so the source must seek. A text cell that a spreadsheet would run as a formula (it starts with =, +, - or @) gets a leading apostrophe.
Types ¶
type Collection ¶
type Collection struct {
Name string `json:"name"`
Documents int64 `json:"documents"`
Part string `json:"part"`
// SchemaVersion is the collection's current schema version when it was exported (collections
// with versioned schema files); each document's own is its _meta.schema_version.
SchemaVersion int `json:"schema_version,omitempty"`
}
Collection is a collection in a package: its part and how many documents it holds.
type Database ¶
type Database struct {
Name string `json:"name"`
Collections []Collection `json:"collections"`
}
Database is a database of the realm in a package.
type EncryptedField ¶
type EncryptedField struct {
Database string `json:"database"`
Collection string `json:"collection"`
Path string `json:"path"`
Key string `json:"key"`
Fingerprint string `json:"fingerprint"`
Form string `json:"form"`
}
EncryptedField records an encrypted field and whether the package holds it as ciphertext or decrypted.
type Exclusion ¶ added in v0.9.2
Exclusion is something a personal data export does not take, with the reason.
type Flags ¶
type Flags struct {
Partial bool `json:"partial"`
Anonymized bool `json:"anonymized"`
Auth bool `json:"auth"`
NoFiles bool `json:"no_files"`
// CSV marks a flat reporting extract: lossy, never importable.
CSV bool `json:"csv"`
// Personal marks the export of one user's personal data (always partial: it is not a copy of
// the realm and is never importable).
Personal bool `json:"personal,omitempty"`
}
Flags are the package's properties an import has to respect.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher computes the SHA-256 of what passes through it.
func WriteAtomic ¶ added in v0.9.4
WriteAtomic writes dst through fn: the bytes go to dst+".partial", which replaces dst only when fn and the close succeed, and is removed otherwise. The returned Hasher holds the checksum and size of what fn wrote.
type Manifest ¶
type Manifest struct {
Format int `json:"format"`
BackdVersion string `json:"backd_version"`
Realm string `json:"realm"`
CreatedAt time.Time `json:"created_at"`
Operator string `json:"operator"`
Fingerprint string `json:"config_fingerprint"`
Flags Flags `json:"flags"`
Databases []Database `json:"databases"`
Encrypted []EncryptedField `json:"encrypted_fields"`
Checksums map[string]string `json:"checksums"`
Files int64 `json:"files"`
// Auth lists the authentication data parts (with --include auth); AuthKey is the fingerprint
// of the one-time export key their realm-sealed fields are sealed under.
Auth []Collection `json:"auth,omitempty"`
AuthKey string `json:"auth_key_fingerprint,omitempty"`
// Subject is the user a personal data export is about; Exclusions lists what it leaves out
// and why. Neither is in the export of a realm.
Subject string `json:"subject,omitempty"`
Exclusions []Exclusion `json:"exclusions,omitempty"`
}
Manifest describes a package.
func ParseManifest ¶
ParseManifest reads a manifest and refuses a format this backd doesn't know.