Skip to content

Commit 3146802

Browse files
Merge pull request #1 from axelfaure/rabbitmq
Add rabbitmq generate credentials request
2 parents 595dd67 + 8a3c3a5 commit 3146802

File tree

11 files changed

+105
-35
lines changed

11 files changed

+105
-35
lines changed

src/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod identity;
66
pub mod kv1;
77
pub mod kv2;
88
pub mod pki;
9+
pub mod rabbitmq;
910
pub mod ssh;
1011
pub mod sys;
1112
pub mod token;

src/api/database/requests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub struct DeleteRoleRequest {
242242
/// * Path: {self.mount}/creds/{self.name}
243243
/// * Method: GET
244244
/// * Response: [GenerateCredentialsResponse]
245-
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/databases#read-role>
245+
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/database#generate-credentials>
246246
#[derive(Builder, Debug, Default, Endpoint)]
247247
#[endpoint(
248248
path = "{self.mount}/creds/{self.name}",

src/api/database/responses.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ pub struct GenerateCredentialsResponseData {
5353
/// [GetSecretRequest][crate::api::database::requests::GenerateCredentialsRequest]
5454
#[derive(Deserialize, Debug, Serialize)]
5555
pub struct GenerateCredentialsResponse {
56-
pub data: GenerateCredentialsResponseData,
56+
pub data: GenerateCredentialsResponseData,
5757

58-
/// Auth is always null, official doc does not document this field
59-
pub auth: Option<String>,
60-
pub lease_duration: i32,
61-
pub lease_id: String,
62-
pub renewable: bool,
63-
pub request_id: String,
58+
/// Auth is always null, official doc does not document this field
59+
pub auth: Option<String>,
60+
pub lease_duration: i32,
61+
pub lease_id: String,
62+
pub renewable: bool,
63+
pub request_id: String,
6464
}
6565

6666
/// Response from executing

src/api/rabbitmq.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod requests;
2+
pub mod responses;

src/api/rabbitmq/requests.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use super::responses::GenerateCredentialsResponse;
2+
use rustify_derive::Endpoint;
3+
use std::fmt::Debug;
4+
5+
/// ## Generate Credentials
6+
/// This endpoint generates a new set of dynamic credentials based on the named
7+
/// role.
8+
///
9+
/// * Path: {self.mount}/creds/{self.name}
10+
/// * Method: GET
11+
/// * Response: [GenerateCredentialsResponse]
12+
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/rabbitmq#generate-credentials>
13+
#[derive(Builder, Debug, Default, Endpoint)]
14+
#[endpoint(
15+
path = "{self.mount}/creds/{self.name}",
16+
response = "GenerateCredentialsResponse",
17+
builder = "true"
18+
)]
19+
#[builder(setter(into, strip_option), default)]
20+
pub struct GenerateCredentialsRequest {
21+
#[endpoint(skip)]
22+
pub mount: String,
23+
#[endpoint(skip)]
24+
pub name: String,
25+
}

src/api/rabbitmq/responses.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use serde::{Deserialize, Serialize};
2+
/// Response from executing
3+
#[derive(Deserialize, Debug, Serialize)]
4+
pub struct GenerateCredentialsResponseData {
5+
pub username: String,
6+
pub password: String,
7+
}
8+
9+
/// Response from executing
10+
/// [GetSecretRequest][crate::api::rabbitmq::requests::GenerateCredentialsRequest]
11+
#[derive(Deserialize, Debug, Serialize)]
12+
pub struct GenerateCredentialsResponse {
13+
pub data: GenerateCredentialsResponseData,
14+
15+
/// Auth is always null, official doc does not document this field
16+
pub auth: Option<String>,
17+
pub lease_duration: i32,
18+
pub lease_id: String,
19+
pub renewable: bool,
20+
pub request_id: String,
21+
}

src/api/sys/requests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,5 +463,5 @@ pub struct RandomRequest {
463463
#[builder(setter(into, strip_option), default)]
464464
pub struct RenewLeaseRequest {
465465
pub lease_id: String,
466-
pub increment: Option<String>
466+
pub increment: Option<String>,
467467
}

src/api/sys/responses.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ pub struct RandomResponse {
173173
pub random_bytes: String,
174174
}
175175

176-
177176
/// Response from executing
178177
/// [RenewLeaseRequest][crate::api::sys::requests::RenewLeaseRequest]
179178
#[derive(Deserialize, Debug, Serialize)]

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ pub mod identity;
267267
pub mod kv1;
268268
pub mod kv2;
269269
pub mod pki;
270+
pub mod rabbitmq;
270271
pub mod ssh;
271272
pub mod sys;
272273
pub mod token;

src/rabbitmq.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
pub mod role {
2+
use crate::api;
3+
use crate::api::rabbitmq::{
4+
requests::GenerateCredentialsRequest, responses::GenerateCredentialsResponse,
5+
};
6+
use crate::client::Client;
7+
use crate::error::ClientError;
8+
9+
/// Generates credentials from a role
10+
///
11+
/// See [GenerateCredentialsRequest]
12+
pub async fn creds(
13+
client: &impl Client,
14+
mount: &str,
15+
name: &str,
16+
) -> Result<GenerateCredentialsResponse, ClientError> {
17+
let endpoint = GenerateCredentialsRequest::builder()
18+
.mount(mount)
19+
.name(name)
20+
.build()
21+
.unwrap();
22+
api::exec_with_no_result(client, endpoint).await
23+
}
24+
}

0 commit comments

Comments
 (0)