use std::collections::HashMap;
use std::time::Duration;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default)]
pub struct QueryOptions {
pub datacenter: Option<String>,
pub allow_stale: bool,
pub require_consistent: bool,
pub use_cache: bool,
pub max_age: Option<Duration>,
pub stale_if_error: Option<Duration>,
pub wait_index: u64,
pub wait_time: Option<Duration>,
pub token: Option<String>,
pub namespace: Option<String>,
pub partition: Option<String>,
pub near: Option<String>,
pub node_meta: HashMap<String, String>,
pub filter: Option<String>,
}
impl QueryOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_token(mut self, token: &str) -> Self {
self.token = Some(token.to_string());
self
}
pub fn with_datacenter(mut self, dc: &str) -> Self {
self.datacenter = Some(dc.to_string());
self
}
pub fn with_namespace(mut self, ns: &str) -> Self {
self.namespace = Some(ns.to_string());
self
}
pub fn with_wait(mut self, index: u64, wait_time: Duration) -> Self {
self.wait_index = index;
self.wait_time = Some(wait_time);
self
}
pub fn with_stale(mut self) -> Self {
self.allow_stale = true;
self
}
pub fn with_consistent(mut self) -> Self {
self.require_consistent = true;
self
}
}
#[derive(Clone, Debug, Default)]
pub struct WriteOptions {
pub datacenter: Option<String>,
pub token: Option<String>,
pub namespace: Option<String>,
pub partition: Option<String>,
}
impl WriteOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_token(mut self, token: &str) -> Self {
self.token = Some(token.to_string());
self
}
pub fn with_datacenter(mut self, dc: &str) -> Self {
self.datacenter = Some(dc.to_string());
self
}
pub fn with_namespace(mut self, ns: &str) -> Self {
self.namespace = Some(ns.to_string());
self
}
}
#[derive(Clone, Debug, Default)]
pub struct QueryMeta {
pub last_index: u64,
pub last_contact: Duration,
pub known_leader: bool,
pub request_time: Duration,
pub address_translation_enabled: bool,
pub cache_hit: bool,
pub cache_age: Option<Duration>,
}
#[derive(Clone, Debug, Default)]
pub struct WriteMeta {
pub request_time: Duration,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct Node {
#[serde(rename = "ID")]
pub id: String,
pub node: String,
pub address: String,
pub datacenter: String,
#[serde(default)]
pub tagged_addresses: HashMap<String, String>,
#[serde(default)]
pub meta: HashMap<String, String>,
pub create_index: u64,
pub modify_index: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct AgentService {
#[serde(rename = "ID")]
pub id: String,
pub service: String,
#[serde(default)]
pub tags: Vec<String>,
pub port: u16,
#[serde(default)]
pub address: String,
#[serde(default)]
pub enable_tag_override: bool,
#[serde(default)]
pub meta: HashMap<String, String>,
#[serde(default)]
pub weights: Option<ServiceWeights>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ServiceWeights {
pub passing: i32,
pub warning: i32,
}
impl Default for ServiceWeights {
fn default() -> Self {
Self {
passing: 1,
warning: 1,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct CatalogService {
#[serde(rename = "ID")]
pub id: String,
pub node: String,
pub address: String,
pub datacenter: String,
#[serde(default)]
pub tagged_addresses: HashMap<String, String>,
#[serde(default)]
pub node_meta: HashMap<String, String>,
#[serde(rename = "ServiceID")]
pub service_id: String,
pub service_name: String,
#[serde(default)]
pub service_tags: Vec<String>,
#[serde(default)]
pub service_address: String,
pub service_port: u16,
#[serde(default)]
pub service_meta: HashMap<String, String>,
#[serde(default)]
pub service_weights: Option<ServiceWeights>,
pub create_index: u64,
pub modify_index: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct HealthCheck {
pub node: String,
#[serde(rename = "CheckID")]
pub check_id: String,
pub name: String,
pub status: String,
#[serde(default)]
pub notes: String,
#[serde(default)]
pub output: String,
#[serde(rename = "ServiceID")]
#[serde(default)]
pub service_id: String,
#[serde(default)]
pub service_name: String,
#[serde(default)]
pub service_tags: Vec<String>,
#[serde(rename = "Type")]
#[serde(default)]
pub check_type: String,
pub create_index: u64,
pub modify_index: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ServiceEntry {
pub node: Node,
pub service: AgentService,
pub checks: Vec<HealthCheck>,
}