hc_vault/approle/create_update.rs
1use serde::Serialize;
2
3use crate::Auth;
4use crate::Client;
5use crate::Error;
6
7/// Struct used for configuring an Approle-Role, contains all the
8/// options that are possible to set on said Role
9///
10/// [Vault-Documentation](https://www.vaultproject.io/api-docs/auth/approle#create-update-approle)
11#[derive(Debug, Serialize)]
12pub struct ApproleOptions {
13 /// If the `secret_id` is required to be present when logging in
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub bind_secret_id: Option<bool>,
16 /// Specifies blocks of IP-addresses that can use this role
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub secret_id_bound_cidrs: Option<Vec<String>>,
19 /// The Number of times a single Secret-ID can be used for login.
20 /// 0 means unlimited
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub secret_id_num_uses: Option<u64>,
23 /// The TTL of a Secret-ID
24 ///
25 /// Example-Value: `30m`
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub secret_id_ttl: Option<String>,
28 /// If the Secret-IDs generated for this role should be cluster local.
29 ///
30 /// Can't be changed after the Role has been created
31 #[serde(skip_serializing_if = "Option::is_none")]
32 pub enable_local_secret_ids: Option<bool>,
33 /// The TTL of the generated Tokens in seconds
34 #[serde(skip_serializing_if = "Option::is_none")]
35 pub token_ttl: Option<u64>,
36 /// The maximum TTL of generated Tokens in seconds
37 #[serde(skip_serializing_if = "Option::is_none")]
38 pub token_max_ttl: Option<u64>,
39 /// The Policies assigned to the generated Tokens
40 #[serde(skip_serializing_if = "Option::is_none")]
41 pub token_policies: Option<Vec<String>>,
42 /// Specifies blocks of IP-addresses that can authenticate using this role
43 /// and ties the tokens to these blocks as well
44 #[serde(skip_serializing_if = "Option::is_none")]
45 pub token_bound_cidrs: Option<Vec<String>>,
46 /// Sets an explicit maximum TTL after which every token will expire even
47 /// if it was renewed before
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub token_explicit_max_ttl: Option<u64>,
50 /// If the `default` Policy should not be set generated tokens
51 #[serde(skip_serializing_if = "Option::is_none")]
52 pub token_no_default_policy: Option<bool>,
53 /// The maximum Number of uses per generated Token, in it's lifetime
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub token_num_uses: Option<u64>,
56 /// The Period, if any, of the Tokens
57 #[serde(skip_serializing_if = "Option::is_none")]
58 pub token_period: Option<u64>,
59 /// The Type of Token that should be generated
60 #[serde(skip_serializing_if = "Option::is_none")]
61 pub token_type: Option<String>,
62}
63
64// TODO: Add test for this function
65/// Used to create or update an Approle-Role with the given options
66///
67/// # Arguments:
68/// * `client`: A valid vault-client session that is used to execute this request
69/// * `name`: The Name of the Role to modify/create
70/// * `opts`: The Options that should be applied to the role
71///
72/// [Vault-Documentation](https://www.vaultproject.io/api-docs/auth/approle#create-update-approle)
73pub async fn create_update(
74 client: &Client<impl Auth>,
75 name: &str,
76 opts: ApproleOptions,
77) -> Result<(), Error> {
78 let path = format!("auth/approle/role/{}", name);
79
80 match client
81 .vault_request(reqwest::Method::POST, &path, Some(&opts))
82 .await
83 {
84 Err(e) => Err(e),
85 Ok(_) => Ok(()),
86 }
87}