oci_api/services/vault/
client.rs1use reqwest::Method;
2
3use crate::client::Oci;
4use crate::client::request_executor::{RequestPayload, RequestTarget};
5use crate::error::Result;
6use crate::services::vault::models::SecretBundle;
7
8#[derive(Clone)]
9pub struct VaultSecretsClient {
10 oci_client: Oci,
11 endpoint: String,
12}
13
14impl VaultSecretsClient {
15 pub fn new(oci_client: &Oci) -> Self {
16 let endpoint = format!(
17 "secrets.vaults.{}.oci.{}",
18 oci_client.region(),
19 oci_client.realm_domain()
20 );
21 Self {
22 oci_client: oci_client.clone(),
23 endpoint,
24 }
25 }
26
27 pub async fn get_secret_bundle(&self, secret_id: &str) -> Result<SecretBundle> {
28 let path = format!("/20190301/secretbundles/{secret_id}");
29 let response = self
30 .oci_client
31 .executor()
32 .execute(
33 Method::GET,
34 RequestTarget {
35 scheme: "https",
36 host: &self.endpoint,
37 path: &path,
38 },
39 RequestPayload {
40 body: None,
41 content_type: None,
42 extra_headers: Vec::new(),
43 },
44 )
45 .await?;
46 response.json().await.map_err(Into::into)
47 }
48
49 pub async fn get_secret_bundle_by_stage(
50 &self,
51 secret_id: &str,
52 stage: &str,
53 ) -> Result<SecretBundle> {
54 let path = format!("/20190301/secretbundles/{secret_id}?stage={stage}");
55 let response = self
56 .oci_client
57 .executor()
58 .execute(
59 Method::GET,
60 RequestTarget {
61 scheme: "https",
62 host: &self.endpoint,
63 path: &path,
64 },
65 RequestPayload {
66 body: None,
67 content_type: None,
68 extra_headers: Vec::new(),
69 },
70 )
71 .await?;
72 response.json().await.map_err(Into::into)
73 }
74
75 pub async fn get_secret_bundle_by_version(
76 &self,
77 secret_id: &str,
78 version_number: i64,
79 ) -> Result<SecretBundle> {
80 let path = format!("/20190301/secretbundles/{secret_id}?versionNumber={version_number}");
81 let response = self
82 .oci_client
83 .executor()
84 .execute(
85 Method::GET,
86 RequestTarget {
87 scheme: "https",
88 host: &self.endpoint,
89 path: &path,
90 },
91 RequestPayload {
92 body: None,
93 content_type: None,
94 extra_headers: Vec::new(),
95 },
96 )
97 .await?;
98 response.json().await.map_err(Into::into)
99 }
100}