stratum-node-cli 0.1.0-alpha.2

The `stratum` client for Stratum pod nodes: operator key files, bootstrap, config, backup, invitations and members over the loopback API; join, pod access and export for tenants through the gate
Documentation
//! 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`, `repair`, `cancel`).
//!   Every authenticated request is signed with
//!   [`NostrSecretKey::sign_request_with_nonce`](stratum_node_core::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`) and `export` 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`](stratum_node_core::PodPath) before anything is sent.
//! - **Exit codes.** Failures are [`CliError`]s, each mapped to a stable
//!   code in [`exit`].
//!
//! The crate targets Unix: key files rely on Unix permission bits.
//!
//! # Example
//!
//! ```no_run
//! use stratum_node_cli::{Output, OutputFormat, Session};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! 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));
//! # }
//! ```

#[cfg(not(unix))]
compile_error!("stratum-node-cli supports Unix only: key files rely on Unix permission bits");

mod admin;
mod changes;
mod client;
mod error;
pub mod exit;
mod export;
mod gate;
mod join;
mod key;
mod listing;
mod origin;
mod output;
mod pod;
mod private_file;
mod redact;
mod resume;
mod session;
mod setup;
mod token;
mod url;
mod wire;

pub use admin::{parse_duration, InviteOptions, MAX_INVITATION_LIFETIME};
pub use changes::{parse_changes, ParseChangeError};
pub use error::CliError;
pub use export::{
    ExportOptions, MANIFEST_FORMAT, MANIFEST_FORMAT_VERSION, MANIFEST_SUFFIX, MAX_EXPORT_BYTES,
    MAX_EXPORT_ENTRIES,
};
pub use join::{JoinOptions, DEFAULT_WAIT};
pub use key::{generate_key_file, load_key_file, KeyFileError};
pub use origin::{
    CanonicalOrigin, ConnectAddress, GateTarget, ParseConnectError, ParseOriginError, Scheme,
};
pub use output::{Output, OutputFormat};
pub use pod::{PutOptions, WriteCondition};
pub use private_file::PrivateFileError;
pub use session::{ApplyOptions, Confirmation, Session, SetupOptions};
pub use token::{BootstrapToken, TokenFileError};
pub use url::{LoopbackUrl, ParseUrlError};

/// The default node URL: the loopback address the controller listens on by
/// default.
pub const DEFAULT_URL: &str = "http://127.0.0.1:7460";

/// Compiles the README's examples as doctests.
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;