Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3734,6 +3734,114 @@ components:
description: The `markdownTextAnnotation` `text`.
type: string
type: object
AnonymizeUserError:
description: Error encountered when anonymizing a specific user.
properties:
error:
description: Error message describing why anonymization failed.
example: ""
type: string
user_id:
description: UUID of the user that failed to be anonymized.
example: "00000000-0000-0000-0000-000000000000"
type: string
required:
- user_id
- error
type: object
AnonymizeUsersRequest:
description: Request body for anonymizing users.
properties:
data:
$ref: "#/components/schemas/AnonymizeUsersRequestData"
required:
- data
type: object
AnonymizeUsersRequestAttributes:
description: Attributes of an anonymize users request.
properties:
user_ids:
description: List of user IDs (UUIDs) to anonymize.
example:
- "00000000-0000-0000-0000-000000000000"
items:
example: "00000000-0000-0000-0000-000000000000"
type: string
type: array
required:
- user_ids
type: object
AnonymizeUsersRequestData:
description: Object to anonymize a list of users.
properties:
attributes:
$ref: "#/components/schemas/AnonymizeUsersRequestAttributes"
id:
description: Unique identifier for the request. Not used server-side.
example: "00000000-0000-0000-0000-000000000000"
type: string
type:
$ref: "#/components/schemas/AnonymizeUsersRequestType"
required:
- type
- attributes
type: object
AnonymizeUsersRequestType:
default: anonymize_users_request
description: Type of the anonymize users request.
enum:
- anonymize_users_request
example: anonymize_users_request
type: string
x-enum-varnames:
- ANONYMIZE_USERS_REQUEST
AnonymizeUsersResponse:
description: Response containing the result of an anonymize users request.
properties:
data:
$ref: "#/components/schemas/AnonymizeUsersResponseData"
type: object
AnonymizeUsersResponseAttributes:
description: Attributes of an anonymize users response.
properties:
anonymize_errors:
description: List of errors encountered during anonymization, one entry per failed user.
items:
$ref: "#/components/schemas/AnonymizeUserError"
type: array
anonymized_user_ids:
description: List of user IDs (UUIDs) that were successfully anonymized.
example:
- "00000000-0000-0000-0000-000000000000"
items:
example: "00000000-0000-0000-0000-000000000000"
type: string
type: array
required:
- anonymized_user_ids
- anonymize_errors
type: object
AnonymizeUsersResponseData:
description: Response data for anonymizing users.
properties:
attributes:
$ref: "#/components/schemas/AnonymizeUsersResponseAttributes"
id:
description: Unique identifier of the response.
example: "00000000-0000-0000-0000-000000000000"
type: string
type:
$ref: "#/components/schemas/AnonymizeUsersResponseType"
type: object
AnonymizeUsersResponseType:
default: anonymize_users_response
description: Type of the anonymize users response.
enum:
- anonymize_users_response
example: anonymize_users_response
type: string
x-enum-varnames:
- ANONYMIZE_USERS_RESPONSE
AnthropicAPIKey:
description: The definition of the `AnthropicAPIKey` object.
properties:
Expand Down Expand Up @@ -76578,6 +76686,53 @@ paths:
operator: OR
permissions:
- security_monitoring_findings_read
/api/v2/anonymize_users:
put:
description: |-
Anonymize a list of users, removing their personal data. This operation is irreversible.
Requires the `user_access_manage` permission.
operationId: AnonymizeUsers
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/AnonymizeUsersRequest"
required: true
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/AnonymizeUsersResponse"
description: OK
"400":
content:
application/json:
schema:
$ref: "#/components/schemas/APIErrorResponse"
description: Bad Request
"403":
content:
application/json:
schema:
$ref: "#/components/schemas/APIErrorResponse"
description: Authentication error
"429":
$ref: "#/components/responses/TooManyRequestsResponse"
security:
- apiKeyAuth: []
appKeyAuth: []
- AuthZ:
- user_access_manage
summary: Anonymize users
tags:
- Users
x-codegen-request-body-name: body
x-permission:
operator: OR
permissions:
- user_access_manage
x-unstable: "**Note**: This endpoint is in Preview and may be subject to changes."
/api/v2/api_keys:
get:
description: List all API keys available for your account.
Expand Down
29 changes: 29 additions & 0 deletions examples/v2_users_AnonymizeUsers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Anonymize users returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_users::UsersAPI;
use datadog_api_client::datadogV2::model::AnonymizeUsersRequest;
use datadog_api_client::datadogV2::model::AnonymizeUsersRequestAttributes;
use datadog_api_client::datadogV2::model::AnonymizeUsersRequestData;
use datadog_api_client::datadogV2::model::AnonymizeUsersRequestType;

#[tokio::main]
async fn main() {
let body = AnonymizeUsersRequest::new(
AnonymizeUsersRequestData::new(
AnonymizeUsersRequestAttributes::new(vec![
"00000000-0000-0000-0000-000000000000".to_string()
]),
AnonymizeUsersRequestType::ANONYMIZE_USERS_REQUEST,
)
.id("00000000-0000-0000-0000-000000000000".to_string()),
);
let mut configuration = datadog::Configuration::new();
configuration.set_unstable_operation_enabled("v2.AnonymizeUsers", true);
let api = UsersAPI::with_config(configuration);
let resp = api.anonymize_users(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
1 change: 1 addition & 0 deletions src/datadog/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl Default for Configuration {
("v2.list_fleet_schedules".to_owned(), false),
("v2.trigger_fleet_schedule".to_owned(), false),
("v2.update_fleet_schedule".to_owned(), false),
("v2.anonymize_users".to_owned(), false),
("v2.create_open_api".to_owned(), false),
("v2.delete_open_api".to_owned(), false),
("v2.get_open_api".to_owned(), false),
Expand Down
172 changes: 172 additions & 0 deletions src/datadogV2/api/api_users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use flate2::{
Compression,
};
use futures_core::stream::Stream;
use log::warn;
use reqwest::header::{HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};
use std::io::Write;
Expand Down Expand Up @@ -73,6 +74,14 @@ impl ListUsersOptionalParams {
}
}

/// AnonymizeUsersError is a struct for typed errors of method [`UsersAPI::anonymize_users`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AnonymizeUsersError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}

/// CreateUserError is a struct for typed errors of method [`UsersAPI::create_user`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -219,6 +228,169 @@ impl UsersAPI {
Self { config, client }
}

/// Anonymize a list of users, removing their personal data. This operation is irreversible.
/// Requires the `user_access_manage` permission.
pub async fn anonymize_users(
&self,
body: crate::datadogV2::model::AnonymizeUsersRequest,
) -> Result<crate::datadogV2::model::AnonymizeUsersResponse, datadog::Error<AnonymizeUsersError>>
{
match self.anonymize_users_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}

/// Anonymize a list of users, removing their personal data. This operation is irreversible.
/// Requires the `user_access_manage` permission.
pub async fn anonymize_users_with_http_info(
&self,
body: crate::datadogV2::model::AnonymizeUsersRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::AnonymizeUsersResponse>,
datadog::Error<AnonymizeUsersError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.anonymize_users";
if local_configuration.is_unstable_operation_enabled(operation_id) {
warn!("Using unstable operation {operation_id}");
} else {
let local_error = datadog::UnstableOperationDisabledError {
msg: "Operation 'v2.anonymize_users' is not enabled".to_string(),
};
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
}

let local_client = &self.client;

let local_uri_str = format!(
"{}/api/v2/anonymize_users",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PUT, local_uri_str.as_str());

// build headers
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));

// build user agent
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};

// build auth
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};

// build body parameters
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
#[cfg(feature = "zstd")]
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}

local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;

let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);

if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::AnonymizeUsersResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<AnonymizeUsersError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}

/// Create a user for your organization.
pub async fn create_user(
&self,
Expand Down
Loading
Loading