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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use bitwarden_core::Client;

use crate::{
    error::SecretsManagerError,
    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, SecretsManagerError> {
        get_secret(self.client, input).await
    }

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

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

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

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

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

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

    pub async fn sync(
        &self,
        input: &SecretsSyncRequest,
    ) -> Result<SecretsSyncResponse, SecretsManagerError> {
        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)
    }
}