From: Ian Jackson Date: Sat, 24 Jul 2021 12:44:01 +0000 (+0100) Subject: config, wip parsing, secret X-Git-Tag: hippotat/1.0.0~484 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=73409ca938229f38e901607ef2c8f23ae3ed8eb9;p=hippotat.git config, wip parsing, secret Signed-off-by: Ian Jackson --- diff --git a/src/config.rs b/src/config.rs index ed4023e..75c3e25 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,13 +21,27 @@ pub struct Opts { pub extra_config: Vec, } -pub struct CidrString(pub String); +pub struct Secret(pub String); +impl Parseable for Secret { + #[throws(AE)] + fn parse(s: Option<&str>) -> Self { + let s = s.ok_or_else(|| anyhow!("value needed"))?; + if s.is_empty() { throw!(anyhow!("secret value cannot be empty")) } + Secret(s.into()) + } + #[throws(AE)] + fn default() -> Self { Secret(default()) } +} +impl Debug for Secret { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut fmt::Formatter) { write!(f, "Secret(***)")? } +} #[derive(hippotat_macros::ResolveConfig)] pub struct InstanceConfig { // Exceptional settings #[special(special_server, SKL::ServerName)] pub server: ServerName, - pub secret: String, //xxx newytpe + pub secret: Secret, #[special(special_ipif, SKL::Ordinary)] pub ipif: String, // Capped settings: diff --git a/src/prelude.rs b/src/prelude.rs index bcb3416..370f948 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,7 +5,7 @@ pub use std::collections::HashMap; pub use std::cmp::{min, max}; pub use std::fs; -pub use std::fmt::Debug; +pub use std::fmt::{self, Debug}; pub use std::io::{self, ErrorKind, Read as _}; pub use std::mem; pub use std::net::{IpAddr, Ipv4Addr};