feat(cfg): turn groupnames into gids at parse time

This commit is contained in:
2026-03-10 14:36:44 +01:00
parent 054c3ff1f8
commit fb62111c7f
5 changed files with 147 additions and 20 deletions

View File

@@ -1,40 +1,40 @@
//! Configuration file structure. (TODO, docs)
use std::{
fmt::Debug,
fs::File,
io::{self, Read, Seek},
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
};
use libc::gid_t;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum Either<T, U> {
Left(T),
Right(U),
}
impl<T: Debug, U: Debug> Debug for Either<T, U> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Left(l) => l.fmt(f),
Self::Right(r) => r.fmt(f),
}
}
}
pub type Group = Either<String, gid_t>;
use crate::serdes::Group;
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(default)]
pub struct Unix {
groups: Vec<Group>,
pub groups: Vec<Group>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Server {
pub listen: SocketAddr,
}
impl Default for Server {
fn default() -> Self {
Self {
listen: SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 8080)),
}
}
}
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(default)]
pub struct Config {
unix: Unix,
pub unix: Unix,
pub server: Server,
}
#[derive(thiserror::Error, Debug)]