Skip to content

Commit

Permalink
Merge pull request #47 from nicoulaj/custom-metadata
Browse files Browse the repository at this point in the history
KV2: add support for custom metadata
  • Loading branch information
Haennetz authored Feb 11, 2024
2 parents 42c2257 + d1afbf1 commit ac6d15d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/api/kv2/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::responses::{
};
use rustify_derive::Endpoint;
use serde_json::Value;
use std::collections::HashMap;
use std::fmt::Debug;

/// ## Configure the KV Engine
Expand Down Expand Up @@ -256,6 +257,7 @@ pub struct SetSecretMetadataRequest {
pub max_versions: Option<u64>,
pub cas_required: Option<bool>,
pub delete_version_after: Option<String>,
pub custom_metadata: Option<HashMap<String, String>>,
}

/// ## Delete Metadata and All Versions
Expand Down
2 changes: 2 additions & 0 deletions src/api/kv2/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct ReadSecretResponse {
pub struct SecretVersionMetadata {
pub created_time: String,
pub deletion_time: String,
pub custom_metadata: Option<HashMap<String, String>>,
pub destroyed: bool,
pub version: u64,
}
Expand All @@ -48,6 +49,7 @@ pub struct ReadSecretMetadataResponse {
pub max_versions: u64,
pub oldest_version: u64,
pub updated_time: String,
pub custom_metadata: Option<HashMap<String, String>>,
pub versions: HashMap<String, SecretMetadata>,
}

Expand Down
16 changes: 13 additions & 3 deletions tests/kv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod common;

use common::{VaultServer, VaultServerHelper};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use test_log::test;
use vaultrs::api::kv2::requests::{SetSecretMetadataRequest, SetSecretRequestOptions};
use vaultrs::client::Client;
Expand All @@ -22,11 +23,11 @@ fn test() {
// Test set / read
test_list(&client, &endpoint).await;
test_read(&client, &endpoint).await;
test_read_metadata(&client, &endpoint).await;
test_read_version(&client, &endpoint).await;
test_set(&client, &endpoint).await;
test_set_with_compare_and_swap(&client, &endpoint).await;
test_set_metadata(&client, &endpoint).await;
test_read_metadata(&client, &endpoint).await;

// Test delete
test_delete_latest(&client, &endpoint).await;
Expand Down Expand Up @@ -94,7 +95,9 @@ async fn test_read(client: &impl Client, endpoint: &SecretEndpoint) {
async fn test_read_metadata(client: &impl Client, endpoint: &SecretEndpoint) {
let res = kv2::read_metadata(client, endpoint.path.as_str(), endpoint.name.as_str()).await;
assert!(res.is_ok());
assert!(!res.unwrap().versions.is_empty());
let response = res.unwrap();
assert!(!response.versions.is_empty());
assert!(!response.custom_metadata.unwrap().is_empty());
}

async fn test_read_version(client: &impl Client, endpoint: &SecretEndpoint) {
Expand Down Expand Up @@ -135,7 +138,14 @@ async fn test_set_metadata(client: &impl Client, endpoint: &SecretEndpoint) {
client,
endpoint.path.as_str(),
endpoint.name.as_str(),
Some(SetSecretMetadataRequest::builder().delete_version_after("1h")),
Some(
SetSecretMetadataRequest::builder()
.delete_version_after("1h")
.custom_metadata(HashMap::from([
("key1".to_string(), "foo".to_string()),
("key2".to_string(), "bar".to_string()),
])),
),
)
.await;
assert!(res.is_ok());
Expand Down

0 comments on commit ac6d15d

Please sign in to comment.