vaultrs/api/token/
requests.rs

1use super::responses::{
2    ListAccessorResponse, ListTokenRolesResponse, LookupTokenResponse, ReadTokenRoleResponse,
3};
4use rustify_derive::Endpoint;
5use serde::Serialize;
6use std::{collections::HashMap, fmt::Debug};
7
8/// ## List Accessors
9/// This endpoint lists token accessors.
10///
11/// * Path: /auth/token/accessors
12/// * Method: LIST
13/// * Response: [ListAccessorResponse]
14/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#list-accessors>
15
16#[derive(Builder, Debug, Default, Endpoint)]
17#[endpoint(
18    path = "/auth/token/accessors",
19    method = "LIST",
20    response = "ListAccessorResponse",
21    builder = "true"
22)]
23#[builder(setter(into, strip_option), default)]
24pub struct ListAccessorRequest {}
25
26/// ## Create Token
27/// Creates a new token.
28///
29/// * Path: /auth/token/create
30/// * Method: POST
31/// * Response: N/A
32/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#create-token>
33#[derive(Builder, Debug, Default, Endpoint, Serialize)]
34#[endpoint(path = "/auth/token/create", method = "POST", builder = "true")]
35#[builder(setter(into, strip_option), default)]
36pub struct CreateTokenRequest {
37    pub display_name: Option<String>,
38    pub entity_alias: Option<String>,
39    pub explicit_max_ttl: Option<String>,
40    pub id: Option<String>,
41    pub lease: Option<String>,
42    pub meta: Option<HashMap<String, String>>,
43    pub no_default_policy: Option<bool>,
44    pub no_parent: Option<bool>,
45    pub num_uses: Option<u64>,
46    pub policies: Option<Vec<String>>,
47    pub period: Option<String>,
48    pub renewable: Option<bool>,
49    pub ttl: Option<String>,
50    #[serde(rename = "type")]
51    pub token_type: Option<String>,
52}
53
54/// ## Create Orphan Token
55/// Creates a new orphan token.
56///
57/// * Path: /auth/token/create-orphan
58/// * Method: POST
59/// * Response: N/A
60/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#create-token>
61#[derive(Builder, Debug, Default, Endpoint, Serialize)]
62#[endpoint(path = "/auth/token/create-orphan", method = "POST", builder = "true")]
63#[builder(setter(into, strip_option), default)]
64pub struct CreateOrphanTokenRequest {
65    pub display_name: Option<String>,
66    pub entity_alias: Option<String>,
67    pub explicit_max_ttl: Option<String>,
68    pub id: Option<String>,
69    pub lease: Option<String>,
70    pub meta: Option<HashMap<String, String>>,
71    pub no_default_policy: Option<bool>,
72    pub no_parent: Option<bool>,
73    pub num_uses: Option<u64>,
74    pub policies: Option<Vec<String>>,
75    pub period: Option<String>,
76    pub renewable: Option<bool>,
77    pub ttl: Option<String>,
78    #[serde(rename = "type")]
79    pub token_type: Option<String>,
80}
81
82/// ## Create Role Token
83/// Creates a new role token.
84///
85/// * Path: /auth/token/create/{self.role_name}
86/// * Method: POST
87/// * Response: N/A
88/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#create-token>
89#[derive(Builder, Debug, Default, Endpoint, Serialize)]
90#[endpoint(
91    path = "/auth/token/create/{self.role_name}",
92    method = "POST",
93    builder = "true"
94)]
95#[builder(setter(into, strip_option), default)]
96pub struct CreateRoleTokenRequest {
97    #[endpoint(skip)]
98    pub role_name: String,
99    pub display_name: Option<String>,
100    pub entity_alias: Option<String>,
101    pub explicit_max_ttl: Option<String>,
102    pub id: Option<String>,
103    pub lease: Option<String>,
104    pub meta: Option<HashMap<String, String>>,
105    pub no_default_policy: Option<bool>,
106    pub no_parent: Option<bool>,
107    pub num_uses: Option<u64>,
108    pub policies: Option<Vec<String>>,
109    pub period: Option<String>,
110    pub renewable: Option<bool>,
111    pub ttl: Option<String>,
112    #[serde(rename = "type")]
113    pub token_type: Option<String>,
114}
115
116/// ## Lookup a Token
117/// Returns information about the client token.
118///
119/// * Path: /auth/token/lookup
120/// * Method: POST
121/// * Response: [LookupTokenResponse]
122/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#lookup-a-token>
123#[derive(Builder, Debug, Default, Endpoint)]
124#[endpoint(
125    path = "/auth/token/lookup",
126    method = "POST",
127    response = "LookupTokenResponse",
128    builder = "true"
129)]
130#[builder(setter(into, strip_option), default)]
131pub struct LookupTokenRequest {
132    pub token: String,
133}
134
135/// ## Lookup a Token (Self)
136/// Returns information about the current client token.
137///
138/// * Path: /auth/token/lookup-self
139/// * Method: GET
140/// * Response: [LookupTokenResponse]
141/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#lookup-a-token-self>
142#[derive(Builder, Debug, Default, Endpoint)]
143#[endpoint(
144    path = "/auth/token/lookup-self",
145    response = "LookupTokenResponse",
146    builder = "true"
147)]
148#[builder(setter(into, strip_option), default)]
149pub struct LookupTokenSelfRequest {}
150
151/// ## Lookup a Token (Accessor)
152/// Returns information about the client token from the accessor.
153///
154/// * Path: /auth/token/lookup-accessor
155/// * Method: POST
156/// * Response: [LookupTokenResponse]
157/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#lookup-a-token-accessor>
158#[derive(Builder, Debug, Default, Endpoint)]
159#[endpoint(
160    path = "/auth/token/lookup-accessor",
161    method = "POST",
162    response = "LookupTokenResponse",
163    builder = "true"
164)]
165#[builder(setter(into, strip_option), default)]
166pub struct LookupTokenAccessorRequest {
167    pub accessor: String,
168}
169
170/// ## Renew a Token
171/// Renews a lease associated with a token.
172///
173/// * Path: /auth/token/renew
174/// * Method: POST
175/// * Response: N/A
176/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#renew-a-token>
177#[derive(Builder, Debug, Default, Endpoint)]
178#[endpoint(path = "/auth/token/renew", method = "POST", builder = "true")]
179#[builder(setter(into, strip_option), default)]
180pub struct RenewTokenRequest {
181    pub token: String,
182    pub increment: Option<String>,
183}
184
185/// ## Renew a Token (Self)
186/// Renews a lease associated with the calling token.
187///
188/// * Path: /auth/token/renew-self
189/// * Method: POST
190/// * Response: N/A
191/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#renew-a-token-self>
192#[derive(Builder, Debug, Default, Endpoint)]
193#[endpoint(path = "	/auth/token/renew-self", method = "POST", builder = "true")]
194#[builder(setter(into, strip_option), default)]
195pub struct RenewTokenSelfRequest {
196    pub increment: Option<String>,
197}
198
199/// ## Renew a Token (Accessor)
200/// Renews a lease associated with a token using its accessor.
201///
202/// * Path: /auth/token/renew-accessor
203/// * Method: POST
204/// * Response: N/A
205/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#renew-a-token-self>
206#[derive(Builder, Debug, Default, Endpoint)]
207#[endpoint(path = "/auth/token/renew-accessor", method = "POST", builder = "true")]
208#[builder(setter(into, strip_option), default)]
209pub struct RenewTokenAccessorRequest {
210    pub accessor: String,
211    pub increment: Option<String>,
212}
213
214/// ## Revoke a Token
215/// Revokes a token and all child tokens
216///
217/// * Path: /auth/token/revoke
218/// * Method: POST
219/// * Response: N/A
220/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#revoke-a-token>
221#[derive(Builder, Debug, Default, Endpoint)]
222#[endpoint(path = "/auth/token/revoke", method = "POST", builder = "true")]
223#[builder(setter(into, strip_option), default)]
224pub struct RevokeTokenRequest {
225    pub token: String,
226}
227
228/// ## Revoke a Token (Self)
229/// Revokes the token used to call it and all child tokens.
230///
231/// * Path: /auth/token/revoke-self
232/// * Method: POST
233/// * Response: N/A
234/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#revoke-a-token-self>
235#[derive(Builder, Debug, Default, Endpoint)]
236#[endpoint(path = "	/auth/token/revoke-self", method = "POST", builder = "true")]
237#[builder(setter(into, strip_option), default)]
238pub struct RevokeTokenSelfRequest {}
239
240/// ## Revoke a Token Accessor
241/// Revoke the token associated with the accessor and all the child tokens.
242///
243/// * Path: /auth/token/revoke-accessor
244/// * Method: POST
245/// * Response: N/A
246/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#revoke-a-token-accessor>
247#[derive(Builder, Debug, Default, Endpoint)]
248#[endpoint(
249    path = "/auth/token/revoke-accessor",
250    method = "POST",
251    builder = "true"
252)]
253#[builder(setter(into, strip_option), default)]
254pub struct RevokeTokenAccessorRequest {
255    pub accessor: String,
256}
257
258/// ## Revoke Token and Orphan Children
259/// Revokes a token but not its child tokens.
260///
261/// * Path: /auth/token/revoke-orphan
262/// * Method: POST
263/// * Response: N/A
264/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#revoke-token-and-orphan-children>
265#[derive(Builder, Debug, Default, Endpoint)]
266#[endpoint(path = "/auth/token/revoke-orphan", method = "POST", builder = "true")]
267#[builder(setter(into, strip_option), default)]
268pub struct RevokeTokenOrphanRequest {
269    pub token: String,
270}
271
272/// ## Read Token Role
273/// Fetches the named role configuration.
274///
275/// * Path: /auth/token/roles/{self.role_name}
276/// * Method: GET
277/// * Response: [ReadTokenRoleResponse]
278/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#read-token-role>
279#[derive(Builder, Debug, Default, Endpoint)]
280#[endpoint(
281    path = "/auth/token/roles/{self.role_name}",
282    response = "ReadTokenRoleResponse",
283    builder = "true"
284)]
285#[builder(setter(into, strip_option), default)]
286pub struct ReadTokenRoleRequest {
287    #[endpoint(skip)]
288    pub role_name: String,
289}
290
291/// ## List Token Roles
292/// List available token roles.
293///
294/// * Path: /auth/token/roles
295/// * Method: GET
296/// * Response: [ListTokenRolesResponse]
297/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#list-token-roles>
298#[derive(Builder, Debug, Default, Endpoint)]
299#[endpoint(
300    path = "/auth/token/roles",
301    method = "LIST",
302    response = "ListTokenRolesResponse",
303    builder = "true"
304)]
305#[builder(setter(into, strip_option), default)]
306pub struct ListTokenRolesRequest {}
307
308/// ## Create/Update Token Role
309/// List available token roles.
310///
311/// * Path: /auth/token/roles/:role_name
312/// * Method: POST
313/// * Response: N/A
314/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#create-update-token-role>
315#[derive(Builder, Debug, Default, Endpoint)]
316#[endpoint(
317    path = "/auth/token/roles/{self.role_name}",
318    method = "POST",
319    builder = "true"
320)]
321#[builder(setter(into, strip_option), default)]
322pub struct SetTokenRoleRequest {
323    #[endpoint(skip)]
324    pub role_name: String,
325    pub allowed_entity_aliases: Option<Vec<String>>,
326    pub allowed_policies: Option<Vec<String>>,
327    pub disallowed_policies: Option<Vec<String>>,
328    pub orphan: Option<bool>,
329    pub path_suffix: Option<String>,
330    pub renewable: Option<bool>,
331    pub token_bound_cidrs: Option<Vec<String>>,
332    pub token_explicit_max_ttl: Option<String>,
333    pub token_no_default_policy: Option<bool>,
334    pub token_num_uses: Option<u64>,
335    pub token_period: Option<String>,
336    pub token_type: Option<String>,
337}
338
339/// ## Delete Token Role
340/// This endpoint deletes the named token role.
341///
342/// * Path: /auth/token/roles/{self.role_name}
343/// * Method: DELETE
344/// * Response: N/A
345/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#delete-token-role>
346#[derive(Builder, Debug, Default, Endpoint)]
347#[endpoint(
348    path = "/auth/token/roles/{self.role_name}",
349    method = "DELETE",
350    builder = "true"
351)]
352#[builder(setter(into, strip_option), default)]
353pub struct DeleteTokenRoleRequest {
354    #[endpoint(skip)]
355    pub role_name: String,
356}
357
358/// ## Tidy Tokens
359/// Performs some maintenance tasks to clean up invalid entries that may remain
360// in the token store.
361///
362/// * Path: /auth/token/tidy
363/// * Method: POST
364/// * Response: N/A
365/// * Reference: <https://developer.hashicorp.com/vault/api-docs/auth/token#tidy-tokens>
366#[derive(Builder, Debug, Default, Endpoint)]
367#[endpoint(path = "/auth/token/tidy", method = "POST", builder = "true")]
368#[builder(setter(into, strip_option), default)]
369pub struct TidyRequest {}