diff options
Diffstat (limited to 'src/locking.rs')
-rw-r--r-- | src/locking.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/locking.rs b/src/locking.rs index 12e9ac0..375d3f4 100644 --- a/src/locking.rs +++ b/src/locking.rs @@ -1,3 +1,8 @@ +//! Contains structures to interact with the locks/sessions API +//! +//! See <https://developer.hashicorp.com/consul/api-docs/session> +//! for the full definition of the API. + use anyhow::Result; use bytes::Bytes; use log::*; @@ -5,37 +10,33 @@ use serde::{Deserialize, Serialize}; use crate::Consul; +/// Session creation request as specified in +/// <https://developer.hashicorp.com/consul/api-docs/session#create-session> #[derive(Serialize, Deserialize, Debug)] -pub struct ConsulSessionRequest { - #[serde(rename = "Name")] +#[serde(rename_all = "PascalCase")] +pub struct SessionRequest { pub name: String, - - #[serde(rename = "Node")] pub node: Option<String>, - - #[serde(rename = "LockDelay")] pub lock_delay: Option<String>, - #[serde(rename = "TTL")] pub ttl: Option<String>, - - #[serde(rename = "Behavior")] pub behavior: Option<String>, } +/// (for internal use, mostly) #[derive(Serialize, Deserialize, Debug)] -pub struct ConsulSessionResponse { +pub struct SessionResponse { #[serde(rename = "ID")] pub id: String, } impl Consul { - pub async fn create_session(&self, req: &ConsulSessionRequest) -> Result<String> { + pub async fn create_session(&self, req: &SessionRequest) -> Result<String> { debug!("create_session {:?}", req); let url = format!("{}/v1/session/create", self.url); let http = self.client.put(&url).json(req).send().await?; - let resp: ConsulSessionResponse = http.json().await?; + let resp: SessionResponse = http.json().await?; Ok(resp.id) } |