crates/monetize-front/src/lib.rs
//! # monetize-front — the ONE monetize's feed and its estates' enrolment
//!
//! ONE monetize, at monetize.ignalina.dk (owner 2026-10-10 13:35Z): no estate
//! runs a monetize, sold estates included; every estate CALLS IN (the pull
//! channel) and monetize dials none. What the ONE box (`monetize-admin`) takes
//! from here:
//!
//! | module | what |
//! |---|---|
//! | [`intake`] | the feed (plugins, vendors, clouds, the signup sink, secrets, the operator's `monetize.toml`) taken into monetize's config and guest files, atomically ([`intake::apply_pull`]): every product served as fed, no endpoint to dial; monetize's signing key minted once |
//! | [`attach`] | an estate joining: `POST /attach/token` (the operator's ask, [`attach::AttachTokenAsk`]) and `POST /attach/enrol` (the estate's) |
//! | [`ledger_backup`] | monetize's state sealed for the operator, and back |
//!
//! **OM-8 (5.4): the legacy dial-in lane is retired** — an estate's own plugin
//! door (tcp/8475), a primary self-registering its plugin (the `endpoint`
//! monetize then DIALLED), the feed loop that filled a block from the estate's
//! verdict. An estate is known to monetize by its enrolment and its first
//! `Fleet.Report`. (It was gunnar-front's `src/{monetize,plugin_door,
//! self_register}.rs`, gunnar-live 4c3d24d, moved here 2026-09-27.)
/// The central monetize's side of an estate attaching from another cloud (f-attach-enrol).
pub mod attach;
pub mod intake;
/// monetize's state off the front, sealed for the operator, and back onto a front laid again.
pub mod ledger_backup;
use std::path::{Path, PathBuf};
/// **Write `text` to `<root>/<rel>`, owner-only (0600), atomically** — staged,
/// synced, renamed, the directory synced (was gunnar-server's
/// `pairing::write_secret`).
pub fn write_secret(root: &Path, rel: &str, text: &str) -> std::io::Result<()> {
use std::io::Write as _;
use std::os::unix::fs::{DirBuilderExt as _, OpenOptionsExt as _};
let path = root.join(rel);
let dir = path.parent().unwrap_or(root);
std::fs::DirBuilder::new()
.recursive(true)
.mode(0o700)
.create(dir)?;
let mut tmp = path.clone().into_os_string();
tmp.push(".staging");
let _ = std::fs::remove_file(&tmp);
let mut f = std::fs::OpenOptions::new()
.write(true)
.create_new(true)
.mode(0o600)
.open(&tmp)?;
f.write_all(text.as_bytes())?;
f.sync_all()?;
drop(f);
std::fs::rename(&tmp, &path)?;
if let Ok(d) = std::fs::File::open(dir) {
let _ = d.sync_all();
}
Ok(())
}
/// **A real signed product guest for the tests**, when one is on this box:
/// `MONETIZE_FRONT_TEST_GUEST` (any product's built wasm32 guest — holger's
/// e.g. `holger_monetize_guest.wasm`). Tests that need one say SKIPPED
/// without it.
#[doc(hidden)]
pub fn test_guest() -> PathBuf {
std::env::var_os("MONETIZE_FRONT_TEST_GUEST")
.map(PathBuf::from)
.unwrap_or_default()
}