Skip to content

Commit 5474a96

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add GetSingleEntityContext endpoint to security monitoring spec (#1726)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent f25de86 commit 5474a96

9 files changed

Lines changed: 490 additions & 5 deletions

File tree

.generator/schemas/v2/openapi.yaml

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31464,9 +31464,10 @@ components:
3146431464
additionalProperties: {}
3146531465
description: The set of attributes recorded for the entity at this revision. The keys depend on the kind of entity.
3146631466
example:
31467+
accounts:
31468+
- linked-account-123
3146731469
display_name: Test User
31468-
emails:
31469-
- user@example.com
31470+
email: user@example.com
3147031471
principal_id: user@example.com
3147131472
type: object
3147231473
EntityData:
@@ -88286,6 +88287,14 @@ components:
8828688287
type: string
8828788288
x-enum-varnames:
8828888289
- AGGREGATED_DNS
88290+
SingleEntityContextResponse:
88291+
description: Response from the single entity context endpoint, containing the matching entity.
88292+
properties:
88293+
data:
88294+
$ref: "#/components/schemas/EntityContextEntity"
88295+
required:
88296+
- data
88297+
type: object
8828988298
SlackIntegrationMetadata:
8829088299
description: Incident integration metadata for the Slack integration.
8829188300
properties:
@@ -166474,9 +166483,10 @@ paths:
166474166483
- attributes:
166475166484
revisions:
166476166485
- attributes:
166486+
accounts:
166487+
- linked-account-123
166477166488
display_name: Test User
166478-
emails:
166479-
- user@example.com
166489+
email: user@example.com
166480166490
principal_id: user@example.com
166481166491
first_seen_at: "2026-04-01T00:00:00Z"
166482166492
last_seen_at: "2026-05-01T00:00:00Z"
@@ -166507,7 +166517,98 @@ paths:
166507166517
permissions:
166508166518
- siem_entities_read
166509166519
x-unstable: |-
166510-
**Note**: This endpoint is in preview and is subject to change.
166520+
**Note**: This endpoint is in Preview and is subject to change.
166521+
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).
166522+
/api/v2/security_monitoring/entity_context/{id}:
166523+
get:
166524+
description: |-
166525+
Get a single entity from the Cloud SIEM entity context store by its identifier, returning the historical
166526+
revisions of the entity in the requested time range. The endpoint can either return revisions across an
166527+
interval (`from` / `to`) or the snapshot of the entity at a single point in time (`as_of`); the two modes
166528+
are mutually exclusive.
166529+
operationId: GetSingleEntityContext
166530+
parameters:
166531+
- description: The unique identifier of the entity to retrieve.
166532+
in: path
166533+
name: id
166534+
required: true
166535+
schema:
166536+
example: user@example.com
166537+
type: string
166538+
- description: |-
166539+
The start of the time range to query, as an RFC3339 timestamp or a relative time (for example, `now-7d`).
166540+
Defaults to `now-7d`. Ignored when `as_of` is set.
166541+
in: query
166542+
name: from
166543+
required: false
166544+
schema:
166545+
default: now-7d
166546+
example: now-7d
166547+
type: string
166548+
- description: |-
166549+
The end of the time range to query, as an RFC3339 timestamp or a relative time (for example, `now`).
166550+
Defaults to `now`. Ignored when `as_of` is set.
166551+
in: query
166552+
name: to
166553+
required: false
166554+
schema:
166555+
default: now
166556+
example: now
166557+
type: string
166558+
- description: |-
166559+
A point in time at which to query the entity revisions, as an RFC3339 timestamp, a Unix timestamp
166560+
(in seconds), or a relative time (for example, `now-1d`). When set, `from` and `to` are ignored.
166561+
Cannot be combined with custom `from` / `to` values.
166562+
example: now-1d
166563+
in: query
166564+
name: as_of
166565+
required: false
166566+
schema:
166567+
type: string
166568+
responses:
166569+
"200":
166570+
content:
166571+
application/json:
166572+
examples:
166573+
default:
166574+
value:
166575+
data:
166576+
attributes:
166577+
revisions:
166578+
- attributes:
166579+
accounts:
166580+
- linked-account-123
166581+
display_name: Test User
166582+
email: user@example.com
166583+
principal_id: user@example.com
166584+
first_seen_at: "2026-04-01T00:00:00Z"
166585+
last_seen_at: "2026-05-01T00:00:00Z"
166586+
id: user@example.com
166587+
type: siem_entity_identity
166588+
schema:
166589+
$ref: "#/components/schemas/SingleEntityContextResponse"
166590+
description: OK
166591+
"400":
166592+
$ref: "#/components/responses/BadRequestResponse"
166593+
"403":
166594+
$ref: "#/components/responses/NotAuthorizedResponse"
166595+
"404":
166596+
$ref: "#/components/responses/NotFoundResponse"
166597+
"429":
166598+
$ref: "#/components/responses/TooManyRequestsResponse"
166599+
security:
166600+
- apiKeyAuth: []
166601+
appKeyAuth: []
166602+
- AuthZ:
166603+
- siem_entities_read
166604+
summary: Get a single entity context
166605+
tags: ["Security Monitoring"]
166606+
x-permission:
166607+
operator: OR
166608+
permissions:
166609+
- siem_entities_read
166610+
x-unstable: |-
166611+
**Note**: This endpoint is in Preview and is subject to change.
166511166612
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).
166512166613
/api/v2/security_monitoring/rules:
166513166614
get:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Get a single entity context returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_security_monitoring::GetSingleEntityContextOptionalParams;
4+
use datadog_api_client::datadogV2::api_security_monitoring::SecurityMonitoringAPI;
5+
6+
#[tokio::main]
7+
async fn main() {
8+
let mut configuration = datadog::Configuration::new();
9+
configuration.set_unstable_operation_enabled("v2.GetSingleEntityContext", true);
10+
let api = SecurityMonitoringAPI::with_config(configuration);
11+
let resp = api
12+
.get_single_entity_context(
13+
"user@example.com".to_string(),
14+
GetSingleEntityContextOptionalParams::default(),
15+
)
16+
.await;
17+
if let Ok(value) = resp {
18+
println!("{:#?}", value);
19+
} else {
20+
println!("{:#?}", resp.unwrap_err());
21+
}
22+
}

src/datadog/configuration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ impl Default for Configuration {
350350
false,
351351
),
352352
("v2.get_signal_entities".to_owned(), false),
353+
("v2.get_single_entity_context".to_owned(), false),
353354
("v2.get_static_analysis_default_rulesets".to_owned(), false),
354355
("v2.get_static_analysis_node_types".to_owned(), false),
355356
("v2.get_static_analysis_ruleset".to_owned(), false),

src/datadogV2/api/api_security_monitoring.rs

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,44 @@ impl GetSignalEntitiesOptionalParams {
254254
}
255255
}
256256

257+
/// GetSingleEntityContextOptionalParams is a struct for passing parameters to the method [`SecurityMonitoringAPI::get_single_entity_context`]
258+
#[non_exhaustive]
259+
#[derive(Clone, Default, Debug)]
260+
pub struct GetSingleEntityContextOptionalParams {
261+
/// The start of the time range to query, as an RFC3339 timestamp or a relative time (for example, `now-7d`).
262+
/// Defaults to `now-7d`. Ignored when `as_of` is set.
263+
pub from: Option<String>,
264+
/// The end of the time range to query, as an RFC3339 timestamp or a relative time (for example, `now`).
265+
/// Defaults to `now`. Ignored when `as_of` is set.
266+
pub to: Option<String>,
267+
/// A point in time at which to query the entity revisions, as an RFC3339 timestamp, a Unix timestamp
268+
/// (in seconds), or a relative time (for example, `now-1d`). When set, `from` and `to` are ignored.
269+
/// Cannot be combined with custom `from` / `to` values.
270+
pub as_of: Option<String>,
271+
}
272+
273+
impl GetSingleEntityContextOptionalParams {
274+
/// The start of the time range to query, as an RFC3339 timestamp or a relative time (for example, `now-7d`).
275+
/// Defaults to `now-7d`. Ignored when `as_of` is set.
276+
pub fn from(mut self, value: String) -> Self {
277+
self.from = Some(value);
278+
self
279+
}
280+
/// The end of the time range to query, as an RFC3339 timestamp or a relative time (for example, `now`).
281+
/// Defaults to `now`. Ignored when `as_of` is set.
282+
pub fn to(mut self, value: String) -> Self {
283+
self.to = Some(value);
284+
self
285+
}
286+
/// A point in time at which to query the entity revisions, as an RFC3339 timestamp, a Unix timestamp
287+
/// (in seconds), or a relative time (for example, `now-1d`). When set, `from` and `to` are ignored.
288+
/// Cannot be combined with custom `from` / `to` values.
289+
pub fn as_of(mut self, value: String) -> Self {
290+
self.as_of = Some(value);
291+
self
292+
}
293+
}
294+
257295
/// GetStaticAnalysisRulesetOptionalParams is a struct for passing parameters to the method [`SecurityMonitoringAPI::get_static_analysis_ruleset`]
258296
#[non_exhaustive]
259297
#[derive(Clone, Default, Debug)]
@@ -2048,6 +2086,14 @@ pub enum GetSignalNotificationRulesError {
20482086
UnknownValue(serde_json::Value),
20492087
}
20502088

2089+
/// GetSingleEntityContextError is a struct for typed errors of method [`SecurityMonitoringAPI::get_single_entity_context`]
2090+
#[derive(Debug, Clone, Serialize, Deserialize)]
2091+
#[serde(untagged)]
2092+
pub enum GetSingleEntityContextError {
2093+
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
2094+
UnknownValue(serde_json::Value),
2095+
}
2096+
20512097
/// GetStaticAnalysisDefaultRulesetsError is a struct for typed errors of method [`SecurityMonitoringAPI::get_static_analysis_default_rulesets`]
20522098
#[derive(Debug, Clone, Serialize, Deserialize)]
20532099
#[serde(untagged)]
@@ -13076,6 +13122,151 @@ impl SecurityMonitoringAPI {
1307613122
}
1307713123
}
1307813124

13125+
/// Get a single entity from the Cloud SIEM entity context store by its identifier, returning the historical
13126+
/// revisions of the entity in the requested time range. The endpoint can either return revisions across an
13127+
/// interval (`from` / `to`) or the snapshot of the entity at a single point in time (`as_of`); the two modes
13128+
/// are mutually exclusive.
13129+
pub async fn get_single_entity_context(
13130+
&self,
13131+
id: String,
13132+
params: GetSingleEntityContextOptionalParams,
13133+
) -> Result<
13134+
crate::datadogV2::model::SingleEntityContextResponse,
13135+
datadog::Error<GetSingleEntityContextError>,
13136+
> {
13137+
match self
13138+
.get_single_entity_context_with_http_info(id, params)
13139+
.await
13140+
{
13141+
Ok(response_content) => {
13142+
if let Some(e) = response_content.entity {
13143+
Ok(e)
13144+
} else {
13145+
Err(datadog::Error::Serde(serde::de::Error::custom(
13146+
"response content was None",
13147+
)))
13148+
}
13149+
}
13150+
Err(err) => Err(err),
13151+
}
13152+
}
13153+
13154+
/// Get a single entity from the Cloud SIEM entity context store by its identifier, returning the historical
13155+
/// revisions of the entity in the requested time range. The endpoint can either return revisions across an
13156+
/// interval (`from` / `to`) or the snapshot of the entity at a single point in time (`as_of`); the two modes
13157+
/// are mutually exclusive.
13158+
pub async fn get_single_entity_context_with_http_info(
13159+
&self,
13160+
id: String,
13161+
params: GetSingleEntityContextOptionalParams,
13162+
) -> Result<
13163+
datadog::ResponseContent<crate::datadogV2::model::SingleEntityContextResponse>,
13164+
datadog::Error<GetSingleEntityContextError>,
13165+
> {
13166+
let local_configuration = &self.config;
13167+
let operation_id = "v2.get_single_entity_context";
13168+
if local_configuration.is_unstable_operation_enabled(operation_id) {
13169+
warn!("Using unstable operation {operation_id}");
13170+
} else {
13171+
let local_error = datadog::UnstableOperationDisabledError {
13172+
msg: "Operation 'v2.get_single_entity_context' is not enabled".to_string(),
13173+
};
13174+
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
13175+
}
13176+
13177+
// unbox and build optional parameters
13178+
let from = params.from;
13179+
let to = params.to;
13180+
let as_of = params.as_of;
13181+
13182+
let local_client = &self.client;
13183+
13184+
let local_uri_str = format!(
13185+
"{}/api/v2/security_monitoring/entity_context/{id}",
13186+
local_configuration.get_operation_host(operation_id),
13187+
id = datadog::urlencode(id)
13188+
);
13189+
let mut local_req_builder =
13190+
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
13191+
13192+
if let Some(ref local_query_param) = from {
13193+
local_req_builder =
13194+
local_req_builder.query(&[("from", &local_query_param.to_string())]);
13195+
};
13196+
if let Some(ref local_query_param) = to {
13197+
local_req_builder = local_req_builder.query(&[("to", &local_query_param.to_string())]);
13198+
};
13199+
if let Some(ref local_query_param) = as_of {
13200+
local_req_builder =
13201+
local_req_builder.query(&[("as_of", &local_query_param.to_string())]);
13202+
};
13203+
13204+
// build headers
13205+
let mut headers = HeaderMap::new();
13206+
headers.insert("Accept", HeaderValue::from_static("application/json"));
13207+
13208+
// build user agent
13209+
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
13210+
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
13211+
Err(e) => {
13212+
log::warn!("Failed to parse user agent header: {e}, falling back to default");
13213+
headers.insert(
13214+
reqwest::header::USER_AGENT,
13215+
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
13216+
)
13217+
}
13218+
};
13219+
13220+
// build auth
13221+
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
13222+
headers.insert(
13223+
"DD-API-KEY",
13224+
HeaderValue::from_str(local_key.key.as_str())
13225+
.expect("failed to parse DD-API-KEY header"),
13226+
);
13227+
};
13228+
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
13229+
headers.insert(
13230+
"DD-APPLICATION-KEY",
13231+
HeaderValue::from_str(local_key.key.as_str())
13232+
.expect("failed to parse DD-APPLICATION-KEY header"),
13233+
);
13234+
};
13235+
13236+
local_req_builder = local_req_builder.headers(headers);
13237+
let local_req = local_req_builder.build()?;
13238+
log::debug!("request content: {:?}", local_req.body());
13239+
let local_resp = local_client.execute(local_req).await?;
13240+
13241+
let local_status = local_resp.status();
13242+
let local_content = local_resp.text().await?;
13243+
log::debug!("response content: {}", local_content);
13244+
13245+
if !local_status.is_client_error() && !local_status.is_server_error() {
13246+
match serde_json::from_str::<crate::datadogV2::model::SingleEntityContextResponse>(
13247+
&local_content,
13248+
) {
13249+
Ok(e) => {
13250+
return Ok(datadog::ResponseContent {
13251+
status: local_status,
13252+
content: local_content,
13253+
entity: Some(e),
13254+
})
13255+
}
13256+
Err(e) => return Err(datadog::Error::Serde(e)),
13257+
};
13258+
} else {
13259+
let local_entity: Option<GetSingleEntityContextError> =
13260+
serde_json::from_str(&local_content).ok();
13261+
let local_error = datadog::ResponseContent {
13262+
status: local_status,
13263+
content: local_content,
13264+
entity: local_entity,
13265+
};
13266+
Err(datadog::Error::ResponseError(local_error))
13267+
}
13268+
}
13269+
1307913270
/// Get the default SAST ruleset names for a given programming language.
1308013271
pub async fn get_static_analysis_default_rulesets(
1308113272
&self,

src/datadogV2/model/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10142,6 +10142,8 @@ pub mod model_entity_context_response_meta;
1014210142
pub use self::model_entity_context_response_meta::EntityContextResponseMeta;
1014310143
pub mod model_entity_context_page;
1014410144
pub use self::model_entity_context_page::EntityContextPage;
10145+
pub mod model_single_entity_context_response;
10146+
pub use self::model_single_entity_context_response::SingleEntityContextResponse;
1014510147
pub mod model_security_monitoring_rule_sort;
1014610148
pub use self::model_security_monitoring_rule_sort::SecurityMonitoringRuleSort;
1014710149
pub mod model_security_monitoring_list_rules_response;

0 commit comments

Comments
 (0)