covert_sdk/
userpass.rs

1use std::sync::Arc;
2
3pub use covert_types::methods::{
4    userpass::{
5        CreateUserParams, CreateUserResponse, ListUsersResponse, LoginParams, RemoveUserResponse,
6        UpdateUserPasswordParams, UpdateUserPasswordResponse,
7    },
8    AuthResponse,
9};
10
11use crate::{base::BaseClient, utils::get_mount_path};
12
13pub struct Client {
14    client: Arc<BaseClient>,
15}
16
17impl Client {
18    pub(crate) fn new(client: Arc<BaseClient>) -> Self {
19        Self { client }
20    }
21
22    pub async fn create(
23        &self,
24        mount: &str,
25        params: &CreateUserParams,
26    ) -> Result<CreateUserResponse, String> {
27        let path = get_mount_path(mount, "users");
28        self.client.post(path, params).await
29    }
30
31    pub async fn list(&self, mount: &str) -> Result<ListUsersResponse, String> {
32        let path = get_mount_path(mount, "users");
33        self.client.get(path).await
34    }
35
36    pub async fn login(&self, mount: &str, params: &LoginParams) -> Result<AuthResponse, String> {
37        let path = get_mount_path(mount, "login");
38        self.client.put(path, params).await
39    }
40
41    pub async fn remove(&self, mount: &str, username: &str) -> Result<RemoveUserResponse, String> {
42        let path = get_mount_path(mount, &format!("users/{username}"));
43        self.client.delete(path).await
44    }
45
46    pub async fn update_password(
47        &self,
48        mount: &str,
49        username: &str,
50        params: &UpdateUserPasswordParams,
51    ) -> Result<UpdateUserPasswordResponse, String> {
52        let path = get_mount_path(mount, &format!("users/{username}/password"));
53        self.client.put(path, params).await
54    }
55}