vault_client_rs/api/
azure.rs1use reqwest::Method;
2
3use crate::VaultClient;
4use crate::api::traits::AzureSecretsOperations;
5use crate::client::{encode_path, to_body};
6use crate::types::azure::*;
7use crate::types::error::VaultError;
8
9#[derive(Debug)]
10pub struct AzureHandler<'a> {
11 pub(crate) client: &'a VaultClient,
12 pub(crate) mount: String,
13}
14
15impl AzureSecretsOperations for AzureHandler<'_> {
16 async fn configure(&self, params: &AzureConfigRequest) -> Result<(), VaultError> {
17 let body = to_body(params)?;
18 self.client
19 .exec_empty(Method::POST, &format!("{}/config", self.mount), Some(&body))
20 .await
21 }
22
23 async fn read_config(&self) -> Result<AzureConfig, VaultError> {
24 self.client
25 .exec_with_data(Method::GET, &format!("{}/config", self.mount), None)
26 .await
27 }
28
29 async fn delete_config(&self) -> Result<(), VaultError> {
30 self.client
31 .exec_empty(Method::DELETE, &format!("{}/config", self.mount), None)
32 .await
33 }
34
35 async fn create_role(&self, name: &str, params: &AzureRoleRequest) -> Result<(), VaultError> {
36 let body = to_body(params)?;
37 self.client
38 .exec_empty(
39 Method::POST,
40 &format!("{}/roles/{}", self.mount, encode_path(name)),
41 Some(&body),
42 )
43 .await
44 }
45
46 async fn read_role(&self, name: &str) -> Result<AzureRole, VaultError> {
47 self.client
48 .exec_with_data(
49 Method::GET,
50 &format!("{}/roles/{}", self.mount, encode_path(name)),
51 None,
52 )
53 .await
54 }
55
56 async fn delete_role(&self, name: &str) -> Result<(), VaultError> {
57 self.client
58 .exec_empty(
59 Method::DELETE,
60 &format!("{}/roles/{}", self.mount, encode_path(name)),
61 None,
62 )
63 .await
64 }
65
66 async fn list_roles(&self) -> Result<Vec<String>, VaultError> {
67 self.client
68 .exec_list(&format!("{}/roles", self.mount))
69 .await
70 }
71
72 async fn get_credentials(&self, role: &str) -> Result<AzureCredentials, VaultError> {
73 self.client
74 .exec_with_data(
75 Method::GET,
76 &format!("{}/creds/{}", self.mount, encode_path(role)),
77 None,
78 )
79 .await
80 }
81}