vaultrs/api/identity/entity/
requests.rs

1use rustify_derive::Endpoint;
2use serde::Serialize;
3use std::{collections::HashMap, fmt::Debug};
4
5use super::responses::{
6    CreateEntityResponse, ListEntitiesByIdResponse, ListEntitiesByNameResponse,
7    ReadEntityByIdResponse, ReadEntityByNameResponse,
8};
9
10/// ## Create an entity
11///
12/// This endpoint creates or updates an Entity.
13///
14/// Note that it's not possible to set the ID to update an existing entity, [`identity::entity::update_by_id`]
15/// is the function to call for that use case.
16///
17/// * Path: identity/entity
18/// * Method: POST
19/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#create-an-entity>
20///
21/// [`identity::entity::update_by_id`]: crate::identity::entity::update_by_id
22#[derive(Builder, Debug, Default, Endpoint)]
23#[endpoint(
24    path = "identity/entity",
25    method = "POST",
26    builder = "true",
27    response = "CreateEntityResponse"
28)]
29#[builder(setter(into, strip_option), default)]
30pub struct CreateEntityRequest {
31    /// Name of the entity.
32    pub name: Option<String>,
33    /// Metadata to be associated with the entity.
34    pub metadata: Option<HashMap<String, String>>,
35    /// Policies to be tied to the entity.
36    pub policies: Option<Vec<String>>,
37    /// Whether the entity is disabled. Disabled entities' associated tokens cannot be used, but are not revoked.
38    pub disabled: Option<bool>,
39}
40
41/// ## Read entity by ID
42///
43/// This endpoint queries the entity by its identifier.
44///
45/// * Path: identity/entity/id/{self.id}
46/// * Method: GET
47/// * Response: [ReadEntityByIdResponse]
48/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#read-entity-by-id>
49#[derive(Builder, Debug, Endpoint)]
50#[endpoint(
51    path = "identity/entity/id/{self.id}",
52    method = "GET",
53    builder = "true",
54    response = "ReadEntityByIdResponse"
55)]
56#[builder(setter(into))]
57pub struct ReadEntityByIdRequest {
58    /// Identifier of the entity.
59    #[endpoint(skip)]
60    pub id: String,
61}
62
63/// ## Update entity by ID
64///
65/// This endpoint is used to update an existing entity.
66///
67/// * Path: identity/entity/id/{self.id}
68/// * Method: POST
69/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#update-entity-by-id>
70#[derive(Builder, Debug, Default, Endpoint)]
71#[endpoint(
72    path = "identity/entity/id/{self.id}",
73    method = "POST",
74    builder = "true"
75)]
76#[builder(setter(into, strip_option), default)]
77pub struct UpdateEntityByIdRequest {
78    /// Identifier of the entity.
79    #[endpoint(skip)]
80    pub id: String,
81    /// Name of the entity.
82    pub name: Option<String>,
83    /// Metadata to be associated with the entity.
84    pub metadata: Option<HashMap<String, String>>,
85    /// Policies to be tied to the entity.
86    pub policies: Option<Vec<String>>,
87    /// Whether the entity is disabled. Disabled entities' associated tokens cannot be used, but are not revoked.
88    pub disabled: Option<bool>,
89}
90
91/// ## Delete entity by ID
92///
93/// This endpoint deletes an entity and all its associated aliases.
94///
95/// * Path: identity/entity/id/{self.id}
96/// * Method: DELETE
97/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#delete-entity-by-id>
98#[derive(Builder, Debug, Default, Endpoint)]
99#[endpoint(
100    path = "identity/entity/id/{self.id}",
101    method = "DELETE",
102    builder = "true"
103)]
104#[builder(setter(into, strip_option), default)]
105pub struct DeleteEntityByIdRequest {
106    /// Identifier of the entity.
107    #[endpoint(skip)]
108    pub id: String,
109}
110
111/// ## Batch delete entities
112///
113/// This endpoint deletes all entities provided.
114///
115/// * Path: identity/entity/batch-delete
116/// * Method: POST
117/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#batch-delete-entities>
118#[derive(Builder, Debug, Default, Endpoint)]
119#[endpoint(
120    path = "identity/entity/batch-delete",
121    method = "POST",
122    builder = "true"
123)]
124#[builder(setter(into, strip_option), default)]
125pub struct BatchDeleteRequest {
126    /// List of entity identifiers to delete.
127    pub entity_ids: Vec<String>,
128}
129
130/// ## List entities by ID
131///
132/// This endpoint returns a list of available entities by their identifiers.
133///
134/// * Path: identity/entity/id
135/// * Method: LIST
136/// * Response: [ListEntitiesByIdResponse]
137/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#list-entities-by-id>
138#[derive(Builder, Debug, Endpoint, Default)]
139#[endpoint(
140    path = "identity/entity/id",
141    method = "LIST",
142    builder = "true",
143    response = "ListEntitiesByIdResponse"
144)]
145#[builder(setter(into, strip_option), default)]
146pub struct ListEntitiesByIdRequest {}
147
148/// ## Create/Update an entity by name
149///
150/// This endpoint is used to create or update an entity by a given name.
151///
152/// * Path: identity/entity/name/{self.name}
153/// * Method: POST
154/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#create-update-entity-by-name>
155#[derive(Builder, Debug, Default, Endpoint)]
156#[endpoint(
157    path = "identity/entity/name/{self.name}",
158    method = "POST",
159    builder = "true"
160)]
161#[builder(setter(into, strip_option), default)]
162pub struct CreateEntityByNameRequest {
163    /// Name of the entity.
164    #[endpoint(skip)]
165    pub name: String,
166    /// Metadata to be associated with the entity.
167    pub metadata: Option<HashMap<String, String>>,
168    /// Policies to be tied to the entity.
169    pub policies: Option<Vec<String>>,
170    /// Whether the entity is disabled. Disabled entities' associated tokens cannot be used, but are not revoked.
171    pub disabled: Option<bool>,
172}
173
174/// ## Read entity by name
175/// This endpoint queries the entity by its name.
176///
177/// * Path: identity/entity/name/{self.name}
178/// * Method: GET
179/// * Response: [ReadEntityByNameResponse]
180/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#read-entity-by-name>
181#[derive(Builder, Debug, Endpoint, Default)]
182#[endpoint(
183    path = "identity/entity/name/{self.name}",
184    method = "GET",
185    builder = "true",
186    response = "ReadEntityByNameResponse"
187)]
188#[builder(setter(into, strip_option), default)]
189pub struct ReadEntityByNameRequest {
190    /// Name of the entity.
191    #[endpoint(skip)]
192    pub name: String,
193}
194
195/// ## Delete entity by name
196///
197/// This endpoint deletes an entity and all its associated aliases, given the entity name.
198///
199/// * Path: identity/entity/name/{self.name}
200/// * Method: DELETE
201/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#delete-entity-by-name>
202#[derive(Builder, Debug, Default, Endpoint)]
203#[endpoint(
204    path = "identity/entity/name/{self.name}",
205    method = "DELETE",
206    builder = "true"
207)]
208#[builder(setter(into, strip_option), default)]
209pub struct DeleteEntityByNameRequest {
210    /// Name of the entity.
211    #[endpoint(skip)]
212    pub name: String,
213}
214
215/// ## List entities by name
216///
217/// This endpoint returns a list of available entities by their names.
218///
219/// * Path: identity/entity/name
220/// * Method: LIST
221/// * Response: [ListEntitiesByNameResponse]
222/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#list-entities-by-name>
223#[derive(Builder, Debug, Endpoint, Default)]
224#[endpoint(
225    path = "identity/entity/name",
226    method = "LIST",
227    builder = "true",
228    response = "ListEntitiesByNameResponse"
229)]
230#[builder(setter(into, strip_option), default)]
231pub struct ListEntitiesByNameRequest {}
232
233/// ## Merge entities
234///
235/// This endpoint merges many entities into one entity.
236///
237/// * Path: identity/entity/merge
238/// * Method: POST
239/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/identity/entity#merge-entities>
240#[derive(Builder, Debug, Endpoint, Default)]
241#[endpoint(path = "identity/entity/merge", method = "POST", builder = "true")]
242#[builder(setter(into, strip_option), default)]
243pub struct MergeEntitiesRequest {
244    /// Entity IDs which need to get merged.
245    pub from_entity_ids: Vec<String>,
246    /// Entity ID into which all the other entities need to get merged.
247    pub to_entity_id: String,
248    /// Setting this will follow the 'mine' strategy for merging MFA secrets.
249    /// If there are secrets of the same type both in entities that are merged from and in entity into
250    /// which all others are getting merged, secrets in the destination will be unaltered.
251    /// If not set, this API will throw an error containing all the conflicts.
252    pub force: Option<bool>,
253    /// A list of entity aliases to keep in the case where the to-Entity and from-Entity have aliases
254    /// with the same mount accessor. In the case where alias share mount accessors, the alias ID given
255    /// in this list will be kept or merged, and the other alias will be deleted.
256    /// Note that merges requiring this parameter must have only one from-Entity.
257    pub conflicting_alias_ids_to_keep: Option<String>,
258}