Skip to content

Commit

Permalink
fix: doc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Haennetz committed Mar 16, 2024
1 parent 54ca778 commit acdeb08
Show file tree
Hide file tree
Showing 31 changed files with 299 additions and 484 deletions.
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,31 @@ AWS Secret Engine.

See [tests/aws.rs][4] for more examples.

```rust
```rust,ignore
use vaultrs::sys::mount;
use vaultrs::aws;
use vaultrs::api::aws::requests::{SetConfigurationRequest, CreateUpdateRoleRequest, GenerateCredentialsRequest};
// Mount AWS SE
server.mount_secret(client, path, "aws").await?;
let endpoint = AwsSecretEngineEndpoint { path: path }
mount::enable(&client, "aws_test", "aws", None).await?;
// Configure AWS SE
aws::config::set(client, &endpoint.path, "access_key", "secret_key", Some(SetConfigurationRequest::builder()
aws::config::set(&client, "aws_test", "access_key", "secret_key", Some(SetConfigurationRequest::builder()
.max_retries(3)
.region("eu-central-1")
)).await?,
)).await?;
// Create HVault role
aws::roles::create_update(client, &endpoint.path, "my_role", "assumed_role", Some(CreateUpdateRoleRequest::builder()
.role_arns( vec!["arn:aws:iam::123456789012:role/test_role"] )
)).await?
aws::roles::create_update(&client, "aws_test", "my_role", "assumed_role", Some(CreateUpdateRoleRequest::builder()
.role_arns( vec!["arn:aws:iam::123456789012:role/test_role".to_string()] )
)).await?;
// Generate credentials
let res = aws::roles::credentials(client, &endpoint.path, "my_role", Some(GenerateCredentialsRequest::builder()
let res = aws::roles::credentials(&client, "aws_test", "my_role", Some(GenerateCredentialsRequest::builder()
.ttl("3h")
)).await?;
let creds = res.unwrap();
let creds = res;
// creds.access_key
// creds.secret_key
// creds.security_token
Expand All @@ -133,7 +136,7 @@ let creds = res.unwrap();
The library currently supports all operations available for version 2 of the
key/value store.

```rust
```rust,ignore
use serde::{Deserialize, Serialize};
use vaultrs::kv2;
Expand Down Expand Up @@ -164,31 +167,34 @@ println!("{}", secret.password); // "secret"
The library currently supports all operations available for version 1 of the
key/value store.

```rust
```rust,ignore
use vaultrs::kv1;
use std::collections::HashMap;
let my_secrets = HashMap::from([
("key1".to_string(), "value1".to_string()),
("key2".to_string(), "value2".to_string())
]);
kv1::set(&client, mount, "my/secrets", &my_secrets).await.unwrap();
kv1::set(&client, "secret", "my/secrets", &my_secrets).await.unwrap();
let read_secrets: HashMap<String, String> = kv1::get(&client, &mount, "my/secrets").await.unwrap();
let read_secrets: HashMap<String, String> = kv1::get(&client, "secret", "my/secrets").await.unwrap();
println!("{:}", read_secrets.get("key1").unwrap()); // value1
let list_secret = kv1::list(&client, &mount, "my").await.unwrap();
let list_secret = kv1::list(&client, "secret", "my").await.unwrap();
println!("{:?}", list_secret.data.keys); // [ "secrets" ]
kv1::delete(&client, &mount, "my/secrets").await.unwrap();
kv1::delete(&client, "secret", "my/secrets").await.unwrap();
```

### PKI

The library currently supports all operations available for the PKI secrets
engine.

```rust
```rust,ignore
use vaultrs::api::pki::requests::GenerateCertificateRequest;
use vaultrs::pki::cert;
Expand All @@ -208,9 +214,10 @@ The library supports most operations for the
[Transit](https://developer.hashicorp.com/vault/api-docs/secret/transit) secrets engine,
other than importing keys or `batch_input` parameters.

```rust
```rust,ignore
use vaultrs::api::transit::requests::CreateKeyRequest;
use vaultrs::api::transit::KeyType;
use vaultrs::transit::key;
// Create an encryption key using the /transit backend
key::create(
Expand All @@ -230,7 +237,7 @@ All requests implement the ability to be
[wrapped](https://developer.hashicorp.com/vault/docs/concepts/response-wrapping). These
can be passed in your application internally before being unwrapped.

```rust
```rust,ignore
use vaultrs::api::ResponseWrapper;
use vaultrs::api::sys::requests::ListMountsRequest;
Expand Down Expand Up @@ -285,4 +292,4 @@ architecture of this library and how to add additional functionality to it.
[2]: https://github.com/jmgilman/vaultrs/issues
[3]: https://github.com/jmgilman/vaultrs/tree/master/tests
[4]: https://github.com/jmgilman/vaultrs/tree/master/tests/aws.rs
[5]: https://github.com/jmgilman/vaultrs/tree/master/CONTRIBUTING.md
[5]: https://github.com/jmgilman/vaultrs/tree/master/CONTRIBUTING.md
1 change: 0 additions & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ pub struct AuthInfo {

/// Represents an API response that has been wrapped by a unique token.
///
/// See [response wrapping][1] for details on how this works. This struct stores
/// See [response wrapping][<https://developer.hashicorp.com/vault/docs/concepts/response-wrapping>] for details on how this works. This struct stores
/// the unique token returned by the server as well as the original endpoint
/// request that generated this token. The struct contains methods for
Expand Down
32 changes: 16 additions & 16 deletions src/api/auth/approle/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustify_derive::Endpoint;
/// * Path: /auth/approle/login
/// * Method: POST
/// * Response: N/A
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#login-with-approle
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#login-with-approle>
#[derive(Builder, Debug, Endpoint)]
#[endpoint(path = "/auth/{self.mount}/login", method = "POST", builder = "true")]
#[builder(setter(into))]
Expand All @@ -26,8 +26,8 @@ pub struct LoginWithApproleRequest {
///
/// * Path: /auth/{self.mount}/role
/// * Method: LIST
/// * Response: [ListRoleResponse]
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#list-roles
/// * Response: [ListRolesResponse]
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#list-roles>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role",
Expand All @@ -47,7 +47,7 @@ pub struct ListRolesRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}
/// * Method: POST
/// * Response: N/A
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#create-update-approle
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#create-update-approle>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}",
Expand Down Expand Up @@ -82,7 +82,7 @@ pub struct SetAppRoleRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}
/// * Method: GET
/// * Response: [ReadAppRoleResponse]
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#read-approle
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#read-approle>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}",
Expand All @@ -103,7 +103,7 @@ pub struct ReadAppRoleRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}
/// * Method: DELETE
/// * Response: N/A
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#delete-approle
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#delete-approle>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}",
Expand All @@ -124,7 +124,7 @@ pub struct DeleteAppRoleRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}/role-id
/// * Method: GET
/// * Response: [ReadRoleIDResponse]
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#read-approle-role-id
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#read-approle-role-id>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}/role-id",
Expand All @@ -145,7 +145,7 @@ pub struct ReadRoleIDRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}/role-id
/// * Method: POST
/// * Response: N/A
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#update-approle-role-id
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#update-approle-role-id>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}/role-id",
Expand All @@ -167,7 +167,7 @@ pub struct UpdateRoleIDRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}/secret-id
/// * Method: POST
/// * Response: [GenerateNewSecretIDResponse]
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#generate-new-secret-id
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#generate-new-secret-id>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}/secret-id",
Expand All @@ -192,7 +192,7 @@ pub struct GenerateNewSecretIDRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}/secret-id
/// * Method: LIST
/// * Response: [ListSecretIDResponse]
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#list-secret-id-accessors
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#list-secret-id-accessors>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}/secret-id",
Expand All @@ -214,7 +214,7 @@ pub struct ListSecretIDRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}/secret-id/lookup
/// * Method: POST
/// * Response: [ReadSecretIDResponse]
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#read-approle-secret-id
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#read-approle-secret-id>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}/secret-id/lookup",
Expand All @@ -237,7 +237,7 @@ pub struct ReadSecretIDRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}/secret-id/destroy
/// * Method: POST
/// * Response: N/A
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#destroy-approle-secret-id
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#destroy-approle-secret-id>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}/secret-id/destroy",
Expand All @@ -259,7 +259,7 @@ pub struct DeleteSecretIDRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}/secret-id-accessor/lookup
/// * Method: POST
/// * Response: [ReadSecretIDResponse]
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#read-approle-secret-id-accessor
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#read-approle-secret-id-accessor>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}/secret-id-accessor/lookup",
Expand All @@ -282,7 +282,7 @@ pub struct ReadSecretIDAccessorRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}/secret-id-accessor/destroy
/// * Method: POST
/// * Response: N/A
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#destroy-approle-secret-id-accessor
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#destroy-approle-secret-id-accessor>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}/secret-id-accessor/destroy",
Expand All @@ -304,7 +304,7 @@ pub struct DeleteSecretIDAccessorRequest {
/// * Path: /auth/{self.mount}/role/{self.role_name}/custom-secret-id
/// * Method: POST
/// * Response: [CreateCustomSecretIDResponse]
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#create-custom-approle-secret-id
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#create-custom-approle-secret-id>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/role/{self.role_name}/custom-secret-id",
Expand All @@ -331,7 +331,7 @@ pub struct CreateCustomSecretIDRequest {
/// * Path: /auth/{self.mount}/tidy/secret-id
/// * Method: POST
/// * Response: N/A
/// * Reference: https://developer.hashicorp.com/vault/api-docs/auth/approle#tidy-tokens
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/approle#tidy-tokens>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "/auth/{self.mount}/tidy/secret-id",
Expand Down
Loading

0 comments on commit acdeb08

Please sign in to comment.