[core] Schema: tests first for validation and compiler determinism (red: 37+11 failing)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// 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/.
|
||||
|
||||
//! Compilers from the validated [`Model`] to the two engines. Both are pure and deterministic:
|
||||
//! the same model and options always give byte-identical output.
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use crate::Model;
|
||||
|
||||
/// Deployment facts that are not part of the routes repo (they change only with a rebuild).
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct CompileOptions {
|
||||
pub http_listen: SocketAddr,
|
||||
pub https_listen: SocketAddr,
|
||||
/// Absolute directory with Domi certificates: `<hostname>.crt` and `<hostname>.key`.
|
||||
pub cert_dir: String,
|
||||
/// Absolute state directory (edge ACME state, Caddy storage).
|
||||
pub state_dir: String,
|
||||
/// Absolute path of the access log file.
|
||||
pub access_log: String,
|
||||
/// `$CREDENTIALS_DIRECTORY` of the Caddy fallback unit, used in `{file.*}` placeholders.
|
||||
pub caddy_credentials_dir: String,
|
||||
/// Caddy admin endpoint; `None` disables the admin API.
|
||||
pub caddy_admin: Option<SocketAddr>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||
pub enum CompileError {
|
||||
#[error("compile option `{option}` is not usable: {reason}")]
|
||||
BadOption { option: &'static str, reason: &'static str },
|
||||
#[error("could not serialise the compiled config: {0}")]
|
||||
Serialize(String),
|
||||
}
|
||||
|
||||
/// Compile to the Pingora runtime config read by ianitor-edge.
|
||||
pub fn edge(model: &Model, options: &CompileOptions) -> Result<String, CompileError> {
|
||||
let _ = (model, options);
|
||||
Err(CompileError::Serialize("not implemented".into()))
|
||||
}
|
||||
|
||||
/// Compile to Caddy JSON for the caddy-fallback unit.
|
||||
pub fn caddy(model: &Model, options: &CompileOptions) -> Result<String, CompileError> {
|
||||
let _ = (model, options);
|
||||
Err(CompileError::Serialize("not implemented".into()))
|
||||
}
|
||||
Reference in New Issue
Block a user