a (hacky, wip) multi-tenant oidc-terminating reverse proxy, written in anger on top of pingora
1use std::path::Path;
2use std::sync::LazyLock;
3
4use color_eyre::eyre::Context as _;
5use prost_reflect::DescriptorPool;
6
7#[allow(unused, reason = "for prost-reflect-build")]
8static DESCRIPTOR_POOL: LazyLock<DescriptorPool> = LazyLock::new(|| {
9 DescriptorPool::decode(
10 include_bytes!(concat!(env!("OUT_DIR"), "/file_descriptor_set.bin")).as_ref(),
11 )
12 .unwrap()
13});
14
15pub mod format {
16 include!(concat!(env!("OUT_DIR"), "/config.format.rs"));
17
18 impl From<&Pingora> for pingora::server::configuration::ServerConf {
19 fn from(raw: &Pingora) -> Self {
20 Self {
21 version: raw.version as usize,
22 daemon: raw.daemon,
23 error_log: raw.error_log.clone(),
24 pid_file: raw.pid_file.clone(),
25 upgrade_sock: raw.upgrade_sock.clone(),
26 user: raw.user.clone(),
27 group: raw.group.clone(),
28 threads: raw.threads as usize,
29 listener_tasks_per_fd: raw.listener_tasks_per_fd as usize,
30 work_stealing: raw.work_stealing,
31 ca_file: raw.ca_file.clone(),
32 grace_period_seconds: raw.grace_period_seconds,
33 graceful_shutdown_timeout_seconds: raw.graceful_shutdown_timeout_seconds,
34 client_bind_to_ipv4: raw.client_bind_to_ipv4.clone(),
35 client_bind_to_ipv6: raw.client_bind_to_ipv6.clone(),
36 upstream_keepalive_pool_size: raw.upstream_keepalive_pool_size as usize,
37 upstream_connect_offload_threadpools: raw
38 .upstream_connect_offload_threadpools
39 .map(|x| x as usize),
40 upstream_connect_offload_thread_per_pool: raw
41 .upstream_connect_offload_thread_per_pool
42 .map(|x| x as usize),
43 upstream_debug_ssl_keylog: raw.upstream_debug_ssl_keylog,
44 max_retries: raw.max_retries as usize,
45 upgrade_sock_connect_accept_max_retries: raw
46 .upgrade_sock_connect_accept_max_retries
47 .map(|x| x as usize),
48 }
49 }
50 }
51}
52
53/// load the config from the given file
54pub fn load(src: impl AsRef<Path>) -> color_eyre::Result<format::Config> {
55 use prost_reflect::{DynamicMessage, ReflectMessage as _};
56
57 let dynamic = DynamicMessage::parse_text_format(
58 format::Config::default().descriptor(),
59 &std::fs::read_to_string(src)
60 .context("reading config file")?,
61 )
62 .context("parsing config")?;
63
64 dynamic.transcode_to().context("validating config")
65}