pub struct Session { /* private fields */ }Expand description
One node, one optional operator key file and one output format: the
context every stratum command runs in.
Each command method writes its results through Output and returns
the process exit code on success (see exit); failures
are returned as CliError, whose
exit_code gives theirs. 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 and
fresh auxiliary randomness.
§Examples
use stratum_node_cli::{CliError, Output, OutputFormat, Session};
let session = Session::new("http://127.0.0.1:7460".parse()?, None, Output::new(OutputFormat::Json));
// Commands that need the operator key say so before touching the network.
assert!(matches!(session.audit_checkpoint(), Err(CliError::MissingKeyFile)));Implementations§
Source§impl Session
impl Session
Sourcepub fn invite_create(&self, options: &InviteOptions) -> Result<u8, CliError>
pub fn invite_create(&self, options: &InviteOptions) -> Result<u8, CliError>
stratum invite create <did> [--expires-in <duration>]: issues an
invitation for one identity and prints its identifier, subject,
expiry, the canonical origin and node DID, and the stratum join
command line the invitee runs. Signed by the administrator.
Without --expires-in the lifetime is the node’s configured
membership.invitation_ttl_secs, read from the effective
configuration. The response must name the requested subject and the
node /readyz reported.
§Errors
CliError::Usage for a lifetime over 30 days or under one second,
CliError::Refused when the response names another subject or
node, and key, transport, protocol and server errors
(invitations_disabled among them).
Sourcepub fn invite_list(&self) -> Result<u8, CliError>
pub fn invite_list(&self) -> Result<u8, CliError>
stratum invite list: lists invitations with their state. Signed.
§Errors
Key, transport, protocol and server errors.
Sourcepub fn invite_revoke(
&self,
invitation: &InvitationId,
operation_id_arg: Option<&str>,
) -> Result<u8, CliError>
pub fn invite_revoke( &self, invitation: &InvitationId, operation_id_arg: Option<&str>, ) -> Result<u8, CliError>
stratum invite revoke <invitation>: revokes an invitation that is
still issued. Signed.
§Errors
CliError::Refused when the response names another invitation or
state, and key, transport, protocol and server errors.
Sourcepub fn member_list(&self) -> Result<u8, CliError>
pub fn member_list(&self) -> Result<u8, CliError>
stratum member list: lists members with their state, pod URL and
the last provisioning error, and the capacity in use. Signed.
§Errors
Key, transport, protocol and server errors.
Sourcepub fn member_repair(
&self,
member: &DidNostr,
operation_id_arg: Option<&str>,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn member_repair( &self, member: &DidNostr, operation_id_arg: Option<&str>, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum member repair <did> [--yes]: runs provisioning again for a
member, which restores a missing root ACL and leaves an existing one
alone. Asks first. Signed.
§Errors
CliError::NotConfirmed, CliError::Refused when the response
names another member, and key, transport, protocol and server errors.
Sourcepub fn member_cancel(
&self,
member: &DidNostr,
operation_id_arg: Option<&str>,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn member_cancel( &self, member: &DidNostr, operation_id_arg: Option<&str>, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum member cancel <did> [--yes]: cancels a reserved member,
releasing its slot; the invitation stays used. Asks first. Signed.
§Errors
CliError::NotConfirmed, CliError::Refused when the response
names another member or a state other than cancelled, and key,
transport, protocol and server errors.
Source§impl Session
impl Session
Sourcepub fn app_catalogue(&self, target: &GateTarget) -> Result<u8, CliError>
pub fn app_catalogue(&self, target: &GateTarget) -> Result<u8, CliError>
stratum app catalogue: lists the applications this node has
approved, each with its manifest’s name, version, image ID, granted
containers and the most workspace it may be given. Signed.
§Errors
Key, transport, protocol and server errors (suspended while the
membership is suspended).
Sourcepub fn app_install(
&self,
target: &GateTarget,
options: &InstallOptions,
) -> Result<u8, CliError>
pub fn app_install( &self, target: &GateTarget, options: &InstallOptions, ) -> Result<u8, CliError>
stratum app install <application> [--schedule <secs>] [--workspace none|read|write] [--yes]: installs an application in the caller’s
pod. Signed.
- Reads the catalogue entry, and creates the installation
(
pending_consent), which gives the application’s key and the offered grant. - Renders the grant again from the manifest with
render_offeredand refuses unless every byte and hash matches the offer. - For each granted container, reads the ACL that governs it now
(its own, or the nearest ancestor’s) and builds its new ACL: the
owner’s control, every rule of its own ACL unchanged, inherited
acl:defaultrules materialised,acl:accessTo-only ones not copied, and the offered rule. A statement the client does not evaluate is refused, and the application is never givenControl. - Prints the diff of each ACL, the owner, the application, its
version and image ID and
OPERATOR_STATEMENT, and asks. - For each container: checks the installation is still
pending_consent, rereads the governing ACL and starts again if its entity tag changed, writes withIf-Match(orIf-None-Match: *when the container had no ACL), starts again on 412, and reads the ACL back, comparing parsed statements. - Sends consent only if every read-back matched. On a mismatch, a
refused consent or an installation that is no longer
pending_consent, removes what it wrote.
The operation ID of the create request is printed first; declining
leaves the installation pending_consent with nothing written.
§Errors
CliError::Usage for a schedule out of range, a workspace above
the manifest’s or an application not in the catalogue;
CliError::NotConfirmed; CliError::Refused for an offer that
is not the one the manifest renders, or an ACL that would give the
application Control; CliError::AclNotEvaluated;
CliError::ReadBackMismatch; CliError::ConsentRefused; and
key, transport, protocol and server errors (workspace_unavailable,
application_unavailable, precondition_failed when a container
kept changing).
Sourcepub fn app_list(&self, target: &GateTarget) -> Result<u8, CliError>
pub fn app_list(&self, target: &GateTarget) -> Result<u8, CliError>
stratum app list: lists the caller’s installations with their
state, grant and job counts, and any ACL cleanup still pending.
Signed.
§Errors
Key, transport, protocol and server errors.
Sourcepub fn app_show(
&self,
target: &GateTarget,
installation: &InstallationId,
) -> Result<u8, CliError>
pub fn app_show( &self, target: &GateTarget, installation: &InstallationId, ) -> Result<u8, CliError>
stratum app show <installation>: prints one installation: state,
application and key, schedule, workspace, key-disable reasons, grant
and pending cleanup, the enforcement parts while a withdrawal or
suspension is being enforced, and job counts. Signed.
§Errors
CliError::Refused for an answer naming another installation or
owner, and key, transport, protocol and server errors.
Sourcepub fn app_jobs(
&self,
target: &GateTarget,
installation: &InstallationId,
) -> Result<u8, CliError>
pub fn app_jobs( &self, target: &GateTarget, installation: &InstallationId, ) -> Result<u8, CliError>
stratum app jobs <installation>: lists the installation’s jobs:
period, state, attempts, outcome and the result the job reported.
Signed.
§Errors
Key, transport, protocol and server errors.
Sourcepub fn app_run(
&self,
target: &GateTarget,
installation: &InstallationId,
period: u64,
operation_id_arg: Option<&str>,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn app_run( &self, target: &GateTarget, installation: &InstallationId, period: u64, operation_id_arg: Option<&str>, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum app run <installation> --period <n> [--yes]: creates the
job for period n if none exists. Asks first. Signed. A period that
already has a job answers that job.
§Errors
CliError::NotConfirmed, and key, transport, protocol and server
errors.
Sourcepub fn app_withdraw(
&self,
target: &GateTarget,
installation: &InstallationId,
operation_id_arg: Option<&str>,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn app_withdraw( &self, target: &GateTarget, installation: &InstallationId, operation_id_arg: Option<&str>, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum app withdraw <installation> [--yes]: withdraws the
installation, then removes its authorisation from every granted
container’s ACL and reports the cleanup, as
app_cleanup does. Asks first. Signed.
The node answers at once with authorisation: enforcing: its gate
and proxy refuse the key once they take the new revision, or within
310 s. The ACL cleanup is the member’s part: if it is interrupted,
every stratum app command shows it pending until
stratum app cleanup finishes it.
§Errors
CliError::NotConfirmed; CliError::CleanupPending (or
CliError::AclNotEvaluated) when a container’s ACL could not be
cleaned; key, transport, protocol and server errors (suspended
while the membership is suspended).
Sourcepub fn app_cleanup(
&self,
target: &GateTarget,
installation: &InstallationId,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn app_cleanup( &self, target: &GateTarget, installation: &InstallationId, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum app cleanup <installation> [--yes]: finishes a withdrawn
installation’s ACL cleanup. Asks first. Signed.
For each container the node lists as pending, the client reads its
ACL, removes only the installation’s authorisation, writes the ACL
back with If-Match (starting again on 412), reads it back and
compares the parsed statements, and reports that container cleaned
at once, so an interruption keeps what was done. An ACL that no
longer holds the authorisation counts as clean. Nothing is kept on
this machine: the pending list is the node’s.
§Errors
CliError::NotConfirmed; CliError::CleanupPending when a
container could not be cleaned, or CliError::AclNotEvaluated
when its ACL holds a statement the client does not evaluate; key,
transport, protocol and server errors.
Sourcepub fn app_resume(
&self,
target: &GateTarget,
installation: &InstallationId,
operation_id_arg: Option<&str>,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn app_resume( &self, target: &GateTarget, installation: &InstallationId, operation_id_arg: Option<&str>, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum app resume <installation> [--yes]: after a restore, enables
the installation’s key again by removing its restore reason. Asks
first. Signed. Only an active installation of an active member
can be resumed.
§Errors
CliError::NotConfirmed, and key, transport, protocol and server
errors (conflict for an installation that cannot be resumed).
Source§impl Session
impl Session
Sourcepub fn application_add(
&self,
manifest_file: &Path,
operation_id_arg: Option<&str>,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn application_add( &self, manifest_file: &Path, operation_id_arg: Option<&str>, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum application add <manifest.json> [--yes]: approves an
application. Asks first. Signed.
The manifest is read (at most 256 KiB), checked for shape locally against the widest ceilings any node allows, shown, and sent as given. The node validates it against its own ceilings, and refuses it unless its runner reports the image ID present on the tenant daemon with no volumes declared.
§Errors
CliError::FileContents for an unreadable or invalid manifest,
CliError::NotConfirmed, and key, transport, protocol and server
errors (invalid naming the failed rule, image_absent,
image_has_volumes).
Sourcepub fn application_list(&self) -> Result<u8, CliError>
pub fn application_list(&self) -> Result<u8, CliError>
stratum application list: lists every application with its state,
manifest name and version, image ID, approval time and installation
count. Signed.
§Errors
Key, transport, protocol and server errors.
Sourcepub fn application_action(
&self,
application: &ApplicationId,
action: ApplicationAction,
operation_id_arg: Option<&str>,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn application_action( &self, application: &ApplicationId, action: ApplicationAction, operation_id_arg: Option<&str>, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum application withdraw|approve|disable <id> [--yes]: moves an
application to another state. Asks first. Signed.
§Errors
CliError::NotConfirmed, CliError::Refused when the answer is
not the state asked for, and key, transport, protocol and server
errors (conflict from a state that cannot make the transition).
Source§impl Session
impl Session
Sourcepub fn export(
&self,
target: &GateTarget,
options: &ExportOptions,
) -> Result<u8, CliError>
pub fn export( &self, target: &GateTarget, options: &ExportOptions, ) -> Result<u8, CliError>
stratum export -o <archive.tar.zst> [--force]: walks the caller’s
own pod over signed requests and writes it as a tar archive
compressed with zstd, with a manifest beside it.
The walk starts at the pod root /pods/<pk>/ and fetches the root
ACL /pods/<pk>.acl. Each child a listing names under ldp:contains
is resolved against the listing’s own address and followed only if
the result is on the canonical origin, parses as a pod path under the
Step 2 rules, is in the caller’s own pod and lies under the container
listed; anything else is skipped and reported. Redirects are never
followed. For every container and resource the ACL beside it is
asked for (a 404 means none). No entry is fetched twice.
The archive holds pods/<pk>/… (containers as directories) and
pods/<pk>.acl, so it unpacks to the bytes that were written. The
manifest, <archive>.manifest.json, lists every entry’s path, kind,
size, SHA-256 and content type, which ACLs exist, the archive’s own
size and SHA-256, and what was skipped. The export is not a snapshot:
after the walk each resource’s entity tag and each container’s
listing is asked for again, and entries that changed or vanished are
reported. The walk stops with an error at 100,000 entries or 64 GiB.
Both files are written under temporary names in the target directory
(mode 0600) and moved into place only once complete, the archive
first and the manifest last. A manifest present beside the archive
therefore always describes that archive; an archive with no manifest
is an export that did not finish and should not be trusted. Without
force, nothing is ever replaced, including a file that appears at
either name while the export runs: the export fails instead, and an
archive it had already placed is withdrawn. With force, the old
manifest is set aside before the archive is replaced, and put back if
the archive cannot be moved; the limit is that a failure or crash
between the two moves leaves the new (or old) archive with no
manifest, never with a mismatched one. Concurrent forced exports to
the same name are not coordinated.
§Errors
CliError::Local when a target exists without force (checked
before the walk and again when the files are placed), a limit is
reached or a file cannot be written; CliError::ExportIncomplete
(after both files are written) when anything changed, vanished or
was skipped; and key, transport and server errors.
Source§impl Session
impl Session
Sourcepub fn join(
&self,
target: &GateTarget,
options: &JoinOptions,
) -> Result<u8, CliError>
pub fn join( &self, target: &GateTarget, options: &JoinOptions, ) -> Result<u8, CliError>
stratum join --invitation <id> --node <did> --origin … [--connect …]:
redeems an invitation with the caller’s key and activates the pod.
The flow:
- Fetch the admission notice. The node DID it reports must be
JoinOptions::node, its origin the canonical origin, and the SHA-256 of the notice text received must equal both the hash the node reports and the hash of the notice this client was built with (admission_notice_v1_sha256). - Ask for the caller’s own operation. A caller who is already a
member (
reserved,provisionedoractive) continues from where an earlier run stopped, without redeeming again. Asuspendedmember stops here. Aremovedorcancelledkey is not a member: it goes on to redeem the new invitation, and the node decides (pod_data_presentuntil its old pod data is purged). - Otherwise show the notice and ask for confirmation (a terminal is
required unless
--yes), then redeem with the admission claim signed by the caller. If the connection fails after the request was sent, the identical signed request is resent once: the node returns the response it stored. - Poll the operation until the member is
provisioned, for at mostJoinOptions::wait, showing the node’s last error when it reports one. - Write a probe resource in the pod (create only), read it back and compare, and delete it.
- Write the public profile document while the member is still
provisioned: the card/pods/<pk>/profile/cardand then its ACL/pods/<pk>/profile/card.acl, each read first and created withIf-None-Match: *only when missing, so a resumed run neither fails nor writes twice. An existing card that names the caller is left alone; one that does not is reported and left alone, with no ACL written, and the join continues (stratum profile init --replacefixes it later). SeeSession::profile_init. - Confirm, and print the pod URL.
Every request is signed with a fresh event over the canonical URL;
only the single resend reuses one. Every pod URL the node reports must
be exactly <origin>/pods/<caller's key>/.
§Errors
CliError::Refused for a notice from another node or with another
hash, a membership cancelled or removed while joining, a response naming another
member or pod URL, or a probe that does not read back; CliError::NotConfirmed;
CliError::TimedOut when provisioning does not finish in time
(rerun join to continue); and key, transport and server errors
(invitation_refused, invitations_disabled, capacity_exhausted,
too_many_requests, suspended, pod_data_present and
insufficient_storage among them).
Source§impl Session
impl Session
Sourcepub fn member_suspend(&self, options: &SuspendOptions) -> Result<u8, CliError>
pub fn member_suspend(&self, options: &SuspendOptions) -> Result<u8, CliError>
stratum member suspend <did> [--wait[=<seconds>]] [--yes]: moves a
provisioned or active member to suspended. Asks first. Signed.
Sends POST /api/v1/members/<pk>/suspend with
{"node", "operation_id"}. The node changes the member’s state and
publishes a new directory revision in one step; no member key and no
pod write is involved. The answer reports the suspension number and
whether the suspension is enforcing (the gate may still admit new
requests) or enforced (it admits none).
With SuspendOptions::wait, the member is then read with
GET /api/v1/members/<pk> at once, and every two seconds after that
until enforcement is enforced; the enforcement printed is the
read’s, never the answer’s. A resend of the same operation returns
the answer stored when the suspension committed, which may say
enforced for a member resumed since, so only the read is current.
Each read is allowed only the time left in the wait (at least one
second), so the wait ends within about a second of its limit.
§Errors
CliError::NotConfirmed; CliError::Refused when the answer is
not suspended, or when the member is not, or stops being,
suspended under that suspension; CliError::TimedOut when the
wait runs out while still enforcing, or while a read is
unanswered; and key, transport, protocol and server errors
(conflict from a state that cannot be suspended).
§Examples
use std::time::Duration;
use stratum_node_cli::{Confirmation, Output, OutputFormat, Session, SuspendOptions};
let session = Session::new(
"http://127.0.0.1:7460".parse()?,
Some("operator.nsec".into()),
Output::new(OutputFormat::Human),
);
session.member_suspend(&SuspendOptions {
member: "did:nostr:79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798".parse()?,
operation_id: None,
confirmation: Confirmation::Assumed,
wait: Some(Duration::from_secs(60)),
})?;Sourcepub fn member_resume(
&self,
member: &DidNostr,
operation_id_arg: Option<&str>,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn member_resume( &self, member: &DidNostr, operation_id_arg: Option<&str>, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum member resume <did> [--yes]: returns a suspended member
to the state it had, provisioned or active. Asks first. Signed.
Sends POST /api/v1/members/<pk>/resume with
{"node", "operation_id"}. Resuming ends the suspension and
discards any archive taken during it.
§Errors
CliError::NotConfirmed, CliError::Refused when the answer is
neither provisioned nor active, and key, transport, protocol and
server errors (conflict for a member that is not suspended).
§Examples
use stratum_node_cli::{Confirmation, Output, OutputFormat, Session};
use stratum_node_core::DidNostr;
let session = Session::new(
"http://127.0.0.1:7460".parse()?,
Some("operator.nsec".into()),
Output::new(OutputFormat::Human),
);
let member: DidNostr =
"did:nostr:79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798".parse()?;
session.member_resume(&member, None, Confirmation::Prompt)?;Sourcepub fn member_archive(
&self,
member: &DidNostr,
operation_id_arg: Option<&str>,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn member_archive( &self, member: &DidNostr, operation_id_arg: Option<&str>, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum member archive <did> [--yes]: has the node take an
encrypted archive of a suspended member’s pod data. Asks first.
Signed.
Sends POST /api/v1/members/<pk>/archive with
{"node", "operation_id"}, allowing up to 15 minutes for the answer.
The node refuses unless the member is suspended and that
suspension is enforced, and while a backup or another archive
runs. It pauses writes at the gate for every tenant while it reads
the pod data, as a backup does. The archive is encrypted to the
backup recipients and signed by the node; its reference is the
manifest’s event ID, which remove and stratumd purge name.
§Errors
CliError::NotConfirmed and key, transport, protocol and server
errors (conflict for a member that is not suspended or not yet
enforced, or while a backup runs; gate_unavailable when the gate
could not be paused).
§Examples
use stratum_node_cli::{Confirmation, Output, OutputFormat, Session};
use stratum_node_core::DidNostr;
let session = Session::new(
"http://127.0.0.1:7460".parse()?,
Some("operator.nsec".into()),
Output::new(OutputFormat::Human),
);
let member: DidNostr =
"did:nostr:79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798".parse()?;
session.member_archive(&member, Some("archive-1"), Confirmation::Assumed)?;Sourcepub fn member_remove(&self, options: &RemoveOptions) -> Result<u8, CliError>
pub fn member_remove(&self, options: &RemoveOptions) -> Result<u8, CliError>
stratum member remove <did> [--no-archive] [--yes]: ends a
suspended member’s membership. Asks first. Signed.
Sends POST /api/v1/members/<pk>/remove with
{"node", "operation_id", "require_archive"}; require_archive is
always written, true unless --no-archive. The member’s slot is
freed and their pod is unreachable at once; the data stays on disk
until the operator purges it, no earlier than the purge_not_before
the answer gives. --no-archive waives the archive: the prompt and
the output say so, and the node records who waived it.
Other members’ ACLs that name the key are not touched; the output says that the key regains that access if it is admitted again.
§Errors
CliError::NotConfirmed, CliError::Refused when the answer is
not removed, or records a waiver for a request that required an
archive, or an archive for one that waived it, and
key, transport, protocol and server errors (archive_required, and
conflict for a member that is not suspended).
§Examples
use stratum_node_cli::{Confirmation, Output, OutputFormat, RemoveOptions, Session};
let session = Session::new(
"http://127.0.0.1:7460".parse()?,
Some("operator.nsec".into()),
Output::new(OutputFormat::Human),
);
session.member_remove(&RemoveOptions {
member: "did:nostr:79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798".parse()?,
operation_id: None,
confirmation: Confirmation::Prompt,
require_archive: true,
})?;Sourcepub fn member_show(&self, member: &DidNostr) -> Result<u8, CliError>
pub fn member_show(&self, member: &DidNostr) -> Result<u8, CliError>
stratum member show <did>: reads one member as it is now. Signed.
Sends GET /api/v1/members/<pk>, which takes no operation ID and is
never stored, so its enforcement is current. Prints the state,
generation, suspension number, the times of each step, enforcement,
whether the pod is over quota, the last measurement (size, when, how
long it took), purge_not_before and the archive reference. Under
--json, prints the node’s answer.
§Errors
CliError::Refused when the answer names another member, and key,
transport, protocol and server errors (not_found for a key the
node has never admitted).
§Examples
use stratum_node_cli::{Output, OutputFormat, Session};
use stratum_node_core::DidNostr;
let session = Session::new(
"http://127.0.0.1:7460".parse()?,
Some("operator.nsec".into()),
Output::new(OutputFormat::Human),
);
let member: DidNostr =
"did:nostr:79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798".parse()?;
let _exit_code = session.member_show(&member)?;Source§impl Session
impl Session
Sourcepub fn pod_ls(&self, target: &GateTarget, path: &str) -> Result<u8, CliError>
pub fn pod_ls(&self, target: &GateTarget, path: &str) -> Result<u8, CliError>
stratum pod ls [<path>]: lists a container in a pod. Signed by the
caller’s key over the canonical URL.
path is relative to the caller’s own pod root (empty for the root
itself) or absolute /pods/<pk>/…; a missing trailing / is added.
Each listed child is resolved against the listing’s address and
shown only if it lies under the container; anything else is
reported as refused.
§Errors
CliError::Usage for a path the Step 2 rules refuse, and key,
transport and server errors.
Sourcepub fn pod_get(
&self,
target: &GateTarget,
path: &str,
output: Option<&Path>,
) -> Result<u8, CliError>
pub fn pod_get( &self, target: &GateTarget, path: &str, output: Option<&Path>, ) -> Result<u8, CliError>
stratum pod get <path> [-o <file>]: reads a resource. Signed.
The body is written byte for byte to output, a new file created
with mode 0600 (an existing file is never overwritten), or to
standard output. On a terminal, control characters are escaped; in a
pipe the bytes are written unchanged. Under --json an output file
is required, and a report of the status, content type, entity tag,
size and SHA-256 is printed.
§Errors
CliError::Usage for a refused path or --json without -o,
CliError::File when the output file exists, and key, transport
and server errors.
Sourcepub fn pod_acl_get(
&self,
target: &GateTarget,
path: &str,
output: Option<&Path>,
) -> Result<u8, CliError>
pub fn pod_acl_get( &self, target: &GateTarget, path: &str, output: Option<&Path>, ) -> Result<u8, CliError>
stratum pod acl get <path> [-o <file>]: reads the ACL beside a
resource or container, as pod_get does. For the
pod root (an empty path) that is the root ACL /pods/<pk>.acl.
§Errors
As pod_get; CliError::Usage when the path is
itself an ACL.
Sourcepub fn pod_put(
&self,
target: &GateTarget,
options: &PutOptions,
) -> Result<u8, CliError>
pub fn pod_put( &self, target: &GateTarget, options: &PutOptions, ) -> Result<u8, CliError>
stratum pod put <path> <file> [--content-type …] [--if-match <etag> | --create-only]: writes a resource. Signed over the body, which is
read whole (at most 1 GiB) and sent with Content-Length.
§Errors
CliError::Usage for a refused path or a container path,
CliError::FileContents for an unreadable or oversized file,
precondition_failed when the condition does not hold, and key,
transport and server errors.
Sourcepub fn pod_acl_put(
&self,
target: &GateTarget,
options: &PutOptions,
) -> Result<u8, CliError>
pub fn pod_acl_put( &self, target: &GateTarget, options: &PutOptions, ) -> Result<u8, CliError>
stratum pod acl put <path> <file>: writes the ACL beside a resource
or container (the root ACL for the pod root), as
pod_put does, with content type text/turtle
unless another is given.
§Errors
As pod_put; CliError::Usage when the path is
itself an ACL.
Sourcepub fn pod_rm(
&self,
target: &GateTarget,
path: &str,
confirmation: Confirmation,
) -> Result<u8, CliError>
pub fn pod_rm( &self, target: &GateTarget, path: &str, confirmation: Confirmation, ) -> Result<u8, CliError>
stratum pod rm <path> [--yes]: deletes a resource or an empty
container after confirmation. Signed. The root ACL cannot be
deleted: that would lock the owner out of their own pod.
§Errors
CliError::Usage for a refused path or the root ACL,
CliError::NotConfirmed, and key, transport and server errors.
Source§impl Session
impl Session
Sourcepub fn profile_init(
&self,
target: &GateTarget,
options: ProfileInitOptions,
) -> Result<u8, CliError>
pub fn profile_init( &self, target: &GateTarget, options: ProfileInitOptions, ) -> Result<u8, CliError>
stratum profile init [--replace] --origin … [--connect …]: writes
the public profile document into the caller’s own pod, for a member
admitted before join wrote one. Signed by the caller’s key.
It never overwrites what is already right, and a repeat sends no write:
- With no card, it writes the standard card
(
PUT /pods/<pk>/profile/card,If-None-Match: *,text/turtle) and then the ACL beside it if that is missing. - With a card that names the owner, it leaves the card and writes
only a missing ACL (
PUT /pods/<pk>/profile/card.acl,If-None-Match: *). An existing ACL is never changed; the output says when it is not the standard one. - With a card that does not name the owner, or that the gate would
not serve (another content type, over 64 KiB), it reports the
conflict and changes nothing, unless
--replaceis given; then the card is replaced withIf-Match: <etag read>and a missing ACL is written.
§Errors
CliError::Refused for a card in conflict without --replace, or
one that changed while being replaced; and key, transport and server
errors (suspended, insufficient_storage among them).
§Examples
use stratum_node_cli::{GateTarget, Output, OutputFormat, Session, ProfileInitOptions};
let session = Session::new(
stratum_node_cli::DEFAULT_URL.parse()?,
Some("me.nsec".into()),
Output::new(OutputFormat::Human),
);
let target = GateTarget::new(
"https://stratum.example".parse()?,
Some("127.0.0.1:7461".parse()?),
)?;
session.profile_init(&target, ProfileInitOptions::default())?;Sourcepub fn profile_show(
&self,
target: &GateTarget,
member: &DidNostr,
) -> Result<u8, CliError>
pub fn profile_show( &self, target: &GateTarget, member: &DidNostr, ) -> Result<u8, CliError>
stratum profile show <did> --origin … [--connect …]: reads any
member’s public profile, without a key.
Sends an unsigned GET /pods/<pk>/profile/card with
Accept: text/turtle to the gate, the one request the gate forwards
without a signature. A 200 must be text/turtle and at most
PROFILE_MAX_BYTES; its text is printed with control characters
escaped (under --json: the DID, URL, content type, entity tag and
text). A 404 is reported as “no public profile” with exit code
exit::NOT_FOUND: the key is not a member, or the member never
wrote one, deleted it or made it private; the gate does not say
which.
No key file is read, even when one is configured.
§Errors
CliError::Protocol for an answer of another content type or
size, and transport and server errors (pod_unavailable, busy).
§Examples
use stratum_node_cli::{GateTarget, Output, OutputFormat, Session};
let session = Session::new(
stratum_node_cli::DEFAULT_URL.parse()?,
None,
Output::new(OutputFormat::Human),
);
let target = GateTarget::new(
"https://stratum.example".parse()?,
Some("127.0.0.1:7461".parse()?),
)?;
let member = "did:nostr:79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798".parse()?;
let code = session.profile_show(&target, &member)?; // 13: no public profileSource§impl Session
impl Session
Sourcepub fn new(url: LoopbackUrl, key_file: Option<PathBuf>, output: Output) -> Self
pub fn new(url: LoopbackUrl, key_file: Option<PathBuf>, output: Output) -> Self
Creates a session for the node at url, signing with the key in
key_file when a command needs it.
Sourcepub fn key_generate(&self, out: &Path) -> Result<u8, CliError>
pub fn key_generate(&self, out: &Path) -> Result<u8, CliError>
stratum key generate --out <file>: creates a new operator key file
and prints the operator’s DID and npub.
§Errors
CliError::KeyFile when the file exists or cannot be created.
Sourcepub fn key_show(&self) -> Result<u8, CliError>
pub fn key_show(&self) -> Result<u8, CliError>
stratum key show: prints the DID and npub of the operator key.
§Errors
Sourcepub fn status(&self) -> Result<u8, CliError>
pub fn status(&self) -> Result<u8, CliError>
stratum status: reads /readyz and returns exit::OK when the
node is ready, exit::UNCONFIGURED or exit::DEGRADED.
§Errors
CliError::Unreachable (exit 2) or CliError::Protocol.
Sourcepub fn config_schema(&self) -> Result<u8, CliError>
pub fn config_schema(&self) -> Result<u8, CliError>
stratum config schema: prints the node’s configuration schema.
§Errors
Transport, protocol and server errors.
Sourcepub fn config_show(&self) -> Result<u8, CliError>
pub fn config_show(&self) -> Result<u8, CliError>
stratum config show: prints the node’s effective configuration,
revisions and public-config hash. Signed.
§Errors
Key, transport, protocol and server errors.
Sourcepub fn config_preview(
&self,
sets: &[String],
base_revision: Option<u64>,
) -> Result<u8, CliError>
pub fn config_preview( &self, sets: &[String], base_revision: Option<u64>, ) -> Result<u8, CliError>
stratum config preview --set path=value …: shows what the change
would do, without changing anything. Signed when a key file is
given (the node requires it once an administrator is bound).
§Errors
CliError::Usage for bad --set arguments,
CliError::InvalidPreview when the result would be invalid, and
key, transport, protocol and server errors.
Sourcepub fn config_apply(&self, options: &ApplyOptions) -> Result<u8, CliError>
pub fn config_apply(&self, options: &ApplyOptions) -> Result<u8, CliError>
stratum config apply --set path=value …: previews the change,
prints the diff and the strictest apply class, and after
confirmation applies it on the same base revision. Signed.
The operation ID is printed before the apply request is sent, so a
retry after a lost response can pass it with --operation-id.
§Errors
CliError::NotConfirmed when not confirmed,
CliError::InvalidPreview, CliError::Usage, and key,
transport, protocol and server errors (conflict for a stale base
revision, invalid for a rejected configuration).
Sourcepub fn audit_checkpoint(&self) -> Result<u8, CliError>
pub fn audit_checkpoint(&self) -> Result<u8, CliError>
stratum audit checkpoint: prints the audit checkpoint <seq>:<hex>
and the node DID. Keep the checkpoint somewhere the node cannot
write: it is what truncation of the audit log is detected against.
Signed.
§Errors
Key, transport, protocol and server errors.
Sourcepub fn backup(
&self,
operation_id_arg: Option<&str>,
expect_node: Option<&DidNostr>,
) -> Result<u8, CliError>
pub fn backup( &self, operation_id_arg: Option<&str>, expect_node: Option<&DidNostr>, ) -> Result<u8, CliError>
stratum backup [--expect-node <did>]: asks the node for a backup
and prints its directory, checkpoint and configuration revision.
Signed.
Before anything is printed, the returned manifest event must verify
(ID and signature), be of kind 30078 and be authored by the node DID
reported by /readyz; its content must be a stratum-backup
version 1 manifest naming that node and listing the three backup
files in order; and its signed audit_checkpoint must equal the
response’s checkpoint. Every printed fact except the backup directory therefore
comes from the signed manifest; the directory is the node’s unsigned
statement of where it wrote the files. When expect_node is given, /readyz must report
it before any request is signed.
§Errors
CliError::Refused for a manifest that fails verification or a
node other than expect_node, backup_refused when the node has no
backup recipient, and key, transport, protocol and server errors.
Sourcepub fn sign_challenge(
&self,
claim_body_file: &Path,
expect_node: &DidNostr,
) -> Result<u8, CliError>
pub fn sign_challenge( &self, claim_body_file: &Path, expect_node: &DidNostr, ) -> Result<u8, CliError>
stratum sign-challenge --claim-body-file <file> --expect-node <did>:
signs a claim body offline and prints the Authorization header
value for it. No network.
Before signing, the body must name this key as claimant and
expect_node as the node, and must not have expired. The expected
node comes from the operator (stratumd prints its node DID at
start), never from the file, so a substituted claim file for another
node is refused. The configuration hash and base revision in the body
cannot be checked offline: they are signed as the node issued them.
stratum setup checks them against its own derivation; prefer it
when the node is reachable.
The URL is the session URL: a bare origin gets
/api/v1/bootstrap/claim appended, and a URL with a path must end in
exactly that path, so no other route can be signed. It must equal
the url the challenge response named. The file’s bytes are signed
exactly as they are, so a trailing newline added by an editor makes
the signature fail at the node; a warning is printed if one is
present.
§Errors
CliError::Usage for a URL with another path,
CliError::Refused when the body names another claimant or node or
has expired, CliError::FileContents when it is not a claim body,
and key and file errors.
Source§impl Session
impl Session
Sourcepub fn setup(&self, options: &SetupOptions) -> Result<u8, CliError>
pub fn setup(&self, options: &SetupOptions) -> Result<u8, CliError>
stratum setup --token-file <path> [--set path=value …]: claims an
unconfigured node for the operator key and commits the initial
configuration. With no --set, the node is claimed with its seed
configuration unchanged.
The flow:
- Read the bootstrap token and
/readyz, which must reportunconfiguredat revision 0, and take the node DID from it. WithSetupOptions::expect_node, that DID must be the expected one, or setup stops before anything else is sent. - Derive the initial configuration locally: the seed text of
stratum-node-config(the text of revision 0) with the changes applied. Preview the same changes on the node; itstextanddiffmust equal the local ones byte for byte. Show the local diff and change list (and withSetupOptions::show_textthe whole text); stop if the result is invalid. - Request a challenge for this key’s DID and the same changes.
- Check the returned claim body locally: it must name this
claimant and the node from
/readyz, must not have expired, must answer the challenge ID and base revision, itsconfig_sha256must be the SHA-256 of the locally derived text (so the hash covers exactly the text shown), and the claim URL must be this client’s own/api/v1/bootstrap/claimURL with methodPOST. - Show the claim fields and ask for confirmation (or
--yes). - Sign the body verbatim, save the signed request with the token to
the resume file (
0600, created exclusively), then send it with the token inStratum-Bootstrap-Token. - Check that the response names this administrator and node, print the administrator DID, revision and public-config hash, and delete the resume file.
If a resume file exists, steps 1 to 6 are skipped and the saved
request is resent byte for byte, so that a node which committed the
claim but lost the response returns its stored result. With
SetupOptions::expect_node, the saved body must name that node and
/readyz must report it before the saved request is resent. The resume
file is kept after a transport failure, a protocol error or a 5xx
response, and deleted after success or any 4xx, which the identical
request can never turn into a success.
§Errors
CliError::Refused for any failed local check (including a node
other than the expected one, or a node preview that differs from
the local derivation),
CliError::NotConfirmed, CliError::InvalidPreview, token, key
and resume-file errors, and transport, protocol and server errors.