use kaniop_k8s_util::types::get_first_cloned;
use kanidm_proto::{
constants::{ATTR_GIDNUMBER, ATTR_LOGINSHELL},
v1::Entry,
};
#[cfg(feature = "schemars")]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
pub fn is_default<T: Default + PartialEq>(value: &T) -> bool {
#[cfg(feature = "examples-gen")]
{
let _ = value; false
}
#[cfg(not(feature = "examples-gen"))]
{
value == &T::default()
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[schemars(extend("x-kubernetes-validations" = [{"message": "Value is immutable", "rule": "self == oldSelf"}]))]
#[serde(rename_all = "camelCase")]
pub struct KanidmRef {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct KanidmAccountPosixAttributes {
pub gidnumber: Option<u32>,
pub loginshell: Option<String>,
}
impl PartialEq for KanidmAccountPosixAttributes {
fn eq(&self, other: &Self) -> bool {
(self.gidnumber.is_none() || self.gidnumber == other.gidnumber)
&& (self.loginshell.is_none() || self.loginshell == other.loginshell)
}
}
impl From<Entry> for KanidmAccountPosixAttributes {
fn from(entry: Entry) -> Self {
KanidmAccountPosixAttributes {
gidnumber: get_first_cloned(&entry, ATTR_GIDNUMBER).and_then(|s| s.parse::<u32>().ok()),
loginshell: get_first_cloned(&entry, ATTR_LOGINSHELL),
}
}
}