vault_client_rs/api/
ssh.rs1use reqwest::Method;
2
3use crate::VaultClient;
4use crate::api::traits::SshOperations;
5use crate::client::{encode_path, to_body};
6use crate::types::error::VaultError;
7use crate::types::ssh::*;
8
9#[derive(Debug)]
10pub struct SshHandler<'a> {
11 pub(crate) client: &'a VaultClient,
12 pub(crate) mount: String,
13}
14
15impl SshOperations for SshHandler<'_> {
16 async fn configure_ca(&self, params: &SshCaConfigRequest) -> Result<(), VaultError> {
17 let body = to_body(params)?;
18 self.client
19 .exec_empty(
20 Method::POST,
21 &format!("{}/config/ca", self.mount),
22 Some(&body),
23 )
24 .await
25 }
26
27 async fn read_public_key(&self) -> Result<SshCaPublicKey, VaultError> {
28 self.client
29 .exec_with_data(Method::GET, &format!("{}/config/ca", self.mount), None)
30 .await
31 }
32
33 async fn delete_ca(&self) -> Result<(), VaultError> {
34 self.client
35 .exec_empty(Method::DELETE, &format!("{}/config/ca", self.mount), None)
36 .await
37 }
38
39 async fn create_role(&self, name: &str, params: &SshRoleRequest) -> Result<(), VaultError> {
40 let body = to_body(params)?;
41 self.client
42 .exec_empty(
43 Method::POST,
44 &format!("{}/roles/{}", self.mount, encode_path(name)),
45 Some(&body),
46 )
47 .await
48 }
49
50 async fn read_role(&self, name: &str) -> Result<SshRole, VaultError> {
51 self.client
52 .exec_with_data(
53 Method::GET,
54 &format!("{}/roles/{}", self.mount, encode_path(name)),
55 None,
56 )
57 .await
58 }
59
60 async fn delete_role(&self, name: &str) -> Result<(), VaultError> {
61 self.client
62 .exec_empty(
63 Method::DELETE,
64 &format!("{}/roles/{}", self.mount, encode_path(name)),
65 None,
66 )
67 .await
68 }
69
70 async fn list_roles(&self) -> Result<Vec<String>, VaultError> {
71 self.client
72 .exec_list(&format!("{}/roles", self.mount))
73 .await
74 }
75
76 async fn sign_key(
77 &self,
78 role: &str,
79 params: &SshSignRequest,
80 ) -> Result<SshSignedKey, VaultError> {
81 let body = to_body(params)?;
82 self.client
83 .exec_with_data(
84 Method::POST,
85 &format!("{}/sign/{}", self.mount, encode_path(role)),
86 Some(&body),
87 )
88 .await
89 }
90
91 async fn verify_otp(&self, params: &SshVerifyRequest) -> Result<SshVerifyResponse, VaultError> {
92 let body = to_body(params)?;
93 self.client
94 .exec_with_data(Method::POST, &format!("{}/verify", self.mount), Some(&body))
95 .await
96 }
97}