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