diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-07-19 11:15:17 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-07-19 11:15:17 +0300 |
commit | f7fc28426990888a0b2f586b8c5ab60eb6a32180 (patch) | |
tree | 6951ca527ca090f7659b70a3dec781d7180d9609 /src/main.rs | |
parent | d5b2b69c6e34822f417a5e4c3b3a533b06a52bf1 (diff) | |
download | ewww-f7fc28426990888a0b2f586b8c5ab60eb6a32180.tar.gz |
feat: check that TLS cert and key files exist, with error message
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 23 |
1 files changed, 23 insertions, 0 deletions
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(()) +} |