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