Skip to main content

cloudillo_core/
lib.rs

1// SPDX-FileCopyrightText: Szilárd Hajba
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4//! Core infrastructure for the Cloudillo platform.
5//!
6//! This crate contains shared infrastructure modules that are used by the server
7//! crate and potentially by future feature crates. Extracting these into a separate
8//! crate enables better build parallelism and clearer module boundaries.
9
10pub mod abac;
11pub mod acme;
12pub mod app;
13pub mod bootstrap_types;
14pub mod core_settings;
15pub mod create_perm;
16pub mod dir_cache;
17pub mod dns;
18pub mod extensions;
19pub mod extract;
20pub mod file_access;
21pub mod log;
22pub mod middleware;
23pub mod prelude;
24pub mod profile_me_cache;
25pub mod profile_visibility;
26pub mod proxy_token_cache;
27pub mod rate_limit;
28pub mod request;
29pub mod roles;
30pub mod scheduler;
31pub mod settings;
32pub mod ws_broadcast;
33pub mod ws_bus;
34
35use std::net::IpAddr;
36use std::pin::Pin;
37
38// Re-export commonly used types
39pub use app::{App, AppBuilderOpts, AppState, ServerMode};
40pub use dir_cache::{DirCache, DirEntry};
41pub use extract::{Auth, IdTag, OptionalAuth};
42pub use middleware::{PermissionCheckFactory, PermissionCheckInput, PermissionCheckOutput};
43pub use profile_me_cache::ProfileMeCache;
44pub use profile_visibility::{CommunityRole, RequesterTier, SectionVisibility};
45pub use proxy_token_cache::ProxyTokenCache;
46pub use ws_broadcast::BroadcastManager;
47
48/// Type-erased function for verifying action tokens.
49/// Registered as an extension by the server's action module.
50/// Used by auth module for the token exchange flow.
51pub type ActionVerifyFn = Box<
52	dyn for<'a> Fn(
53			&'a app::App,
54			cloudillo_types::types::TnId,
55			&'a str,
56			Option<&'a IpAddr>,
57		) -> Pin<
58			Box<
59				dyn Future<
60						Output = cloudillo_types::error::ClResult<
61							cloudillo_types::auth_adapter::ActionToken,
62						>,
63					> + Send
64					+ 'a,
65			>,
66		> + Send
67		+ Sync,
68>;
69
70/// Type-erased function for creating a complete tenant (bootstrap).
71/// Registered as an extension by the server's bootstrap module.
72/// Used by profile crate for registration and community creation.
73pub type CreateCompleteTenantFn = Box<
74	dyn for<'a> Fn(
75			&'a app::App,
76			bootstrap_types::CreateCompleteTenantOptions<'a>,
77		) -> Pin<
78			Box<
79				dyn Future<Output = cloudillo_types::error::ClResult<cloudillo_types::types::TnId>>
80					+ Send
81					+ 'a,
82			>,
83		> + Send
84		+ Sync,
85>;
86
87/// Type-erased function for creating an action.
88/// Registered as an extension by the server's action module.
89/// Used by profile crate for community CONN creation.
90pub type CreateActionFn = Box<
91	dyn for<'a> Fn(
92			&'a app::App,
93			cloudillo_types::types::TnId,
94			&'a str,
95			cloudillo_types::action_types::CreateAction,
96		) -> Pin<
97			Box<dyn Future<Output = cloudillo_types::error::ClResult<Box<str>>> + Send + 'a>,
98		> + Send
99		+ Sync,
100>;
101
102/// Parameters passed to a `ScheduleEmailFn` invocation. Mirrors
103/// `cloudillo_email::EmailTaskParams` but lives in core so the ACME renewal
104/// task (and other core-side tasks) can schedule emails without a cyclic
105/// dependency on the email crate.
106pub struct ScheduleEmailParams {
107	pub to: String,
108	pub template_name: String,
109	pub template_vars: serde_json::Value,
110	pub lang: Option<String>,
111	pub custom_key: Option<String>,
112	pub from_name_override: Option<String>,
113}
114
115/// Type-erased function for scheduling a templated email via the scheduler.
116/// Registered as an extension by the server's app module (delegates to
117/// `cloudillo_email::EmailModule::schedule_email_task`).
118pub type ScheduleEmailFn = Box<
119	dyn for<'a> Fn(
120			&'a app::App,
121			cloudillo_types::types::TnId,
122			ScheduleEmailParams,
123		) -> Pin<
124			Box<dyn Future<Output = cloudillo_types::error::ClResult<()>> + Send + 'a>,
125		> + Send
126		+ Sync,
127>;
128
129/// Type-erased function invoked once the very first ACME certificate for a
130/// tenant has been successfully issued. Registered by the profile crate so
131/// it can flush deferred work (e.g. queueing a welcome email that requires
132/// HTTPS to be usable). Called from `acme::handle_renewal_success` only when
133/// the renewal row's pre-renewal `expires_at` was `None`.
134///
135/// **Implementations MUST be idempotent.** The hook may fire multiple times
136/// for the same `tn_id`: the bootstrap path (`bootstrap.rs`) and the
137/// early-retry task (`acme.rs::AcmeEarlyRetryTask`) can both observe the
138/// first successful issuance after a process restart, both with
139/// `is_first_issuance: true`. Implementations must dedupe — e.g. by using a
140/// scheduler dedup key or a marker setting cleared after first run.
141pub type OnFirstCertIssuedFn = Box<
142	dyn for<'a> Fn(
143			&'a app::App,
144			cloudillo_types::types::TnId,
145			&'a str,
146		) -> Pin<
147			Box<dyn Future<Output = cloudillo_types::error::ClResult<()>> + Send + 'a>,
148		> + Send
149		+ Sync,
150>;
151
152/// Type-erased function for ensuring a remote profile exists locally.
153/// Registered as an extension by the server's app module.
154/// Used by action hooks for profile sync.
155pub type EnsureProfileFn = Box<
156	dyn for<'a> Fn(
157			&'a app::App,
158			cloudillo_types::types::TnId,
159			&'a str,
160		) -> Pin<
161			Box<dyn Future<Output = cloudillo_types::error::ClResult<bool>> + Send + 'a>,
162		> + Send
163		+ Sync,
164>;
165
166pub fn register_settings(
167	registry: &mut settings::SettingsRegistry,
168) -> cloudillo_types::error::ClResult<()> {
169	core_settings::register_settings(registry)
170}
171
172// vim: ts=4