clicore

package
v0.9.14 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 35 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const AdminAPINote = "" /* 130-byte string literal not displayed */

Variables

View Source
var WithHeaders = WithProof

withHeaders is withProof for headers that are not a proof (an export's lease).

Functions

func CiphertextFields

func CiphertextFields(m *exportpkg.Manifest) []string

ciphertextFields lists the encrypted fields a package still holds as ciphertext.

func CopyPackageTree

func CopyPackageTree(src, dst string) error

copyTree copies the files of a directory, readable only by the owner.

func DecryptPackage

func DecryptPackage(dir string, m *exportpkg.Manifest, d *Decryptor) (int, error)

decryptPackage opens, in the package at dir, every field the keys open, and records that in the manifest (form plaintext, new checksums). It returns how many fields it opened.

func HTTPClient

func HTTPClient(getenv func(string) string) (*http.Client, error)

httpClient trusts the system's CAs, plus BACKD_CA_CERT (a PEM file) if set, for servers with a private CA such as the local stack.

func OpenPackage

func OpenPackage(from string) (string, func(), error)

openPackage returns the directory of a package: the path itself, or an archive extracted to a private temporary directory that cleanup removes.

func PackageKeys

func PackageKeys(dir string) (map[string]fieldcrypt.Record, error)

packageKeys reads the wrapped keys of a package, by id.

func ParseFieldKeys

func ParseFieldKeys(spec string, getenv func(string) string, warn io.Writer) ([]*fieldKey, error)

parseFieldKeys reads the value of --field.

func ReadKeyRecords

func ReadKeyRecords(r io.Reader) (map[string]fieldcrypt.Record, error)

func Remote

func Remote(cc *kli.CommandConfig)

remote adds the flags every command that talks to a running backd has.

func ResolveURL

func ResolveURL(flagURL string, getenv func(string) string, creds *Credentials) (string, error)

resolveURL picks the server: --url, BACKD_URL, or the one used last.

func UserAgent

func UserAgent() string

UserAgent is how the CLI introduces itself: backd/<version>. The server compares the version with its own and only says whether it is newer or older; a released server refuses backd/dev.

func VerifyPackage

func VerifyPackage(dir string, stderr io.Writer) (*exportpkg.Manifest, error)

verifyPackage reads the manifest and checks every file it lists against its checksum.

func WithProof

func WithProof(headers map[string]string) []client.RequestOption

withProof turns the header a proof is carried in (or any headers) into request options.

Types

type APIError

type APIError struct {
	Status    int
	Code      string
	Message   string
	Details   []struct{ Path, Reason string }
	RequestID string
	// contains filtered or unexported fields
}

apiError is an error answer from backd as the CLI shows it: its status, code and message, the details and the request id, with a hint when the CLI user can act on it. It wraps the client's error, so errors.Is(err, client.ErrNotFound) and errors.As(err, &*client.Error) work.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

type Credentials

type Credentials struct {
	DefaultURL string                           `json:"default_url,omitempty"`
	Sessions   map[string]map[string]StoredAuth `json:"sessions"`
}

credentials is the CLI's credentials file: sessions per server URL and realm, and the server used last.

func LoadCredentials

func LoadCredentials(getenv func(string) string) (*Credentials, string, error)

func (*Credentials) Save

func (c *Credentials) Save(path string) error

save writes the file readable only by its owner: it holds session tokens.

type Decryptor

type Decryptor struct {

	// opened, by <database>/<collection>, are the fields it opens: only those with a key.
	Opened map[string][]exportpkg.EncryptedField
	// contains filtered or unexported fields
}

decryptor opens, with the keys given, the encrypted fields of a package's documents.

func NewDecryptor

func NewDecryptor(m *exportpkg.Manifest, keys []*fieldKey, data map[string]fieldcrypt.Record) (*Decryptor, error)

newDecryptor matches the keys to the fields of the manifest that are still ciphertext. A key whose fingerprint isn't the field's is an error naming the field and the key; a key that matches no field is an error too (a typo would otherwise leave the data encrypted unnoticed).

func (*Decryptor) Any

func (d *Decryptor) Any() bool

func (*Decryptor) Chunk

func (d *Decryptor) Chunk(database, collection string, chunk []byte) ([]byte, error)

chunk opens the encrypted fields of a chunk of a collection's JSON Lines.

func (*Decryptor) Part

func (d *Decryptor) Part(dir, partPath, database, collection string) (ExportedPart, error)

part rewrites a collection's part of the package with its fields opened, and returns what the part is now.

type ExportedPart

type ExportedPart struct {
	Checksum  string `json:"checksum"`
	Size      int64  `json:"size"`
	Documents int64  `json:"documents,omitempty"`
}

type InProcess

type InProcess struct{ H http.Handler }

inProcess is an http.RoundTripper that hands requests to a handler without a network. The response body streams: the handler runs on its own goroutine and writes into a pipe.

func (InProcess) RoundTrip

func (p InProcess) RoundTrip(req *http.Request) (*http.Response, error)

type StoredAuth

type StoredAuth struct {
	Token     string `json:"token"`
	Email     string `json:"email"`
	ExpiresAt string `json:"expires_at,omitempty"`
}

type Target

type Target struct {
	URL, Realm string

	Ctx    context.Context
	Client *client.Client // 60 seconds for a whole call
	Adm    *adminclient.Admin

	AdmLong *adminclient.Admin

	// Warn receives the one line about a version skew (TargetFor sets the command's stderr).
	Warn io.Writer
	// contains filtered or unexported fields
}

target is a server and realm the CLI talks to, with a credential. Everything it asks of the server goes through the Go client (pkg/client) and, for the administration, internal/adminclient on top of it.

func MakeTarget

func MakeTarget(u, realm, credential string, fromKey bool, hc *http.Client) (*Target, error)

makeTarget builds the clients of a server and realm, signed in with a session token or an API key (neither when credential is empty).

func NewTarget

func NewTarget(flagURL, realm string, getenv func(string) string, sessionOnly bool) (*Target, error)

newTarget resolves server, realm and credential for API commands: an admin API key from BACKD_API_KEY (unless sessionOnly), else the session stored by `backd login` for that server and realm.

func OfflineTarget

func OfflineTarget(u, realm string, hc *http.Client) *Target

offlineTarget is the target of an in-process handler (backd-server's export, import and field key commands): there is no network and no credential, only the handler the transport calls.

func TargetFor

func TargetFor(c *kli.CommandContext, realm string, sessionOnly bool) (*Target, error)

targetFor is targetOf for a realm resolved apart from the --realm flag.

func TargetOf

func TargetOf(c *kli.CommandContext, sessionOnly bool) (*Target, error)

targetOf resolves the server, realm and credential of an API command from its --realm and --url flags.

func (*Target) Proof

func (t *Target) Proof(uio cmdutil.IO) (map[string]string, error)

proof asks the signed-in user for a fresh proof of identity, the strongest they have (their second factor's code, else the password, else a code sent by email), and returns the header that sensitive requests carry. Nothing is asked of an API key, or of a user the server asks nothing of.

Jump to

Keyboard shortcuts

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