diff options
-rw-r--r-- | Cargo.lock | 21 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/main.rs | 23 |
3 files changed, 46 insertions, 1 deletions
@@ -179,6 +179,7 @@ dependencies = [ "serde", "serde_yaml", "structopt", + "thiserror", "tokio", "warp", ] @@ -1200,6 +1201,26 @@ dependencies = [ ] [[package]] +name = "thiserror" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "time" version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -10,4 +10,5 @@ tokio = { version = "0.2", features = ["macros"] } serde_yaml = "0.8" serde = { version = "1", features = ["derive"] } structopt = "0.3" -anyhow = "1"
\ No newline at end of file +anyhow = "1" +thiserror = "1" diff --git a/src/main.rs b/src/main.rs index c6e22ab..d74a148 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,17 @@ struct Opt { config: PathBuf, } +#[derive(Debug, thiserror::Error)] +enum EwwwError { + #[error("TLS certificate {0} does not exist")] + TlsCertNotFound(PathBuf), + + #[error("TLS key {0} does not exist")] + TlsKeyNotFound(PathBuf), +} + + + #[tokio::main] async fn main() { let opt = Opt::from_args(); @@ -37,5 +48,17 @@ async fn main() { fn read_config(filename: &Path) -> anyhow::Result<Config> { let config = std::fs::read_to_string(filename)?; let config: Config = serde_yaml::from_str(&config)?; + check_config(&config)?; Ok(config) } + +fn check_config(config: &Config) -> anyhow::Result<()> { + if !config.tls_cert.exists() { + return Err(EwwwError::TlsCertNotFound(config.tls_cert.clone()).into()); + } + if !config.tls_key.exists() { + return Err(EwwwError::TlsKeyNotFound(config.tls_key.clone()).into()); + + } + Ok(()) +} |