Documentation
¶
Index ¶
- Constants
- Variables
- func CiphertextFields(m *exportpkg.Manifest) []string
- func CopyPackageTree(src, dst string) error
- func DecryptPackage(dir string, m *exportpkg.Manifest, d *Decryptor) (int, error)
- func HTTPClient(getenv func(string) string) (*http.Client, error)
- func OpenPackage(from string) (string, func(), error)
- func PackageKeys(dir string) (map[string]fieldcrypt.Record, error)
- func ParseFieldKeys(spec string, getenv func(string) string, warn io.Writer) ([]*fieldKey, error)
- func ReadKeyRecords(r io.Reader) (map[string]fieldcrypt.Record, error)
- func Remote(cc *kli.CommandConfig)
- func ResolveURL(flagURL string, getenv func(string) string, creds *Credentials) (string, error)
- func UserAgent() string
- func VerifyPackage(dir string, stderr io.Writer) (*exportpkg.Manifest, error)
- func WithProof(headers map[string]string) []client.RequestOption
- type APIError
- type Credentials
- type Decryptor
- type ExportedPart
- type InProcess
- type StoredAuth
- type Target
- func MakeTarget(u, realm, credential string, fromKey bool, hc *http.Client) (*Target, error)
- func NewTarget(flagURL, realm string, getenv func(string) string, sessionOnly bool) (*Target, error)
- func OfflineTarget(u, realm string, hc *http.Client) *Target
- func TargetFor(c *kli.CommandContext, realm string, sessionOnly bool) (*Target, error)
- func TargetOf(c *kli.CommandContext, sessionOnly bool) (*Target, error)
Constants ¶
const AdminAPINote = "" /* 130-byte string literal not displayed */
Variables ¶
var WithHeaders = WithProof
withHeaders is withProof for headers that are not a proof (an export's lease).
Functions ¶
func CiphertextFields ¶
ciphertextFields lists the encrypted fields a package still holds as ciphertext.
func CopyPackageTree ¶
copyTree copies the files of a directory, readable only by the owner.
func DecryptPackage ¶
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 ¶
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 ¶
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 ¶
parseFieldKeys reads the value of --field.
func ReadKeyRecords ¶
func Remote ¶
func Remote(cc *kli.CommandConfig)
remote adds the flags every command that talks to a running backd has.
func ResolveURL ¶
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 ¶
verifyPackage reads the manifest and checks every file it lists against its checksum.
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.
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).
type ExportedPart ¶
type InProcess ¶
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.
type StoredAuth ¶
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 ¶
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 ¶
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 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 ¶
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.