use serde::{Deserialize, Serialize};
#[cfg(feature = "zeroize")]
use zeroize::{Zeroize, ZeroizeOnDrop};
#[derive(Serialize)]
pub struct UserParams<'a> {
pub name: &'a str,
pub password_hash: &'a str,
pub tags: &'a str,
}
impl<'a> UserParams<'a> {
pub fn new(name: &'a str, password_hash: &'a str, tags: &'a str) -> Self {
Self {
name,
password_hash,
tags,
}
}
pub fn administrator(name: &'a str, password_hash: &'a str) -> Self {
Self {
name,
password_hash,
tags: "administrator",
}
}
pub fn monitoring(name: &'a str, password_hash: &'a str) -> Self {
Self {
name,
password_hash,
tags: "monitoring",
}
}
pub fn management(name: &'a str, password_hash: &'a str) -> Self {
Self {
name,
password_hash,
tags: "management",
}
}
pub fn policymaker(name: &'a str, password_hash: &'a str) -> Self {
Self {
name,
password_hash,
tags: "policymaker",
}
}
pub fn without_tags(name: &'a str, password_hash: &'a str) -> Self {
Self {
name,
password_hash,
tags: "",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "zeroize", derive(Zeroize, ZeroizeOnDrop))]
pub struct OwnedUserParams {
pub name: String,
pub password_hash: String,
pub tags: String,
}
impl OwnedUserParams {
pub fn new(
name: impl Into<String>,
password_hash: impl Into<String>,
tags: impl Into<String>,
) -> Self {
Self {
name: name.into(),
password_hash: password_hash.into(),
tags: tags.into(),
}
}
pub fn administrator(name: impl Into<String>, password_hash: impl Into<String>) -> Self {
Self {
name: name.into(),
password_hash: password_hash.into(),
tags: "administrator".to_owned(),
}
}
pub fn monitoring(name: impl Into<String>, password_hash: impl Into<String>) -> Self {
Self {
name: name.into(),
password_hash: password_hash.into(),
tags: "monitoring".to_owned(),
}
}
pub fn management(name: impl Into<String>, password_hash: impl Into<String>) -> Self {
Self {
name: name.into(),
password_hash: password_hash.into(),
tags: "management".to_owned(),
}
}
pub fn policymaker(name: impl Into<String>, password_hash: impl Into<String>) -> Self {
Self {
name: name.into(),
password_hash: password_hash.into(),
tags: "policymaker".to_owned(),
}
}
pub fn without_tags(name: impl Into<String>, password_hash: impl Into<String>) -> Self {
Self {
name: name.into(),
password_hash: password_hash.into(),
tags: String::new(),
}
}
pub fn as_ref(&self) -> UserParams<'_> {
UserParams {
name: &self.name,
password_hash: &self.password_hash,
tags: &self.tags,
}
}
}
impl<'a> From<UserParams<'a>> for OwnedUserParams {
fn from(params: UserParams<'a>) -> Self {
Self {
name: params.name.to_owned(),
password_hash: params.password_hash.to_owned(),
tags: params.tags.to_owned(),
}
}
}
#[derive(Serialize, Deserialize)]
pub struct BulkUserDelete<'a> {
#[serde(borrow, rename = "users")]
pub usernames: Vec<&'a str>,
}