-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add support for consul secret engine #73
Open
Haennetz
wants to merge
1
commit into
jmgilman:master
Choose a base branch
from
Haennetz:feature/add-consul-secret-engine
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod auth; | ||
pub mod consul; | ||
pub mod database; | ||
pub mod kv1; | ||
pub mod kv2; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod requests; | ||
pub mod responses; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
use super::responses::{GenerateConsulCredsResponse, ListRolesResponse, ReadRoleResponse}; | ||
use rustify_derive::Endpoint; | ||
|
||
/// ## Create/Update access Config | ||
/// This endpoint creates or updates a consul secret engines access configuration. | ||
/// | ||
/// * Path: {self.mount}/config/access | ||
/// * Method: POST | ||
/// * Response: N/A | ||
/// * Reference: https://www.vaultproject.io/api-docs/secret/consul#configure-access | ||
#[derive(Builder, Debug, Default, Endpoint)] | ||
#[endpoint(path = "{self.mount}/config/access", method = "POST", builder = "true")] | ||
#[builder(setter(into, strip_option), default)] | ||
pub struct SetAccessConfigRequest { | ||
#[endpoint(skip)] | ||
pub mount: String, | ||
pub address: String, | ||
pub schema: Option<String>, | ||
pub token: Option<String>, | ||
pub ca_cert: Option<String>, | ||
pub client_cert: Option<String>, | ||
pub client_key: Option<String>, | ||
} | ||
|
||
/// ## Create Role | ||
/// This endpoint creates or updates a named role. | ||
/// | ||
/// * Path: {self.mount}/roles/{self.name} | ||
/// * Method: POST | ||
/// * Response: N/A | ||
/// * Reference: https://www.vaultproject.io/api-docs/secret/consul#configure-access | ||
#[derive(Builder, Debug, Default, Endpoint)] | ||
#[endpoint( | ||
path = "{self.mount}/roles/{self.name}", | ||
method = "POST", | ||
builder = "true" | ||
)] | ||
#[builder(setter(into, strip_option), default)] | ||
pub struct SetRoleRequest { | ||
#[endpoint(skip)] | ||
pub mount: String, | ||
pub name: String, | ||
pub token_type: Option<String>, // DEPRECATED since consul version 1.4 and removed in 1.11 | ||
pub partition: Option<String>, | ||
pub node_identities: Option<Vec<String>>, | ||
pub consul_namespace: Option<String>, | ||
pub service_identities: Option<Vec<String>>, | ||
pub consul_roles: Option<Vec<String>>, | ||
pub consul_policies: Option<Vec<String>>, | ||
pub policy: Option<String>, // DEPRECATED since consul version 1.4 and removed in 1.11 | ||
pub policies: Option<Vec<String>>, // DEPRECATED since consul version 1.4 and removed in 1.11 | ||
pub local: Option<bool>, | ||
pub max_ttl: Option<String>, | ||
pub ttl: Option<String>, | ||
} | ||
|
||
/// ## Read Role | ||
/// This endpoint queries a named role. | ||
/// | ||
/// * Path: {self.mount}/roles/{self.name} | ||
/// * Method: GET | ||
/// * Response: [ReadRoleResponse] | ||
/// * Reference: https://www.vaultproject.io/api-docs/secret/consul#read-role | ||
#[derive(Builder, Debug, Default, Endpoint)] | ||
#[endpoint( | ||
path = "{self.mount}/roles/{self.name}", | ||
response = "ReadRoleResponse", | ||
builder = "true" | ||
)] | ||
#[builder(setter(into, strip_option), default)] | ||
pub struct ReadRoleRequest { | ||
#[endpoint(skip)] | ||
pub mount: String, | ||
#[endpoint(skip)] | ||
pub name: String, | ||
} | ||
|
||
/// ## List Roles | ||
/// This endpoint returns a list of available roles. | ||
/// | ||
/// * Path: {self.mount}/roles | ||
/// * Method: LIST | ||
/// * Response: [ListRolesResponse] | ||
/// * Reference: https://www.vaultproject.io/api-docs/secret/consul#list-roles | ||
#[derive(Builder, Debug, Default, Endpoint)] | ||
#[endpoint( | ||
path = "{self.mount}/roles", | ||
method = "LIST", | ||
response = "ListRolesResponse", | ||
builder = "true" | ||
)] | ||
#[builder(setter(into, strip_option), default)] | ||
pub struct ListRolesRequest { | ||
#[endpoint(skip)] | ||
pub mount: String, | ||
} | ||
|
||
/// ## Delete Role | ||
/// This endpoint deletes a named role. | ||
/// | ||
/// * Path: {self.mount}/roles/{self.name} | ||
/// * Method: DELETE | ||
/// * Response: N/A | ||
/// * Reference: https://www.vaultproject.io/api-docs/secret/consul#delete-role | ||
#[derive(Builder, Debug, Default, Endpoint)] | ||
#[endpoint( | ||
path = "{self.mount}/roles/{self.name}", | ||
method = "DELETE", | ||
builder = "true" | ||
)] | ||
#[builder(setter(into, strip_option), default)] | ||
pub struct DeleteRoleRequest { | ||
#[endpoint(skip)] | ||
pub mount: String, | ||
#[endpoint(skip)] | ||
pub name: String, | ||
} | ||
|
||
/// ## Generate Consul Credentials | ||
/// This endpoint creates credentials with the parameters defined in the given role. | ||
/// | ||
/// * Path: {self.mount}/creds/{self.name} | ||
/// * Method: POST | ||
/// * Response: [GenerateConsulCredsResponse] | ||
/// * Reference: https://www.vaultproject.io/api-docs/secret/consul#generate-credential | ||
#[derive(Builder, Debug, Default, Endpoint)] | ||
#[endpoint( | ||
path = "{self.mount}/creds/{self.name}", | ||
method = "POST", | ||
response = "GenerateConsulCredsResponse", | ||
builder = "true" | ||
)] | ||
#[builder(setter(into, strip_option), default)] | ||
pub struct GenerateConsulCredsRequest { | ||
#[endpoint(skip)] | ||
pub mount: String, | ||
#[endpoint(skip)] | ||
pub name: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Response from executing | ||
/// [ReadRoleRequest][crate::api::consul::requests::ReadRoleRequest] | ||
#[derive(Deserialize, Debug, Serialize)] | ||
pub struct ReadRoleResponse { | ||
pub token_type: Option<String>, // DEPRECATED since consul version 1.4 and removed in 1.11 | ||
pub partition: Option<String>, | ||
pub node_identities: Option<Vec<String>>, | ||
pub consul_namespace: Option<String>, | ||
pub service_identities: Option<Vec<String>>, | ||
pub consul_roles: Option<Vec<String>>, | ||
pub policy: Option<String>, // DEPRECATED since consul version 1.4 and removed in 1.11 | ||
pub policies: Option<Vec<String>>, // DEPRECATED since consul version 1.4 and removed in 1.11 | ||
pub consul_policies: Option<Vec<String>>, | ||
pub local: bool, | ||
pub max_ttl: u64, | ||
pub ttl: u64, | ||
} | ||
|
||
/// Response from executing | ||
/// [ListRolesRequest][crate::api::consul::requests::ListRolesRequest] | ||
#[derive(Deserialize, Debug, Serialize)] | ||
pub struct ListRolesResponse { | ||
pub keys: Vec<String>, | ||
} | ||
|
||
/// Response from executing | ||
/// [GenerateConsulCredsRequest][crate::api::consul::requests::GenerateConsulCredsRequest] | ||
#[derive(Deserialize, Debug, Serialize)] | ||
pub struct GenerateConsulCredsResponse { | ||
pub token: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use crate::api; | ||
use crate::api::consul::requests::GenerateConsulCredsRequest; | ||
use crate::api::consul::responses::GenerateConsulCredsResponse; | ||
use crate::client::Client; | ||
use crate::error::ClientError; | ||
|
||
/// Generates Consul credentials for the given role | ||
/// | ||
/// See [GenerateConsulCredsRequest] | ||
#[instrument(skip(client), err)] | ||
pub async fn generate( | ||
client: &impl Client, | ||
mount: &str, | ||
name: &str, | ||
) -> Result<GenerateConsulCredsResponse, ClientError> { | ||
let endpoint = GenerateConsulCredsRequest::builder() | ||
.mount(mount) | ||
.name(name) | ||
.build() | ||
.unwrap(); | ||
api::exec_with_result(client, endpoint).await | ||
} | ||
|
||
pub mod config { | ||
use crate::api; | ||
use crate::api::consul::requests::{SetAccessConfigRequest, SetAccessConfigRequestBuilder}; | ||
use crate::client::Client; | ||
use crate::error::ClientError; | ||
|
||
/// Creates or updates Consul access config | ||
/// | ||
/// See [SetAccessConfigRequest] | ||
#[instrument(skip(client, opts), err)] | ||
pub async fn set( | ||
client: &impl Client, | ||
mount: &str, | ||
opts: Option<&mut SetAccessConfigRequestBuilder>, | ||
) -> Result<(), ClientError> { | ||
let mut t = SetAccessConfigRequest::builder(); | ||
let endpoint = opts.unwrap_or(&mut t).mount(mount).build().unwrap(); | ||
api::exec_with_empty(client, endpoint).await | ||
} | ||
} | ||
|
||
pub mod role { | ||
use crate::api; | ||
use crate::api::consul::{ | ||
requests::{ | ||
DeleteRoleRequest, ListRolesRequest, ReadRoleRequest, SetRoleRequest, | ||
SetRoleRequestBuilder, | ||
}, | ||
responses::{ListRolesResponse, ReadRoleResponse}, | ||
}; | ||
use crate::client::Client; | ||
use crate::error::ClientError; | ||
|
||
/// Deletes a role | ||
/// | ||
/// See [DeleteRoleRequest] | ||
#[instrument(skip(client), err)] | ||
pub async fn delete(client: &impl Client, mount: &str, name: &str) -> Result<(), ClientError> { | ||
let endpoint = DeleteRoleRequest::builder() | ||
.mount(mount) | ||
.name(name) | ||
.build() | ||
.unwrap(); | ||
api::exec_with_empty(client, endpoint).await | ||
} | ||
|
||
/// Lists all roles | ||
/// | ||
/// See [ListRolesRequest] | ||
#[instrument(skip(client), err)] | ||
pub async fn list(client: &impl Client, mount: &str) -> Result<ListRolesResponse, ClientError> { | ||
let endpoint = ListRolesRequest::builder().mount(mount).build().unwrap(); | ||
api::exec_with_result(client, endpoint).await | ||
} | ||
|
||
/// Reads a role | ||
/// | ||
/// See [ReadRoleRequest] | ||
#[instrument(skip(client), err)] | ||
pub async fn read( | ||
client: &impl Client, | ||
mount: &str, | ||
name: &str, | ||
) -> Result<ReadRoleResponse, ClientError> { | ||
let endpoint = ReadRoleRequest::builder() | ||
.mount(mount) | ||
.name(name) | ||
.build() | ||
.unwrap(); | ||
api::exec_with_result(client, endpoint).await | ||
} | ||
|
||
/// Creates or updates a role | ||
/// | ||
/// See [SetRoleRequest] | ||
#[instrument(skip(client, opts), err)] | ||
pub async fn set( | ||
client: &impl Client, | ||
mount: &str, | ||
name: &str, | ||
opts: Option<&mut SetRoleRequestBuilder>, | ||
) -> Result<(), ClientError> { | ||
let mut t = SetRoleRequest::builder(); | ||
let endpoint = opts | ||
.unwrap_or(&mut t) | ||
.mount(mount) | ||
.name(name) | ||
.build() | ||
.unwrap(); | ||
api::exec_with_empty(client, endpoint).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.