bitwarden_sm/
client_secrets.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use bitwarden_core::{Client, Error};

use crate::secrets::{
    create_secret, delete_secrets, get_secret, get_secrets_by_ids, list_secrets,
    list_secrets_by_project, sync_secrets, update_secret, SecretCreateRequest, SecretGetRequest,
    SecretIdentifiersByProjectRequest, SecretIdentifiersRequest, SecretIdentifiersResponse,
    SecretPutRequest, SecretResponse, SecretsDeleteRequest, SecretsDeleteResponse,
    SecretsGetRequest, SecretsResponse, SecretsSyncRequest, SecretsSyncResponse,
};

pub struct ClientSecrets<'a> {
    client: &'a Client,
}

impl<'a> ClientSecrets<'a> {
    pub fn new(client: &'a Client) -> Self {
        Self { client }
    }

    pub async fn get(&self, input: &SecretGetRequest) -> Result<SecretResponse, Error> {
        get_secret(self.client, input).await
    }

    pub async fn get_by_ids(&self, input: SecretsGetRequest) -> Result<SecretsResponse, Error> {
        get_secrets_by_ids(self.client, input).await
    }

    pub async fn create(&self, input: &SecretCreateRequest) -> Result<SecretResponse, Error> {
        create_secret(self.client, input).await
    }

    pub async fn list(
        &self,
        input: &SecretIdentifiersRequest,
    ) -> Result<SecretIdentifiersResponse, Error> {
        list_secrets(self.client, input).await
    }

    pub async fn list_by_project(
        &self,
        input: &SecretIdentifiersByProjectRequest,
    ) -> Result<SecretIdentifiersResponse, Error> {
        list_secrets_by_project(self.client, input).await
    }

    pub async fn update(&self, input: &SecretPutRequest) -> Result<SecretResponse, Error> {
        update_secret(self.client, input).await
    }

    pub async fn delete(
        &self,
        input: SecretsDeleteRequest,
    ) -> Result<SecretsDeleteResponse, Error> {
        delete_secrets(self.client, input).await
    }

    pub async fn sync(&self, input: &SecretsSyncRequest) -> Result<SecretsSyncResponse, Error> {
        sync_secrets(self.client, input).await
    }
}

pub trait ClientSecretsExt<'a> {
    fn secrets(&'a self) -> ClientSecrets<'a>;
}

impl<'a> ClientSecretsExt<'a> for Client {
    fn secrets(&'a self) -> ClientSecrets<'a> {
        ClientSecrets::new(self)
    }
}