Skip to content

Commit

Permalink
add get configuration of the secret engine
Browse files Browse the repository at this point in the history
  • Loading branch information
stormshield-gt committed Jul 15, 2024
1 parent a898f0b commit 9850320
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 6 deletions.
26 changes: 24 additions & 2 deletions src/api/sys/requests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::responses::{
AuthResponse, ListPoliciesResponse, MountResponse, RandomResponse, ReadHealthResponse,
ReadPolicyResponse, StartInitializationResponse, UnsealResponse, WrappingLookupResponse,
AuthResponse, GetConfigurationOfTheSecretEngineResponse, ListPoliciesResponse, MountResponse,
RandomResponse, ReadHealthResponse, ReadPolicyResponse, StartInitializationResponse,
UnsealResponse, WrappingLookupResponse,
};
use rustify_derive::Endpoint;
use serde::Serialize;
Expand Down Expand Up @@ -57,6 +58,27 @@ pub struct DisableEngineRequest {
pub path: String,
}

/// ## Get the configuration of a secret engine
/// This endpoint returns the configuration of a specific secret engine.
///
/// * Path: sys/mounts/{self.path}
/// * Method: GET
/// * Response: GetConfigurationOfTheSecretEngineResponse
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/mounts#get-the-configuration-of-a-secret-engine>
#[derive(Builder, Debug, Default, Endpoint, Serialize)]
#[endpoint(
path = "sys/mounts/{self.path}",
method = "GET",
builder = "true",
response = "GetConfigurationOfTheSecretEngineResponse"
)]
#[builder(setter(into, strip_option), default)]
pub struct GetConfigurationOfTheSecretEngineRequest {
#[endpoint(skip)]
pub path: String,
}

/// ## List Mounted Secrets Engines
/// This endpoints lists all the mounted secrets engines.
///
Expand Down
19 changes: 19 additions & 0 deletions src/api/sys/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ pub struct MountConfigResponse {
pub max_lease_ttl: u64,
}

/// Response from executing
/// [GetConfigurationOfTheSecretEngineRequest][crate::api::sys::requests::GetConfigurationOfTheSecretEngineRequest ]
#[derive(Deserialize, Debug, Serialize)]
pub struct GetConfigurationOfTheSecretEngineResponse {
pub accessor: String,
pub config: MountConfigResponse,
pub description: String,
pub external_entropy_access: bool,
pub local: bool,
pub options: Option<HashMap<String, String>>,
pub plugin_version: Option<String>,
pub running_plugin_version: Option<String>,
pub running_sha256: Option<String>,
pub seal_wrap: bool,
#[serde(rename = "type")]
pub mount_type: String,
pub uuid: String,
}

/// Response from executing
/// [ListAuthsRequest][crate::api::sys::requests::ListAuthsRequest]
#[derive(Deserialize, Debug, Serialize)]
Expand Down
20 changes: 18 additions & 2 deletions src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ pub mod mount {

use crate::api;
use crate::api::sys::requests::{
DisableEngineRequest, EnableEngineRequest, EnableEngineRequestBuilder, ListMountsRequest,
DisableEngineRequest, EnableEngineRequest, EnableEngineRequestBuilder,
GetConfigurationOfTheSecretEngineRequest, ListMountsRequest,
};
use crate::api::sys::responses::MountResponse;
use crate::api::sys::responses::{GetConfigurationOfTheSecretEngineResponse, MountResponse};
use crate::client::Client;
use crate::error::ClientError;

Expand Down Expand Up @@ -192,6 +193,21 @@ pub mod mount {
api::exec_with_empty(client, endpoint).await
}

/// This endpoint returns the configuration of a specific secret engine.
///
/// See [GetConfigurationOfTheSecretEngineRequest]
#[instrument(skip(client), err)]
pub async fn get_configuration_of_a_secret_engine(
client: &impl Client,
path: &str,
) -> Result<GetConfigurationOfTheSecretEngineResponse, ClientError> {
let endpoint = GetConfigurationOfTheSecretEngineRequest::builder()
.path(path)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}

/// Lists all mounted secret engines
///
/// See [ListMountsRequest]
Expand Down
14 changes: 12 additions & 2 deletions tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn test() {
// Test mount
crate::mount::test_create_mount(&client).await;
crate::mount::test_list_mount(&client).await;
crate::mount::test_get_configuration_of_a_secret_engine(&client).await;
crate::mount::test_delete_mount(&client).await;

// Test auth
Expand Down Expand Up @@ -131,10 +132,19 @@ mod mount {
let resp = mount::list(client).await;
assert!(resp.is_ok());
}
pub async fn test_get_configuration_of_a_secret_engine(client: &impl Client) {
mount::get_configuration_of_a_secret_engine(client, "pki_temp")
.await
.unwrap();
}

pub async fn test_delete_mount(client: &impl Client) {
let resp = mount::disable(client, "pki_temp").await;
assert!(resp.is_ok());
mount::disable(client, "pki_temp").await.unwrap();
assert!(
mount::get_configuration_of_a_secret_engine(client, "pki_temp")
.await
.is_err()
);
}
}

Expand Down

0 comments on commit 9850320

Please sign in to comment.