From 2b2da3a7c15111a6f114485357aad2b692f576c8 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Fri, 11 Jun 2021 03:07:23 +0200 Subject: [PATCH] refactor: --http2-tls-cert and --http2-tls-key requires --http2 --- src/config.rs | 14 ++++++++++++-- src/server.rs | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index b94ca73..8efc362 100644 --- a/src/config.rs +++ b/src/config.rs @@ -81,11 +81,21 @@ pub struct Config { /// Enable HTTP/2 with TLS support. pub http2: bool, - #[structopt(long, default_value = "", env = "SERVER_HTTP2_TLS_CERT")] + #[structopt( + long, + required_if("http2", "true"), + default_value = "", + env = "SERVER_HTTP2_TLS_CERT" + )] /// Specify the file path to read the certificate. pub http2_tls_cert: String, - #[structopt(long, default_value = "", env = "SERVER_HTTP2_TLS_KEY")] + #[structopt( + long, + required_if("http2", "true"), + default_value = "", + env = "SERVER_HTTP2_TLS_KEY" + )] /// Specify the file path to read the private key. pub http2_tls_key: String, diff --git a/src/server.rs b/src/server.rs index b0bb735..bd8b555 100644 --- a/src/server.rs +++ b/src/server.rs @@ -137,7 +137,9 @@ impl Server { .cert_path(cert_path) .key_path(key_path) .build() - .unwrap(); + .expect( + "error during TLS server initialization, probably cert or key file missing", + ); let server = HyperServer::builder(TlsAcceptor::new(tls, incoming)).serve(router_service); -- libgit2 1.7.2