diff options
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(()) +} |