Skip to main content

oci_api/services/vault/
models.rs

1use base64::{Engine as _, engine::general_purpose::STANDARD};
2use serde::{Deserialize, Serialize};
3
4use crate::error::{Error, Result};
5
6#[derive(Debug, Clone, Deserialize, Serialize)]
7#[serde(rename_all = "camelCase")]
8pub struct SecretBundleContent {
9    pub content: String,
10    pub content_type: String,
11    pub stage: Option<String>,
12    pub name: Option<String>,
13}
14
15impl SecretBundleContent {
16    pub fn decoded_bytes(&self) -> Result<Vec<u8>> {
17        STANDARD
18            .decode(&self.content)
19            .map_err(|e| Error::Other(format!("Failed to decode secret bundle content: {e}")))
20    }
21
22    pub fn decoded_string(&self) -> Result<String> {
23        String::from_utf8(self.decoded_bytes()?)
24            .map_err(|e| Error::Other(format!("Failed to decode secret bundle utf-8: {e}")))
25    }
26}
27
28#[derive(Debug, Clone, Deserialize, Serialize)]
29#[serde(rename_all = "camelCase")]
30pub struct SecretBundle {
31    pub secret_id: Option<String>,
32    pub time_created: Option<String>,
33    pub version_number: Option<i64>,
34    pub secret_bundle_content: SecretBundleContent,
35    #[serde(default)]
36    pub stages: Vec<String>,
37}