Skip to main content

rustio_admin/
lib.rs

1//! rustio-admin — Django Admin, but for Rust.
2//!
3//! This crate is the public face of the framework. Phase 2 ships the
4//! HTTP / router / server / ORM / migrations / templates core; later
5//! phases populate `auth` and `admin`.
6
7#![forbid(unsafe_code)]
8
9// public:
10pub mod admin;
11// public:
12pub mod auth;
13// public:
14pub mod background;
15// public:
16pub mod email;
17// public:
18pub mod error;
19// public:
20pub mod http;
21// public:
22pub mod middleware;
23// public:
24pub mod migrations;
25// public:
26pub mod orm;
27// public:
28pub mod router;
29// public:
30pub mod server;
31// public:
32pub mod templates;
33
34// public:
35pub use crate::admin::{
36    register_admin_routes, Admin, AdminField, AdminModel, FieldType, Fieldset, ModelAdmin,
37};
38// public:
39pub use crate::auth::{Identity, Role};
40// public:
41pub use crate::error::{Error, Result};
42// public:
43pub use crate::http::{FormData, Request, Response};
44// public:
45pub use crate::orm::{Db, DbOptions, Model, Row, Value};
46// public:
47pub use crate::router::{Next, Router};
48// public:
49pub use crate::server::Server;
50
51// public:
52pub use rustio_admin_macros::RustioAdmin;
53
54// `RustioAdmin` emits `::rustio_admin::*` paths in its expansion. That
55// resolves cleanly for downstream consumers, but inside this crate's
56// own compilation unit `rustio_admin` isn't a known extern. Aliasing
57// the crate to itself under `cfg(test)` lets the macro be exercised
58// from this crate's own tests without changing any non-test build.
59#[cfg(test)]
60extern crate self as rustio_admin;
61
62// internal: test-only re-export surface, gated by integration-test feature
63/// Test-only re-exports for the integration-test suite under
64/// `tests/integration_*.rs`. NOT part of the public API — the
65/// module is `#[doc(hidden)]` and gated behind the
66/// `integration-test` Cargo feature, so a regular
67/// `cargo build` / `cargo test --workspace` cannot reach it.
68///
69/// Re-exports the otherwise-`pub(crate)` runtime surface of
70/// `auth::recovery_admin` so the integration tests can exercise
71/// `record_failed_login`, `admin_set_temp_password`, etc. without
72/// promoting the internal API to permanent `pub` visibility.
73///
74/// Plus a `fake_request()` builder for runtime fns that take
75/// `&Request` (currently `lock_user_account`,
76/// `unlock_user_account`, `admin_revoke_sessions`,
77/// `issue_admin_reset_token`, `admin_set_temp_password`). The
78/// fake request has no headers — `client_ip` and
79/// `correlation_id_from` both return `None`, which is the
80/// neutral state for the audit + logging layers.
81///
82/// See `DESIGN_R2_ORGANISATIONAL.md` §10.3 for the integration-
83/// test plan.
84#[doc(hidden)]
85#[cfg(feature = "integration-test")]
86pub mod __integration {
87    // internal: test-only re-export
88    pub use crate::auth::recovery_admin::{
89        admin_revoke_sessions, admin_set_temp_password, check_account_lockout,
90        check_session_elevated, issue_admin_reset_token, lock_user_account,
91        promote_session_elevated, record_failed_login, record_successful_login,
92        unlock_user_account, AdminActor, AdminIssueOutcome, AdminRevokeOutcome, AdminTempPwOutcome,
93        LockDuration, LockOutcome, LockState, ThrottleOutcome, UnlockOutcome,
94    };
95    // R3 MFA — runtime fns + outcomes + key type + pure helpers the
96    // integration suite needs to drive enrolment / verify /
97    // consume / disable / regenerate flows. The `auth::mfa` module
98    // is `pub(crate)`, so this is the only door under the
99    // `integration-test` feature. See `DESIGN_R3_MFA.md` §13.3.
100    // internal: test-only re-export
101    pub use crate::auth::mfa::{
102        confirm_enrolment, consume_backup_code, current_step, disable_mfa, generate_totp,
103        promote_session_to_mfa_verified, provision_secret, regenerate_backup_codes,
104        verify_totp_for_user, BackupConsumeOutcome, DisableOutcome, EnrolOutcome, MfaKey,
105        ProvisionedSecret, RegenOutcome, VerifyOutcome, BACKUP_CODE_COUNT,
106    };
107    // internal: test-only wrapper for the pub(crate) hash helper
108    /// R4 emergency-recovery test-only helper — forwards to the
109    /// `pub(crate)` `auth::sessions::hash_token_for_storage` so
110    /// the integration suite can verify that an
111    /// `emergency_access`-issued URL stores its token in the
112    /// exact same format R1's consume path will look up later.
113    /// Catches the hex-vs-base64 drift surfaced during commit #8
114    /// (which the unit-test gate could not have seen — only a
115    /// live-DB or testcontainers run can). Wrapped rather than
116    /// `pub use`'d because the inner helper is `pub(crate)` and
117    /// cannot be re-exported under a stricter visibility.
118    /// See `DESIGN_R4_EMERGENCY.md` §9.2.
119    pub fn hash_token_for_storage(token: &str) -> String {
120        crate::auth::sessions::hash_token_for_storage(token)
121    }
122
123    // internal: test-only request builder
124    /// Construct a minimal [`crate::http::Request`] for integration
125    /// tests. POST to `/test`, no headers, no body, no params.
126    /// Adequate for runtime fns that read only `client_ip` (None)
127    /// and `correlation_id_from` (None) from the request.
128    pub fn fake_request() -> crate::http::Request {
129        use std::collections::HashMap;
130        crate::http::Request::__integration_test_fake("/test".to_string(), HashMap::new())
131    }
132}