stratum-node-cli 0.1.0-alpha.1

The `stratum` operator client for Stratum pod nodes: operator key files, bootstrap claim, signed config apply, audit checkpoint and backup over the loopback API
Documentation
//! The library behind `stratum`, the operator's client for a Stratum node.
//!
//! **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.
//!
//! - **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` and `backup`. Every authenticated
//!   request is signed with
//!   [`NostrSecretKey::sign_request`](stratum_node_core::NostrSecretKey::sign_request)
//!   over the exact URL, method and body bytes 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 changes;
mod client;
mod error;
pub mod exit;
mod key;
mod output;
mod private_file;
mod redact;
mod resume;
mod session;
mod setup;
mod token;
mod url;
mod wire;

pub use changes::{parse_changes, ParseChangeError};
pub use error::CliError;
pub use key::{generate_key_file, load_key_file, KeyFileError};
pub use output::{Output, OutputFormat};
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;