Skip to main content

Crate stratum_node_cli

Crate stratum_node_cli 

Source
Expand description

The library behind stratum, the client for a Stratum node: the administrator’s commands on the loopback API, and a tenant’s commands through the gate.

Pre-release: this is 0.1.0-alpha. The commands, output and API may change before 0.1.0, and nothing built on it has been deployed yet.

A Stratum node serves an administrative API on loopback only. stratum talks to that API over plain HTTP and holds the operator’s own Nostr key; it never sees the node key or the node’s state volume, except that stratum setup reads the bootstrap token file the operator points it at. A tenant uses the same binary with their own key to join a node and to read, write and export their pod through the node’s gate.

  • URLs. LoopbackUrl accepts http:// URLs whose host is an IPv4 address in 127.0.0.0/8, [::1] or localhost, and nothing else: Step 1 has no TLS. localhost is connected to 127.0.0.1 without a name lookup.
  • Operator keys. generate_key_file writes a fresh key as one nsec1… line to a file created exclusively with mode 0600; load_key_file refuses symbolic links and modes wider than 0600. The secret is never printed, logged or returned as text.
  • Changes. parse_changes reads --set path=value arguments typed by the schema in stratum-node-config.
  • Commands. Session runs each command against one node: status, config (schema, show, preview, apply), setup, sign-challenge, audit checkpoint, backup, invite (create, list, revoke) and member (list, show, repair, cancel, suspend, resume, archive, remove; see SuspendOptions and RemoveOptions). Every authenticated request is signed with NostrSecretKey::sign_request_with_nonce over the exact URL, method and body bytes sent, with a fresh random nonce so no two signings are the same event.
  • Tenant commands. join, pod (ls, get, put, rm, acl get, acl put), export, profile init and profile show take a GateTarget: the node’s CanonicalOrigin, which every request is signed for and named in Host, and a loopback ConnectAddress the request is sent to over plain HTTP. Every pod path is checked as a PodPath before anything is sent.
  • The public profile. join and profile init write the card /pods/<pk>/profile/card and its public-read ACL with the exact texts of profile_card and profile_acl, reading first and creating only what is missing (ProfileInitOptions). profile show reads anyone’s card with an unsigned request and needs no key.
  • Exit codes. Failures are CliErrors, each mapped to a stable code in exit; CliError::hint adds advice for the codes that need it.

The crate targets Unix: key files rely on Unix permission bits.

§Example

use stratum_node_cli::{Output, OutputFormat, Session};

let output = Output::new(OutputFormat::Human);
let session = Session::new("http://127.0.0.1:7460".parse()?, Some("operator.nsec".into()), output);
let code = session.status().unwrap_or_else(|err| {
    output.error(&err);
    err.exit_code()
});
std::process::exit(i32::from(code));

Modules§

exit
The process exit codes of stratum, stable across releases.

Structs§

ApplyOptions
Options for Session::config_apply.
BootstrapToken
The bootstrap token: 64 lowercase hex digits proving entitlement to claim a node.
CanonicalOrigin
A node’s canonical origin: the one origin every signed tenant URL names.
ConnectAddress
A --connect <host:port> value: a loopback literal and an explicit port.
ExportOptions
Options for Session::export.
GateTarget
Where a tenant command sends its requests: the canonical origin it signs for, and the local plain-HTTP address it connects to.
InviteOptions
Options for Session::invite_create.
JoinOptions
Options for Session::join.
LoopbackUrl
A plain-HTTP URL whose host is a loopback literal, kept in canonical form.
Output
The terminal writer used by every command.
ParseConnectError
A --connect value was not <loopback host>:<port>.
ProfileInitOptions
Options for Session::profile_init.
PutOptions
Options for Session::pod_put and Session::pod_acl_put.
RemoveOptions
Options for Session::member_remove.
Session
One node, one optional operator key file and one output format: the context every stratum command runs in.
SetupOptions
Options for Session::setup.
SuspendOptions
Options for Session::member_suspend.

Enums§

CliError
Why a stratum command failed.
Confirmation
Whether a command that changes the node may proceed without asking.
KeyFileError
Why an operator key file could not be created or loaded.
OutputFormat
How results are written to standard output.
ParseChangeError
Why a --set argument could not be parsed.
ParseOriginError
The reasons an origin is refused by CanonicalOrigin.
ParseUrlError
The reasons a URL is refused by LoopbackUrl.
PrivateFileError
Why a private file could not be created or read.
Scheme
The scheme of a canonical origin.
TokenFileError
Why the bootstrap token file could not be read.
WriteCondition
The condition a PUT is sent under.

Constants§

DEFAULT_ENFORCEMENT_WAIT
The default for member suspend --wait: longer than the node’s 310 second fallback, after which a suspension is enforced even if the gate never polled.
DEFAULT_URL
The default node URL: the loopback address the controller listens on by default.
DEFAULT_WAIT
The default time join waits for the pod to be provisioned.
MANIFEST_FORMAT
The format member of an export manifest.
MANIFEST_FORMAT_VERSION
The format_version member of an export manifest.
MANIFEST_SUFFIX
The suffix appended to the archive’s file name for the manifest.
MAX_EXPORT_BYTES
The most bytes of resource content an export holds before it stops: 64 GiB.
MAX_EXPORT_ENTRIES
The most entries an export holds before it stops: containers, resources and ACLs together.
MAX_INVITATION_LIFETIME
The longest invitation lifetime the node accepts: 30 days.

Functions§

generate_key_file
Creates a new operator key file holding a freshly generated key.
load_key_file
Loads an operator key file written by generate_key_file.
parse_changes
Parses --set path=value arguments into configuration changes, typed by the schema in stratum-node-config.
parse_duration
Parses a duration written as a whole number of seconds, or a number followed by s, m, h or d.