chiark / gitweb /
config, wip parsing, secret
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Jul 2021 12:44:01 +0000 (13:44 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Jul 2021 12:44:01 +0000 (13:44 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/config.rs
src/prelude.rs

index ed4023e0d6e0af0a21caf5c8d3e193c37244e2b6..75c3e250f973d4222993535c2ff102e62bde677c 100644 (file)
@@ -21,13 +21,27 @@ pub struct Opts {
   pub extra_config: Vec<PathBuf>,
 }
 
-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:
index bcb3416898f0e3834a78edd20613e2eef0bdc32b..370f948f74d186e46c6b4c2b597232966bc513ad 100644 (file)
@@ -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};