diff options
author | Alex Auvolat <alex@adnab.me> | 2021-12-30 20:42:56 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-12-30 20:42:56 +0100 |
commit | 04bdd029fefbce08184c12809b5d6e4bf2a12fa1 (patch) | |
tree | 9f03cccf6558df489ff05c65c23d6a01a7a2f02d /src/consul.rs | |
parent | 4560622fa125afb8ac5161f8d0e8a353f99f7a38 (diff) | |
download | diplonat-04bdd029fefbce08184c12809b5d6e4bf2a12fa1.tar.gz diplonat-04bdd029fefbce08184c12809b5d6e4bf2a12fa1.zip |
Add TLS support for Consul
Diffstat (limited to 'src/consul.rs')
-rw-r--r-- | src/consul.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/consul.rs b/src/consul.rs index 4e4f79c..4677931 100644 --- a/src/consul.rs +++ b/src/consul.rs @@ -3,6 +3,8 @@ use std::collections::HashMap; use anyhow::{anyhow, Result}; use serde::{Deserialize, Serialize}; +use crate::config::RuntimeConfigConsul; + #[derive(Serialize, Deserialize, Debug)] pub struct ServiceEntry { pub Tags: Vec<String>, @@ -20,10 +22,20 @@ pub struct Consul { } impl Consul { - pub fn new(url: &str) -> Self { + pub fn new(config: &RuntimeConfigConsul) -> Self { + let client = if let Some((ca, ident)) = config.tls.clone() { + reqwest::Client::builder() + .use_rustls_tls() + .add_root_certificate(ca) + .identity(ident) + .build() + .expect("Unable to build reqwest client") + } else { + reqwest::Client::new() + }; return Self { - client: reqwest::Client::new(), - url: url.to_string(), + client, + url: config.url.clone(), idx: None, }; } |