vault_client_rs/api/
gcp.rs1use reqwest::Method;
2
3use crate::VaultClient;
4use crate::api::traits::GcpSecretsOperations;
5use crate::client::{encode_path, to_body};
6use crate::types::error::VaultError;
7use crate::types::gcp::*;
8
9#[derive(Debug)]
10pub struct GcpHandler<'a> {
11 pub(crate) client: &'a VaultClient,
12 pub(crate) mount: String,
13}
14
15impl GcpSecretsOperations for GcpHandler<'_> {
16 async fn configure(&self, params: &GcpConfigRequest) -> 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<GcpConfig, 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_roleset(
36 &self,
37 name: &str,
38 params: &GcpRolesetRequest,
39 ) -> Result<(), VaultError> {
40 let body = to_body(params)?;
41 self.client
42 .exec_empty(
43 Method::POST,
44 &format!("{}/roleset/{}", self.mount, encode_path(name)),
45 Some(&body),
46 )
47 .await
48 }
49
50 async fn read_roleset(&self, name: &str) -> Result<GcpRoleset, VaultError> {
51 self.client
52 .exec_with_data(
53 Method::GET,
54 &format!("{}/roleset/{}", self.mount, encode_path(name)),
55 None,
56 )
57 .await
58 }
59
60 async fn delete_roleset(&self, name: &str) -> Result<(), VaultError> {
61 self.client
62 .exec_empty(
63 Method::DELETE,
64 &format!("{}/roleset/{}", self.mount, encode_path(name)),
65 None,
66 )
67 .await
68 }
69
70 async fn list_rolesets(&self) -> Result<Vec<String>, VaultError> {
71 self.client
72 .exec_list(&format!("{}/rolesets", self.mount))
73 .await
74 }
75
76 async fn get_service_account_key(
77 &self,
78 roleset: &str,
79 ) -> Result<GcpServiceAccountKey, VaultError> {
80 self.client
81 .exec_with_data(
82 Method::GET,
83 &format!("{}/key/{}", self.mount, encode_path(roleset)),
84 None,
85 )
86 .await
87 }
88
89 async fn get_oauth_token(&self, roleset: &str) -> Result<GcpOAuthToken, VaultError> {
90 self.client
91 .exec_with_data(
92 Method::GET,
93 &format!("{}/token/{}", self.mount, encode_path(roleset)),
94 None,
95 )
96 .await
97 }
98
99 async fn rotate_roleset(&self, name: &str) -> Result<(), VaultError> {
100 self.client
101 .exec_empty(
102 Method::POST,
103 &format!("{}/roleset/{}/rotate", self.mount, encode_path(name)),
104 None,
105 )
106 .await
107 }
108}