[control] Phase 2 control plane: routes repo via git, journaled apply with trial/watch/revert, undo and restore, push with retry, share links, API tokens, REST API with OpenAPI, --dev

This commit is contained in:
2026-11-07 18:17:06 +01:00
parent 56209cc595
commit aa0f66b5ac
20 changed files with 7165 additions and 13 deletions
+274
View File
@@ -0,0 +1,274 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! Every user-facing message, by code, in the words of docs/ui-api.md §3. `{x}` is filled from
//! the params; a missing param leaves a plain gap rather than a placeholder.
use std::collections::BTreeMap;
pub type Params = BTreeMap<String, String>;
fn template(code: &str) -> &'static str {
match code {
// 3.1 host form
"host.hostname.missing" => "Enter the address people will type, like wiki.home.example.",
"host.hostname.uppercase" => "Use lowercase letters only: {suggestion}.",
"host.hostname.characters" => "Use only letters a–z, digits, dots and dashes.",
"host.hostname.spaces" => "Remove the spaces from the address.",
"host.hostname.wildcard" => {
"Addresses with * are not supported yet. Add each name as its own host."
}
"host.hostname.trailing_dot" => "Remove the dot at the end.",
"host.hostname.empty_label" => "There are two dots in a row. Remove one.",
"host.hostname.label_dash" => "A part of the address cannot start or end with a dash.",
"host.hostname.label_long" => "Each part between dots can be at most 63 characters.",
"host.hostname.too_long" => "The address can be at most 253 characters.",
"host.hostname.numeric" => {
"That looks like an IP address. Use a name, like wiki.home.example."
}
"host.hostname.taken" => "{hostname} is already a host.",
"host.hostname.mismatch" => {
"The address in the form ({hostname}) is not the host you are editing ({path_hostname})."
}
"host.file_name" => "The address does not match the file it is stored in.",
"host.upstreams.missing" => {
"Enter where Ianitor should send traffic, like http://10.0.0.23:3000."
}
"host.upstream.not_url" => "Write it as a full address, like http://10.0.0.23:3000.",
"host.upstream.scheme" => "Start the address with http:// or https://.",
"host.upstream.no_host" => "Add the server's name or IP address after http://.",
"host.upstream.host_name" => {
"The server name is not usable. Use letters a–z, digits, dots and dashes, or an IP address."
}
"host.upstream.no_port" => "Add the port at the end, like :3000.",
"host.upstream.port_zero" => {
"Port 0 cannot be used. Enter the port the service listens on."
}
"host.upstream.path" => "Leave out the path after the port. Visitors keep their own path.",
"host.upstream.query" | "host.upstream.fragment" => "Leave out everything after ? or #.",
"host.upstream.credentials" => {
"Leave out the user name and password. Put them in a header rule with a secret instead."
}
"host.upstream.duplicate" => "This address is listed twice.",
"host.upstream.mixed_schemes" => {
"All addresses for one host must start the same way: all http:// or all https://."
}
"host.upstream.too_many" => "One host can send traffic to at most {max} addresses.",
"host.auth.not_configured" => {
"Sign-in is not set up on this server yet, so choose Anyone for now. To set it up, add the Authelia address to ianitor.toml in the routes repository."
}
"host.header.name" => "\"{name}\" cannot be a header name. Use letters, digits and dashes.",
"host.header.value" => {
"This value has characters a header cannot carry. Use visible characters and spaces only."
}
"host.header.empty" => "Enter a value, or choose Remove to drop the header.",
"host.header.protected" => "Ianitor sets {name} itself, so a rule cannot change it.",
"host.header.duplicate" => "{name} already has a rule in this list.",
"host.header.both" => "Choose a fixed value or a secret, not both.",
"host.header.remove_value" => "Remove needs only the header name.",
"host.header.secret_unknown" => {
"There is no secret named {secret}. Secrets are listed in ianitor.toml and loaded from the server's credentials."
}
"host.header.secret_response" => {
"Secrets can only be sent to your service, never back to visitors."
}
"host.health.path" => "Start with / and use plain characters, like /health.",
"host.health.interval" => "Check every 1 to 3600 seconds.",
"host.field.unknown" => "Ianitor does not know the setting \"{field}\".",
"host.field.invalid" | "file.field.invalid" => {
"One of the settings has a value Ianitor cannot use. Show details to see which."
}
"file.field.missing" => "The setting \"{field}\" is missing.",
"change.conflict" => {
"{hostname} was changed at {time} (\"{summary}\") after you opened it. Your edits are still here. Check them, then Apply again."
}
"change.unchanged" => "This is the same as what is live now, so nothing changed.",
"host.not_found" => "{hostname} is no longer a host.",
"host.share.no_signin" => {
"Anyone can already open {hostname}, so a share link changes nothing."
}
// 3.2 apply, undo, restore, repository
"apply.queued" => "Waiting for \"{summary}\" to finish, about {seconds} s.",
"apply.kept" => "{hostname} is live. Health checks passed for {seconds} s.",
"apply.kept.no_watch" => {
"{hostname} is live. It has no health check, so Ianitor only checked that it answers."
}
"apply.kept.removed" => "{hostname} is removed.",
"apply.kept.no_edge" => {
"Saved. No proxy is attached (development mode), so nothing was checked."
}
"apply.reverted.refused" => {
"{hostname} was not {verb}. {upstream} refused the connection on {count} of {of} checks. Ianitor undid the change; every other host kept running."
}
"apply.reverted.timeout" => {
"{hostname} was not {verb}. {upstream} did not answer within 5 seconds on {count} of {of} checks. Ianitor undid the change."
}
"apply.reverted.not_found" => {
"{hostname} was not {verb}. {upstream} says {path} does not exist. Check the health check address. Ianitor undid the change."
}
"apply.reverted.server_error" => {
"{hostname} was not {verb}. {upstream} answered with an error page on {count} of {of} checks. Ianitor undid the change."
}
"apply.reverted.redirect" => {
"{hostname} was not {verb}. {upstream} sent visitors elsewhere instead of answering {path}. Use an address that answers directly, like /health."
}
"apply.reverted.sign_in" => {
"{hostname} was not {verb}. {upstream} asked for a sign-in on {path}. Use an address that answers without signing in."
}
"apply.reverted.name" => {
"{hostname} was not {verb}. The name {upstream_host} could not be found on this network."
}
"apply.reverted.tls" => {
"{hostname} was not {verb}. {upstream} uses https://, but its certificate could not be checked."
}
"apply.reverted.no_answer" => {
"{hostname} was not {verb}. No health check finished within {seconds} s. Ianitor undid the change."
}
"apply.reverted.edge_lost" => {
"The proxy restarted during the check, so it went back to the last good settings. Ianitor undid the change to match."
}
"apply.failed.reload" => {
"{engine} did not take the new settings, so nothing changed. Every host kept running."
}
"apply.failed.build" => {
"Ianitor could not build the settings for this change, so nothing changed."
}
"apply.failed.validation" => {
"This change no longer fits with the routes: {first_error} Nothing changed."
}
"apply.failed.edge_unreachable" => {
"Ianitor cannot reach the proxy right now, so nothing changed. Traffic is not affected."
}
"apply.interrupted" => {
"Ianitor restarted during the check, so it undid the change to be safe."
}
"apply.interrupted.queued" => {
"Ianitor restarted before this change ran, so nothing changed. Try again."
}
"apply.cancelled" => "Cancelled before it started. Nothing changed.",
"apply.needs_attention" => {
"The change failed its check, and Ianitor could not undo it by itself. Visitors are served the last good settings, but the routes repository still has the change."
}
"push.failed.unreachable" => {
"Kept, but not yet saved to {remote}: {remote} did not answer. Ianitor tries again at {time}."
}
"push.failed.rejected" => {
"Kept, but {remote} has changes Ianitor does not have, so nothing was sent. Nothing is lost on this server."
}
"push.failed.auth" => {
"Kept, but {remote} refused Ianitor's access key. Check the key in Custos."
}
"undo.nothing" => "Nothing to undo yet.",
"undo.watching" => "Wait for the check to finish ({seconds} s).",
"undo.paused" => "Changes are paused, so Undo is not available.",
"undo.target_moved" => {
"The last change is now \"{summary}\", so Undo did nothing. Look again and choose."
}
"restore.same" => "This version is the same as the current one. Nothing to restore.",
"restore.not_kept" => {
"This change was undone at the time, so there is nothing to go back to."
}
"change.not_found" => "There is no change with that id.",
"repo.unreadable" => {
"{file} in the routes repository cannot be read. Changes are paused until it is fixed."
}
"repo.unexpected_file" => "{file} does not belong in the routes repository.",
"repo.no_remote" => "No place to push to is set up.",
// 3.4 share links
"share.disabled" => {
"Share links are off for {hostname}. Turning them on is a change to the host, checked like any other."
}
"share.prefix" => "Start with /, like /share/summer-2026. / shares the whole site.",
"share.expiry" => "Choose between 1 hour and 90 days.",
"share.password_short" => "Use at least 8 characters.",
"share.password_long" => "Use at most 128 characters.",
"share.stopped" => "Stopped. The link stops working within a few seconds.",
"share.stopped_all" => "All share links are stopped. New ones work as usual.",
"share.unavailable" => {
"Share links are not set up on this server: the share-link key is missing from the credentials."
}
"share.not_found" => "There is no share link with that id.",
"share.replaces" => "The link to replace is not a link for {hostname}.",
// 3.5 tokens, limits
"token.missing" => "This request needs an API token. Make one in Settings, API.",
"token.unknown" => {
"This API token is not one Ianitor issued, or it was copied incompletely."
}
"token.expired" => {
"This API token expired on {date}. Make a new one in Settings, API, then revoke this one."
}
"token.revoked" => "This API token was revoked on {date}.",
"token.not_found" => "There is no API token with that id.",
"token.name" => "Use 1 to 64 letters, digits, spaces, dots, dashes or underscores.",
"token.expiry" => "Choose between 1 and 3650 days, or never.",
"rate.limited" => "Too many requests in a short time. Try again in {seconds} s.",
"control.paused" => "Changes are paused: {reason} Traffic keeps flowing.",
// request shape
"request.body" => "The request body is not valid: {problem}",
"request.body_unknown_field" => "Ianitor does not know the field \"{field}\".",
"request.too_large" => "The request body is too large.",
"request.csrf" => {
"This request came from a browser page without Ianitor's UI header, so it was refused."
}
"request.host" => "This request was sent to an address Ianitor does not answer on.",
"request.not_found" => "There is no such API call.",
"request.method" => "This API call does not take that method.",
"request.idempotency" => "This Idempotency-Key was already used for a different request.",
"request.base_rev" => "base_rev is not a commit in the routes history.",
"health.unavailable" => {
"Ianitor cannot read health from {engine} right now. Traffic is not affected."
}
"internal" => "Something went wrong inside Ianitor control. Show details for more.",
_ => "Something went wrong.",
}
}
/// The message for `code`, with params filled in.
pub fn message(code: &str, params: &Params) -> String {
let t = template(code);
let mut out = String::with_capacity(t.len() + 32);
let mut rest = t;
while let Some(start) = rest.find('{') {
out.push_str(&rest[..start]);
let after = &rest[start + 1..];
match after.find('}') {
Some(end) => {
let key = &after[..end];
if let Some(v) = params.get(key) {
out.push_str(v);
}
rest = &after[end + 1..];
}
None => {
out.push_str(&rest[start..]);
rest = "";
}
}
}
out.push_str(rest);
out
}
pub fn params<const N: usize>(pairs: [(&str, String); N]) -> Params {
pairs.into_iter().map(|(k, v)| (k.to_owned(), v)).collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn placeholders_are_filled() {
let p = params([("hostname", "a.test".into()), ("max", "64".into())]);
assert_eq!(
message("host.hostname.taken", &p),
"a.test is already a host."
);
assert_eq!(
message("host.upstream.too_many", &p),
"One host can send traffic to at most 64 addresses."
);
assert!(!message("token.revoked", &Params::new()).contains('{'));
}
}