Files
sausage/host/src/harness/config.rs
T

31 lines
966 B
Rust

//! Fresh reads of the user-owned world proxy configuration.
use sausage_vfs::{Layer, Open};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
pub const PATH: &str = "/etc/sausage/config.yaml";
#[derive(Default, Deserialize, Serialize)]
#[serde(default)]
pub struct Proxy {
pub base_url: String,
pub api_key: String,
}
#[derive(Default, Deserialize)]
#[serde(default)]
pub struct Config {
pub proxy: Proxy,
}
impl Config {
pub async fn read(root: &Arc<dyn Layer>) -> anyhow::Result<Self> {
let file = match root.open(PATH, Open::default()).await {
Ok(file) => file,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
return Ok(Self::default());
}
Err(error) => return Err(error.into()),
};
serde_yaml_ng::from_slice(&file.read(0, 16 * 1024 * 1024).await?)
.map_err(|error| anyhow::anyhow!("Cannot read {PATH}: {error}"))
}
}