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 process exit codes of `stratum`, stable across releases.
//!
//! | Code | Meaning |
//! |---|---|
//! | 0 | Success; for `status`, the node is `ready` |
//! | 1 | Local failure: a key, token or resume file, the clock, or writing output |
//! | 2 | The node could not be reached |
//! | 3 | `status`: the node is `unconfigured` |
//! | 4 | `status`: the node is `degraded` |
//! | 5 | The node sent a response that does not follow the API contract |
//! | 6 | Changes were previewed but not applied: no confirmation |
//! | 7 | A local check refused the node's answer (claim body, manifest signature) |
//! | 10 | Server error `bad_request` |
//! | 11 | Server error `unauthorized` |
//! | 12 | Server error `forbidden` |
//! | 13 | Server error `not_found` |
//! | 14 | Server error `conflict` |
//! | 15 | Server error `payload_too_large` |
//! | 16 | Server error `unsupported_media_type` |
//! | 17 | Server error `invalid`, or a preview that reports validation errors |
//! | 18 | Server error `too_many_challenges` |
//! | 19 | Server error `backup_refused` |
//! | 20 | Server error `internal` |
//! | 21 | A server error code this client does not know |
//! | 64 | Invalid command line |

/// Success. For `status`, the node is `ready`.
pub const OK: u8 = 0;
/// A local failure: a key, token or resume file, the clock, or output.
pub const FAILURE: u8 = 1;
/// The node could not be reached.
pub const UNREACHABLE: u8 = 2;
/// `status`: the node is `unconfigured`.
pub const UNCONFIGURED: u8 = 3;
/// `status`: the node is `degraded`.
pub const DEGRADED: u8 = 4;
/// The node's response does not follow the API contract.
pub const PROTOCOL: u8 = 5;
/// Changes were previewed but not applied because nothing confirmed them.
pub const NOT_CONFIRMED: u8 = 6;
/// A local check refused the node's answer.
pub const REFUSED: u8 = 7;
/// Server error `bad_request` (HTTP 400).
pub const BAD_REQUEST: u8 = 10;
/// Server error `unauthorized` (HTTP 401).
pub const UNAUTHORIZED: u8 = 11;
/// Server error `forbidden` (HTTP 403).
pub const FORBIDDEN: u8 = 12;
/// Server error `not_found` (HTTP 404).
pub const NOT_FOUND: u8 = 13;
/// Server error `conflict` (HTTP 409): stale revision, already bound or
/// operation conflict.
pub const CONFLICT: u8 = 14;
/// Server error `payload_too_large` (HTTP 413).
pub const PAYLOAD_TOO_LARGE: u8 = 15;
/// Server error `unsupported_media_type` (HTTP 415).
pub const UNSUPPORTED_MEDIA_TYPE: u8 = 16;
/// Server error `invalid` (HTTP 422), or a preview with validation errors.
pub const INVALID: u8 = 17;
/// Server error `too_many_challenges` (HTTP 429).
pub const TOO_MANY_CHALLENGES: u8 = 18;
/// Server error `backup_refused` (HTTP 409): no backup recipient configured.
pub const BACKUP_REFUSED: u8 = 19;
/// Server error `internal` (HTTP 500).
pub const INTERNAL: u8 = 20;
/// A server error code this client does not know.
pub const UNKNOWN_SERVER_ERROR: u8 = 21;
/// The command line could not be parsed.
pub const USAGE: u8 = 64;

/// Returns the exit code for a server error code from the API contract.
///
/// # Examples
///
/// ```
/// use stratum_node_cli::exit;
///
/// assert_eq!(exit::for_server_code("conflict"), exit::CONFLICT);
/// assert_eq!(exit::for_server_code("something_new"), exit::UNKNOWN_SERVER_ERROR);
/// ```
pub fn for_server_code(code: &str) -> u8 {
    match code {
        "bad_request" => BAD_REQUEST,
        "unauthorized" => UNAUTHORIZED,
        "forbidden" => FORBIDDEN,
        "not_found" => NOT_FOUND,
        "conflict" => CONFLICT,
        "payload_too_large" => PAYLOAD_TOO_LARGE,
        "unsupported_media_type" => UNSUPPORTED_MEDIA_TYPE,
        "invalid" => INVALID,
        "too_many_challenges" => TOO_MANY_CHALLENGES,
        "backup_refused" => BACKUP_REFUSED,
        "internal" => INTERNAL,
        _ => UNKNOWN_SERVER_ERROR,
    }
}