use std::fmt;
#[cfg(feature = "registry-client-reqwest")]
mod reqwest;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::error::InternalError;
pub use self::reqwest::ReqwestRegistryClient;
pub trait RegistryClient {
fn add_node(&self, node: &RegistryNode) -> Result<(), InternalError>;
fn get_node(&self, identity: &str) -> Result<Option<RegistryNode>, InternalError>;
fn list_nodes(&self, filter: Option<&str>) -> Result<RegistryNodeListSlice, InternalError>;
fn update_node(&self, node: &RegistryNode) -> Result<(), InternalError>;
fn delete_node(&self, identity: &str) -> Result<(), InternalError>;
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RegistryNode {
pub identity: String,
pub endpoints: Vec<String>,
pub display_name: String,
pub keys: Vec<String>,
pub metadata: HashMap<String, String>,
}
impl fmt::Display for RegistryNode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut display_string = format!("identity: {}\nendpoints:", self.identity);
for endpoint in &self.endpoints {
display_string += &format!("\n - {}", endpoint);
}
display_string += &format!("\ndisplay name: {}\nkeys:", self.display_name);
for key in &self.keys {
display_string += &format!("\n - {}", key);
}
display_string += "\nmetadata:";
for (key, value) in &self.metadata {
display_string += &format!("\n {}: {}", key, value);
}
write!(f, "{}", display_string)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RegistryNodeListSlice {
pub data: Vec<RegistryNode>,
pub paging: Paging,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Paging {
pub current: String,
pub offset: usize,
pub limit: usize,
pub total: usize,
pub first: String,
pub prev: String,
pub next: String,
pub last: String,
}