Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete the mount endpoint #90

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 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 @@ -41,6 +42,43 @@ pub struct EnableEngineDataConfig {
pub allowed_response_headers: Option<Vec<String>>,
}

/// ## Disable Secrets Engine
/// This endpoint disables the mount point specified in the URL.
///
/// * Path: sys/mounts/{self.path}
/// * Method: DELETE
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/mounts#disable-secrets-engine>

#[derive(Builder, Debug, Default, Endpoint, Serialize)]
#[endpoint(path = "sys/mounts/{self.path}", method = "DELETE", builder = "true")]
#[builder(setter(into, strip_option), default)]
pub struct DisableEngineRequest {
#[endpoint(skip)]
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
29 changes: 27 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::{
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 All @@ -183,6 +184,30 @@ pub mod mount {
api::exec_with_empty(client, endpoint).await
}

/// Disable a secret engine at the given path
///
/// See [DisableEngineRequest]
#[instrument(skip(client), err)]
pub async fn disable(client: &impl Client, path: &str) -> Result<(), ClientError> {
let endpoint = DisableEngineRequest::builder().path(path).build().unwrap();
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
16 changes: 16 additions & 0 deletions tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ 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
crate::auth::test_create_auth(&client).await;
Expand Down Expand Up @@ -130,6 +132,20 @@ 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) {
mount::disable(client, "pki_temp").await.unwrap();
assert!(
mount::get_configuration_of_a_secret_engine(client, "pki_temp")
.await
.is_err()
);
}
}

mod auth {
Expand Down
Loading