//! Fresh reads of provider configuration and keys for the host harness. use sausage_vfs::{Layer, Open}; use serde::{Deserialize, Serialize}; use std::{collections::BTreeMap, sync::Arc}; pub const PATH: &str = "/etc/sausage/config.yaml"; #[derive(Default, Deserialize, Serialize)] #[serde(default)] pub struct Provider { #[serde(rename = "type")] pub api_type: String, pub base_url: String, pub api_key: String, pub catalog: Option, pub models: Vec, } #[derive(Default, Deserialize)] #[serde(default)] pub struct Config { pub providers: BTreeMap, } impl Config { pub async fn read(root: &Arc) -> anyhow::Result { 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}")) } }