aboutsummaryrefslogtreecommitdiff
path: root/src/consul.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-04-04 18:46:14 +0200
committerAlex Auvolat <alex@adnab.me>2023-04-04 18:46:14 +0200
commit615f926618471998f85ee184b378b1128340367b (patch)
treebe9b5d5da3e844460a533bea9fefd452892a7f32 /src/consul.rs
parente64be9e8816b9bd5d3d787d1d5d57d460ae37569 (diff)
downloaddiplonat-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.rs19
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(())
}
}