mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
Add CLI for most basic user management
This commit is contained in:
@@ -29,6 +29,7 @@ toml.workspace = true
|
||||
tokio.workspace = true
|
||||
rand.workspace = true
|
||||
uuid.workspace = true
|
||||
clap.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
rstest = { workspace = true }
|
||||
|
||||
@@ -6,7 +6,9 @@ use async_trait::async_trait;
|
||||
|
||||
#[async_trait]
|
||||
pub trait AuthenticationProvider: 'static {
|
||||
async fn get_principals(&self) -> Result<Vec<User>, crate::Error>;
|
||||
async fn get_principal(&self, id: &str) -> Result<Option<User>, crate::Error>;
|
||||
async fn remove_principal(&self, id: &str) -> Result<(), crate::Error>;
|
||||
async fn insert_principal(&self, user: User) -> Result<(), crate::Error>;
|
||||
async fn validate_password(&self, user_id: &str, password: &str)
|
||||
-> Result<Option<User>, Error>;
|
||||
|
||||
@@ -61,6 +61,10 @@ impl TomlPrincipalStore {
|
||||
|
||||
#[async_trait]
|
||||
impl AuthenticationProvider for TomlPrincipalStore {
|
||||
async fn get_principals(&self) -> Result<Vec<User>, crate::Error> {
|
||||
Ok(self.principals.read().await.values().cloned().collect())
|
||||
}
|
||||
|
||||
async fn get_principal(&self, id: &str) -> Result<Option<User>, crate::Error> {
|
||||
Ok(self.principals.read().await.get(id).cloned())
|
||||
}
|
||||
@@ -75,6 +79,13 @@ impl AuthenticationProvider for TomlPrincipalStore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_principal(&self, id: &str) -> Result<(), crate::Error> {
|
||||
let mut principals = self.principals.write().await;
|
||||
principals.remove(id);
|
||||
self.save(principals.deref())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn validate_password(
|
||||
&self,
|
||||
user_id: &str,
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::future::{Ready, ready};
|
||||
use crate::Secret;
|
||||
|
||||
/// https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.3
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Display, clap::ValueEnum)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PrincipalType {
|
||||
#[default]
|
||||
|
||||
Reference in New Issue
Block a user