1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
// This file is auto-generated by oagen. Do not edit.
use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;
pub struct AuditLogsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdateOrganizationAuditLogsRetentionParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: UpdateAuditLogsRetention,
}
impl UpdateOrganizationAuditLogsRetentionParams {
/// Construct a new `UpdateOrganizationAuditLogsRetentionParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: UpdateAuditLogsRetention) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ListActionsParams {
/// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub before: Option<String>,
/// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<String>,
/// Upper limit on the number of objects to return, between `1` and `100`.
///
/// Defaults to `10`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Order the results by the creation time.
///
/// Defaults to `desc`.
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<PaginationOrder>,
}
impl Default for ListActionsParams {
#[allow(deprecated)]
fn default() -> Self {
Self {
before: Default::default(),
after: Default::default(),
limit: Some(10),
order: Some(PaginationOrder::Desc),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ListActionSchemasParams {
/// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub before: Option<String>,
/// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<String>,
/// Upper limit on the number of objects to return, between `1` and `100`.
///
/// Defaults to `10`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Order the results by the creation time.
///
/// Defaults to `desc`.
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<PaginationOrder>,
}
impl Default for ListActionSchemasParams {
#[allow(deprecated)]
fn default() -> Self {
Self {
before: Default::default(),
after: Default::default(),
limit: Some(10),
order: Some(PaginationOrder::Desc),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateSchemaParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: AuditLogSchemaInput,
}
impl CreateSchemaParams {
/// Construct a new `CreateSchemaParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: AuditLogSchemaInput) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateEventParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: AuditLogEventIngestion,
}
impl CreateEventParams {
/// Construct a new `CreateEventParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: AuditLogEventIngestion) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateExportParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: AuditLogExportCreation,
}
impl CreateExportParams {
/// Construct a new `CreateExportParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: AuditLogExportCreation) -> Self {
Self { body }
}
}
impl<'a> AuditLogsApi<'a> {
/// Get Retention
///
/// Get the configured event retention period for the given Organization.
pub async fn get_organization_audit_logs_retention(
&self,
id: &str,
) -> Result<AuditLogsRetention, Error> {
self.get_organization_audit_logs_retention_with_options(id, None)
.await
}
/// Variant of [`Self::get_organization_audit_logs_retention`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_organization_audit_logs_retention_with_options(
&self,
id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<AuditLogsRetention, Error> {
let id = crate::client::path_segment(id);
let path = format!("/organizations/{id}/audit_logs_retention");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, &(), options)
.await
}
/// Set Retention
///
/// Set the event retention period for the given Organization.
pub async fn update_organization_audit_logs_retention(
&self,
id: &str,
params: UpdateOrganizationAuditLogsRetentionParams,
) -> Result<AuditLogsRetention, Error> {
self.update_organization_audit_logs_retention_with_options(id, params, None)
.await
}
/// Variant of [`Self::update_organization_audit_logs_retention`] that accepts per-request [`crate::RequestOptions`].
pub async fn update_organization_audit_logs_retention_with_options(
&self,
id: &str,
params: UpdateOrganizationAuditLogsRetentionParams,
options: Option<&crate::RequestOptions>,
) -> Result<AuditLogsRetention, Error> {
let id = crate::client::path_segment(id);
let path = format!("/organizations/{id}/audit_logs_retention");
let method = http::Method::PUT;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
/// List Actions
///
/// Get a list of all Audit Log actions in the current environment.
pub async fn list_actions(
&self,
params: ListActionsParams,
) -> Result<crate::pagination::Page<AuditLogAction>, Error> {
self.list_actions_with_options(params, None).await
}
/// Variant of [`Self::list_actions`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_actions_with_options(
&self,
params: ListActionsParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::pagination::Page<AuditLogAction>, Error> {
let path = "/audit_logs/actions".to_string();
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, ¶ms, options)
.await
}
/// Returns an async [`futures_util::Stream`] that yields every `AuditLogAction`
/// across all pages, advancing the `after` cursor under the hood.
///
/// ```ignore
/// use futures_util::TryStreamExt;
/// let all: Vec<AuditLogAction> = self
/// .list_actions_auto_paging(params)
/// .try_collect()
/// .await?;
/// ```
pub fn list_actions_auto_paging(
&self,
params: ListActionsParams,
) -> impl futures_util::Stream<Item = Result<AuditLogAction, Error>> + '_ {
crate::pagination::auto_paginate_pages(move |after| {
let mut params = params.clone();
params.after = after;
async move {
let page = self.list_actions(params).await?;
Ok((page.data, page.list_metadata.after))
}
})
}
/// List Schemas
///
/// Get a list of all schemas for the Audit Logs action identified by `:name`.
pub async fn list_action_schemas(
&self,
action_name: &str,
params: ListActionSchemasParams,
) -> Result<crate::pagination::Page<AuditLogSchema>, Error> {
self.list_action_schemas_with_options(action_name, params, None)
.await
}
/// Variant of [`Self::list_action_schemas`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_action_schemas_with_options(
&self,
action_name: &str,
params: ListActionSchemasParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::pagination::Page<AuditLogSchema>, Error> {
let action_name = crate::client::path_segment(action_name);
let path = format!("/audit_logs/actions/{action_name}/schemas");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, ¶ms, options)
.await
}
/// Returns an async [`futures_util::Stream`] that yields every `AuditLogSchema`
/// across all pages, advancing the `after` cursor under the hood.
///
/// ```ignore
/// use futures_util::TryStreamExt;
/// let all: Vec<AuditLogSchema> = self
/// .list_action_schemas_auto_paging(action_name, params)
/// .try_collect()
/// .await?;
/// ```
pub fn list_action_schemas_auto_paging(
&self,
action_name: impl Into<String>,
params: ListActionSchemasParams,
) -> impl futures_util::Stream<Item = Result<AuditLogSchema, Error>> + '_ {
let action_name: String = action_name.into();
crate::pagination::auto_paginate_pages(move |after| {
let action_name = action_name.clone();
let mut params = params.clone();
params.after = after;
async move {
let page = self.list_action_schemas(&action_name, params).await?;
Ok((page.data, page.list_metadata.after))
}
})
}
/// Create Schema
///
/// Creates a new Audit Log schema used to validate the payload of incoming Audit Log Events. If the `action` does not exist, it will also be created.
pub async fn create_schema(
&self,
action_name: &str,
params: CreateSchemaParams,
) -> Result<AuditLogSchema, Error> {
self.create_schema_with_options(action_name, params, None)
.await
}
/// Variant of [`Self::create_schema`] that accepts per-request [`crate::RequestOptions`].
pub async fn create_schema_with_options(
&self,
action_name: &str,
params: CreateSchemaParams,
options: Option<&crate::RequestOptions>,
) -> Result<AuditLogSchema, Error> {
let action_name = crate::client::path_segment(action_name);
let path = format!("/audit_logs/actions/{action_name}/schemas");
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
/// Create Event
///
/// Create an Audit Log Event.
///
/// This API supports idempotency which guarantees that performing the same operation multiple times will have the same result as if the operation were performed only once. This is handy in situations where you may need to retry a request due to a failure or prevent accidental duplicate requests from creating more than one resource.
///
/// To achieve idempotency, you can add `Idempotency-Key` request header to a Create Event request with a unique string as the value. Each subsequent request matching this unique string will return the same response. We suggest using [v4 UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier) for idempotency keys to avoid collisions.
///
/// Idempotency keys expire after 24 hours. The API will generate a new response if you submit a request with an expired key.
pub async fn create_event(
&self,
params: CreateEventParams,
) -> Result<AuditLogEventCreateResponse, Error> {
self.create_event_with_options(params, None).await
}
/// Variant of [`Self::create_event`] that accepts per-request [`crate::RequestOptions`].
pub async fn create_event_with_options(
&self,
params: CreateEventParams,
options: Option<&crate::RequestOptions>,
) -> Result<AuditLogEventCreateResponse, Error> {
let path = "/audit_logs/events".to_string();
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
/// Create Export
///
/// Create an Audit Log Export. Exports are scoped to a single organization within a specified date range.
pub async fn create_export(&self, params: CreateExportParams) -> Result<AuditLogExport, Error> {
self.create_export_with_options(params, None).await
}
/// Variant of [`Self::create_export`] that accepts per-request [`crate::RequestOptions`].
pub async fn create_export_with_options(
&self,
params: CreateExportParams,
options: Option<&crate::RequestOptions>,
) -> Result<AuditLogExport, Error> {
let path = "/audit_logs/exports".to_string();
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
/// Get Export
///
/// Get an Audit Log Export. The URL will expire after 10 minutes. If the export is needed again at a later time, refetching the export will regenerate the URL.
pub async fn get_export(&self, audit_log_export_id: &str) -> Result<AuditLogExport, Error> {
self.get_export_with_options(audit_log_export_id, None)
.await
}
/// Variant of [`Self::get_export`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_export_with_options(
&self,
audit_log_export_id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<AuditLogExport, Error> {
let audit_log_export_id = crate::client::path_segment(audit_log_export_id);
let path = format!("/audit_logs/exports/{audit_log_export_id}");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, &(), options)
.await
}
}