diff options
author | Alex Auvolat <alex@adnab.me> | 2023-04-04 18:46:14 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-04-04 18:46:14 +0200 |
commit | 615f926618471998f85ee184b378b1128340367b (patch) | |
tree | be9b5d5da3e844460a533bea9fefd452892a7f32 /src/consul.rs | |
parent | e64be9e8816b9bd5d3d787d1d5d57d460ae37569 (diff) | |
download | diplonat-615f926618471998f85ee184b378b1128340367b.tar.gz diplonat-615f926618471998f85ee184b378b1128340367b.zip |
Add STUN actor that saves autodiscovered IPv4/IPv6 to Consul
Diffstat (limited to 'src/consul.rs')
-rw-r--r-- | src/consul.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/consul.rs b/src/consul.rs index c7ac2b6..e31033c 100644 --- a/src/consul.rs +++ b/src/consul.rs @@ -7,12 +7,14 @@ use crate::config::RuntimeConfigConsul; #[derive(Serialize, Deserialize, Debug)] pub struct ServiceEntry { - pub Tags: Vec<String>, + #[serde(rename = "Tags")] + pub tags: Vec<String>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Default)] pub struct CatalogNode { - pub Services: HashMap<String, ServiceEntry>, + #[serde(rename = "Services")] + pub services: HashMap<String, ServiceEntry>, } pub struct Consul { @@ -71,7 +73,14 @@ impl Consul { None => return Err(anyhow!("X-Consul-Index header not found")), }; - let resp: CatalogNode = http.json().await?; - return Ok(resp); + let resp: Option<CatalogNode> = http.json().await?; + return Ok(resp.unwrap_or_default()); + } + + pub async fn kv_put(&self, key: &str, bytes: Vec<u8>) -> Result<()> { + let url = format!("{}/v1/kv/{}", self.url, key); + let http = self.client.put(&url).body(bytes).send().await?; + http.error_for_status()?; + Ok(()) } } |