use std::collections::BTreeMap;
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};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct SecretRotation {
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_rotation_period_days")]
pub period_days: u32,
}
impl Default for SecretRotation {
fn default() -> Self {
Self {
enabled: false,
period_days: default_rotation_period_days(),
}
}
}
fn default_rotation_period_days() -> u32 {
90
}
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))]
#[serde(rename_all = "camelCase")]
pub struct MetadataTemplate {
#[serde(skip_serializing_if = "Option::is_none")]
pub annotations: Option<BTreeMap<String, String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub labels: Option<BTreeMap<String, String>>,
}
#[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),
}
}
}