summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-07-19 11:15:17 +0300
committerLars Wirzenius <liw@liw.fi>2020-07-19 11:15:17 +0300
commitf7fc28426990888a0b2f586b8c5ab60eb6a32180 (patch)
tree6951ca527ca090f7659b70a3dec781d7180d9609
parentd5b2b69c6e34822f417a5e4c3b3a533b06a52bf1 (diff)
downloadewww-f7fc28426990888a0b2f586b8c5ab60eb6a32180.tar.gz
feat: check that TLS cert and key files exist, with error message
-rw-r--r--Cargo.lock21
-rw-r--r--Cargo.toml3
-rw-r--r--src/main.rs23
3 files changed, 46 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7e7d8c2..ad8b7b1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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"
diff --git a/Cargo.toml b/Cargo.toml
index ffcdfb2..f0cd5f1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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(())
+}