1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! 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));
//! # }
//! ```
compile_error!;
pub use ;
pub use ;
pub use CliError;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use PrivateFileError;
pub use ;
pub use ;
pub use ;
/// 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.
;