Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint to retrieve Security Monitoring rule version history #2372

Merged
merged 2 commits into from
Feb 13, 2025
Merged
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
111 changes: 111 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13006,6 +13006,30 @@ components:
$ref: '#/components/schemas/GetInterfacesData'
type: array
type: object
GetRuleVersionHistoryData:
description: Data for the rule version history.
properties:
attributes:
$ref: '#/components/schemas/RuleVersionHistory'
id:
description: ID of the rule.
type: string
type:
$ref: '#/components/schemas/GetRuleVersionHistoryDataType'
type: object
GetRuleVersionHistoryDataType:
description: Type of data.
enum:
- GetRuleVersionHistoryResponse
type: string
x-enum-varnames:
- GETRULEVERSIONHISTORYRESPONSE
GetRuleVersionHistoryResponse:
description: Response for getting the rule version history.
properties:
data:
$ref: '#/components/schemas/GetRuleVersionHistoryData'
type: object
GetSBOMResponse:
description: The expected response schema when getting an SBOM.
properties:
Expand Down Expand Up @@ -23825,6 +23849,57 @@ components:
example: John Doe
type: string
type: object
RuleVersionHistory:
description: Response object containing the version history of a rule.
properties:
count:
description: The number of rule versions.
format: int32
maximum: 2147483647
type: integer
data:
additionalProperties:
$ref: '#/components/schemas/RuleVersions'
description: A rule version with a list of updates.
description: The `RuleVersionHistory` `data`.
type: object
type: object
RuleVersionUpdate:
description: A change in a rule version.
properties:
change:
description: The new value of the field.
example: cloud_provider:aws
type: string
field:
description: The field that was changed.
example: Tags
type: string
type:
$ref: '#/components/schemas/RuleVersionUpdateType'
type: object
RuleVersionUpdateType:
description: The type of change.
enum:
- create
- update
- delete
type: string
x-enum-varnames:
- CREATE
- UPDATE
- DELETE
RuleVersions:
description: A rule version with a list of updates.
properties:
changes:
description: A list of changes.
items:
$ref: '#/components/schemas/RuleVersionUpdate'
type: array
rule:
$ref: '#/components/schemas/SecurityMonitoringRuleResponse'
type: object
RumMetricCompute:
description: The compute rule to compute the rum-based metric.
properties:
Expand Down Expand Up @@ -46712,6 +46787,42 @@ paths:
operator: OR
permissions:
- security_monitoring_rules_write
/api/v2/security_monitoring/rules/{rule_id}/version_history:
get:
description: Get a rule's version history.
operationId: GetRuleVersionHistory
parameters:
- $ref: '#/components/parameters/SecurityMonitoringRuleID'
- $ref: '#/components/parameters/PageSize'
- $ref: '#/components/parameters/PageNumber'
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/GetRuleVersionHistoryResponse'
description: OK
'400':
$ref: '#/components/responses/BadRequestResponse'
'403':
$ref: '#/components/responses/NotAuthorizedResponse'
'404':
$ref: '#/components/responses/NotFoundResponse'
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
security:
- apiKeyAuth: []
appKeyAuth: []
- AuthZ:
- security_monitoring_rules_read
summary: Get a rule's version history
tags:
- Security Monitoring
x-permission:
operator: OR
permissions:
- security_monitoring_rules_read
x-unstable: '**Note**: This endpoint is in beta and may be subject to changes.'
/api/v2/security_monitoring/signals:
get:
description: 'The list endpoint returns security signals that match a search
Expand Down
49 changes: 49 additions & 0 deletions docs/datadog_api_client.v2.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5331,6 +5331,27 @@ datadog\_api\_client.v2.model.get\_interfaces\_response module
:members:
:show-inheritance:

datadog\_api\_client.v2.model.get\_rule\_version\_history\_data module
----------------------------------------------------------------------

.. automodule:: datadog_api_client.v2.model.get_rule_version_history_data
:members:
:show-inheritance:

datadog\_api\_client.v2.model.get\_rule\_version\_history\_data\_type module
----------------------------------------------------------------------------

.. automodule:: datadog_api_client.v2.model.get_rule_version_history_data_type
:members:
:show-inheritance:

datadog\_api\_client.v2.model.get\_rule\_version\_history\_response module
--------------------------------------------------------------------------

.. automodule:: datadog_api_client.v2.model.get_rule_version_history_response
:members:
:show-inheritance:

datadog\_api\_client.v2.model.get\_sbom\_response module
--------------------------------------------------------

Expand Down Expand Up @@ -10140,6 +10161,34 @@ datadog\_api\_client.v2.model.rule\_user module
:members:
:show-inheritance:

datadog\_api\_client.v2.model.rule\_version\_history module
-----------------------------------------------------------

.. automodule:: datadog_api_client.v2.model.rule_version_history
:members:
:show-inheritance:

datadog\_api\_client.v2.model.rule\_version\_update module
----------------------------------------------------------

.. automodule:: datadog_api_client.v2.model.rule_version_update
:members:
:show-inheritance:

datadog\_api\_client.v2.model.rule\_version\_update\_type module
----------------------------------------------------------------

.. automodule:: datadog_api_client.v2.model.rule_version_update_type
:members:
:show-inheritance:

datadog\_api\_client.v2.model.rule\_versions module
---------------------------------------------------

.. automodule:: datadog_api_client.v2.model.rule_versions
:members:
:show-inheritance:

datadog\_api\_client.v2.model.rum\_aggregate\_bucket\_value module
------------------------------------------------------------------

Expand Down
16 changes: 16 additions & 0 deletions examples/v2/security-monitoring/GetRuleVersionHistory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Get a rule's version history returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.security_monitoring_api import SecurityMonitoringApi

configuration = Configuration()
configuration.unstable_operations["get_rule_version_history"] = True
with ApiClient(configuration) as api_client:
api_instance = SecurityMonitoringApi(api_client)
response = api_instance.get_rule_version_history(
rule_id="rule_id",
)

print(response)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Get rule version history returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.security_monitoring_api import SecurityMonitoringApi

# there is a valid "security_rule" in the system
SECURITY_RULE_ID = environ["SECURITY_RULE_ID"]

configuration = Configuration()
configuration.unstable_operations["get_rule_version_history"] = True
with ApiClient(configuration) as api_client:
api_instance = SecurityMonitoringApi(api_client)
response = api_instance.get_rule_version_history(
rule_id=SECURITY_RULE_ID,
)

print(response)
1 change: 1 addition & 0 deletions src/datadog_api_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def __init__(
"v2.delete_historical_job": False,
"v2.get_finding": False,
"v2.get_historical_job": False,
"v2.get_rule_version_history": False,
"v2.list_findings": False,
"v2.list_historical_jobs": False,
"v2.mute_findings": False,
Expand Down
64 changes: 64 additions & 0 deletions src/datadog_api_client/v2/api/security_monitoring_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from datadog_api_client.v2.model.security_monitoring_rule_validate_payload import SecurityMonitoringRuleValidatePayload
from datadog_api_client.v2.model.cloud_configuration_rule_payload import CloudConfigurationRulePayload
from datadog_api_client.v2.model.security_monitoring_rule_update_payload import SecurityMonitoringRuleUpdatePayload
from datadog_api_client.v2.model.get_rule_version_history_response import GetRuleVersionHistoryResponse
from datadog_api_client.v2.model.security_monitoring_signals_list_response import SecurityMonitoringSignalsListResponse
from datadog_api_client.v2.model.security_monitoring_signals_sort import SecurityMonitoringSignalsSort
from datadog_api_client.v2.model.security_monitoring_signal import SecurityMonitoringSignal
Expand Down Expand Up @@ -556,6 +557,39 @@ def __init__(self, api_client=None):
api_client=api_client,
)

self._get_rule_version_history_endpoint = _Endpoint(
settings={
"response_type": (GetRuleVersionHistoryResponse,),
"auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"],
"endpoint_path": "/api/v2/security_monitoring/rules/{rule_id}/version_history",
"operation_id": "get_rule_version_history",
"http_method": "GET",
"version": "v2",
},
params_map={
"rule_id": {
"required": True,
"openapi_types": (str,),
"attribute": "rule_id",
"location": "path",
},
"page_size": {
"openapi_types": (int,),
"attribute": "page[size]",
"location": "query",
},
"page_number": {
"openapi_types": (int,),
"attribute": "page[number]",
"location": "query",
},
},
headers_map={
"accept": ["application/json"],
},
api_client=api_client,
)

self._get_sbom_endpoint = _Endpoint(
settings={
"response_type": (GetSBOMResponse,),
Expand Down Expand Up @@ -1958,6 +1992,36 @@ def get_historical_job(

return self._get_historical_job_endpoint.call_with_http_info(**kwargs)

def get_rule_version_history(
self,
rule_id: str,
*,
page_size: Union[int, UnsetType] = unset,
page_number: Union[int, UnsetType] = unset,
) -> GetRuleVersionHistoryResponse:
"""Get a rule's version history.

Get a rule's version history.

:param rule_id: The ID of the rule.
:type rule_id: str
:param page_size: Size for a given page. The maximum allowed value is 100.
:type page_size: int, optional
:param page_number: Specific page number to return.
:type page_number: int, optional
:rtype: GetRuleVersionHistoryResponse
"""
kwargs: Dict[str, Any] = {}
kwargs["rule_id"] = rule_id

if page_size is not unset:
kwargs["page_size"] = page_size

if page_number is not unset:
kwargs["page_number"] = page_number

return self._get_rule_version_history_endpoint.call_with_http_info(**kwargs)

def get_sbom(
self,
asset_type: AssetType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import Union, TYPE_CHECKING

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


if TYPE_CHECKING:
from datadog_api_client.v2.model.rule_version_history import RuleVersionHistory
from datadog_api_client.v2.model.get_rule_version_history_data_type import GetRuleVersionHistoryDataType


class GetRuleVersionHistoryData(ModelNormal):
@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.rule_version_history import RuleVersionHistory
from datadog_api_client.v2.model.get_rule_version_history_data_type import GetRuleVersionHistoryDataType

return {
"attributes": (RuleVersionHistory,),
"id": (str,),
"type": (GetRuleVersionHistoryDataType,),
}

attribute_map = {
"attributes": "attributes",
"id": "id",
"type": "type",
}

def __init__(
self_,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Code Quality Violation

Suggested change
self_,
self,
first parameter of a class function should be self (...read more)

In a class method (that is not a class method nor a static method), the first argument must be self by convention.

Learn More

View in Datadog  Leave us feedback  Documentation

attributes: Union[RuleVersionHistory, UnsetType] = unset,
id: Union[str, UnsetType] = unset,
type: Union[GetRuleVersionHistoryDataType, UnsetType] = unset,
**kwargs,
):
"""
Data for the rule version history.

:param attributes: Response object containing the version history of a rule.
:type attributes: RuleVersionHistory, optional

:param id: ID of the rule.
:type id: str, optional

:param type: Type of data.
:type type: GetRuleVersionHistoryDataType, optional
"""
if attributes is not unset:
kwargs["attributes"] = attributes
if id is not unset:
kwargs["id"] = id
if type is not unset:
kwargs["type"] = type
super().__init__(kwargs)
Loading