mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 09:22:26 +00:00
Migrate principal store to sqlite
This commit is contained in:
@@ -7,12 +7,15 @@ use chrono::{DateTime, Utc};
|
||||
use derive_more::Display;
|
||||
use rustical_xml::ValueSerialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::future::{Ready, ready};
|
||||
use std::{
|
||||
fmt::Display,
|
||||
future::{Ready, ready},
|
||||
};
|
||||
|
||||
use crate::Secret;
|
||||
|
||||
/// https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.3
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Display, clap::ValueEnum)]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, clap::ValueEnum)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PrincipalType {
|
||||
#[default]
|
||||
@@ -24,8 +27,27 @@ pub enum PrincipalType {
|
||||
// TODO: X-Name, IANA-token
|
||||
}
|
||||
|
||||
impl ValueSerialize for PrincipalType {
|
||||
fn serialize(&self) -> String {
|
||||
impl TryFrom<&str> for PrincipalType {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
Ok(match value {
|
||||
"INDIVIDUAL" => Self::Individual,
|
||||
"GROUP" => Self::Group,
|
||||
"RESOURCE" => Self::Resource,
|
||||
"ROOM" => Self::Room,
|
||||
"UNKNOWN" => Self::Unknown,
|
||||
_ => {
|
||||
return Err(crate::Error::InvalidData(
|
||||
"Invalid principal type".to_owned(),
|
||||
));
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl PrincipalType {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
PrincipalType::Individual => "INDIVIDUAL",
|
||||
PrincipalType::Group => "GROUP",
|
||||
@@ -33,7 +55,18 @@ impl ValueSerialize for PrincipalType {
|
||||
PrincipalType::Room => "ROOM",
|
||||
PrincipalType::Unknown => "UNKNOWN",
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for PrincipalType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueSerialize for PrincipalType {
|
||||
fn serialize(&self) -> String {
|
||||
self.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,8 +88,6 @@ pub struct User {
|
||||
pub principal_type: PrincipalType,
|
||||
pub password: Option<Secret<String>>,
|
||||
#[serde(default)]
|
||||
pub app_tokens: Vec<AppToken>,
|
||||
#[serde(default)]
|
||||
pub memberships: Vec<String>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user