Skip to content

Commit

Permalink
Add Security Monitoring rule test endpoint (#2509)
Browse files Browse the repository at this point in the history
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored May 29, 2024
1 parent ed67079 commit 791308f
Show file tree
Hide file tree
Showing 14 changed files with 1,166 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-05-23 19:28:50.831479",
"spec_repo_commit": "b9b11fda"
"regenerated": "2024-05-28 16:29:22.979941",
"spec_repo_commit": "9445af96"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-05-23 19:28:50.850499",
"spec_repo_commit": "b9b11fda"
"regenerated": "2024-05-28 16:29:22.997842",
"spec_repo_commit": "9445af96"
}
}
}
140 changes: 140 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17407,6 +17407,47 @@ components:
- GEO_DATA
- EVENT_COUNT
- NONE
SecurityMonitoringRuleQueryPayload:
description: Payload to test a rule query with the expected result.
properties:
expectedResult:
description: Expected result of the test.
example: true
type: boolean
index:
description: Index of the query under test.
example: 0
format: int64
minimum: 0
type: integer
payload:
$ref: '#/components/schemas/SecurityMonitoringRuleQueryPayloadData'
type: object
SecurityMonitoringRuleQueryPayloadData:
additionalProperties: {}
description: Payload used to test the rule query.
properties:
ddsource:
description: Source of the payload.
example: nginx
type: string
ddtags:
description: Tags associated with your data.
example: env:staging,version:5.1
type: string
hostname:
description: The name of the originating host of the log.
example: i-012345678
type: string
message:
description: The message of the payload.
example: 2019-11-19T14:37:58,995 INFO [process.name][20081] Hello World
type: string
service:
description: The name of the application or service generating the data.
example: payment
type: string
type: object
SecurityMonitoringRuleResponse:
description: Create a new rule.
oneOf:
Expand All @@ -17428,6 +17469,31 @@ components:
- MEDIUM
- HIGH
- CRITICAL
SecurityMonitoringRuleTestRequest:
description: Test the rule queries of a rule.
properties:
rule:
$ref: '#/components/schemas/SecurityMonitoringRuleCreatePayload'
ruleQueryPayloads:
description: Data payloads used to test rules query with the expected result.
items:
$ref: '#/components/schemas/SecurityMonitoringRuleQueryPayload'
type: array
type: object
SecurityMonitoringRuleTestResponse:
description: Result of the test of the rule queries.
properties:
results:
description: 'Assert results are returned in the same order as the rule
query payloads.

For each payload, it returns True if the result matched the expected result,

False otherwise.'
items:
type: boolean
type: array
type: object
SecurityMonitoringRuleThirdPartyOptions:
description: Options on third party rules.
properties:
Expand Down Expand Up @@ -32551,6 +32617,42 @@ paths:
tags:
- Security Monitoring
x-codegen-request-body-name: body
/api/v2/security_monitoring/rules/test:
post:
description: Test a rule.
operationId: TestSecurityMonitoringRule
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/SecurityMonitoringRuleTestRequest'
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/SecurityMonitoringRuleTestResponse'
description: OK
'400':
$ref: '#/components/responses/BadRequestResponse'
'401':
$ref: '#/components/responses/ConcurrentModificationResponse'
'403':
$ref: '#/components/responses/NotAuthorizedResponse'
'404':
$ref: '#/components/responses/NotFoundResponse'
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
security:
- apiKeyAuth: []
appKeyAuth: []
- AuthZ:
- security_monitoring_rules_write
summary: Test a rule
tags:
- Security Monitoring
x-codegen-request-body-name: body
/api/v2/security_monitoring/rules/validation:
post:
description: Validate a detection rule.
Expand Down Expand Up @@ -32672,6 +32774,44 @@ paths:
tags:
- Security Monitoring
x-codegen-request-body-name: body
/api/v2/security_monitoring/rules/{rule_id}/test:
post:
description: Test an existing rule.
operationId: TestExistingSecurityMonitoringRule
parameters:
- $ref: '#/components/parameters/SecurityMonitoringRuleID'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/SecurityMonitoringRuleTestRequest'
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/SecurityMonitoringRuleTestResponse'
description: OK
'400':
$ref: '#/components/responses/BadRequestResponse'
'401':
$ref: '#/components/responses/ConcurrentModificationResponse'
'403':
$ref: '#/components/responses/NotAuthorizedResponse'
'404':
$ref: '#/components/responses/NotFoundResponse'
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
security:
- apiKeyAuth: []
appKeyAuth: []
- AuthZ:
- security_monitoring_rules_write
summary: Test an existing rule
tags:
- Security Monitoring
x-codegen-request-body-name: body
/api/v2/security_monitoring/signals:
get:
description: 'The list endpoint returns security signals that match a search
Expand Down
147 changes: 147 additions & 0 deletions api/datadogV2/api_security_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,153 @@ func (a *SecurityMonitoringApi) SearchSecurityMonitoringSignalsWithPagination(ct
return items, cancel
}

// TestExistingSecurityMonitoringRule Test an existing rule.
// Test an existing rule.
func (a *SecurityMonitoringApi) TestExistingSecurityMonitoringRule(ctx _context.Context, ruleId string, body SecurityMonitoringRuleTestRequest) (SecurityMonitoringRuleTestResponse, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodPost
localVarPostBody interface{}
localVarReturnValue SecurityMonitoringRuleTestResponse
)

localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.SecurityMonitoringApi.TestExistingSecurityMonitoringRule")
if err != nil {
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
}

localVarPath := localBasePath + "/api/v2/security_monitoring/rules/{rule_id}/test"
localVarPath = strings.Replace(localVarPath, "{"+"rule_id"+"}", _neturl.PathEscape(datadog.ParameterToString(ruleId, "")), -1)

localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
localVarHeaderParams["Content-Type"] = "application/json"
localVarHeaderParams["Accept"] = "application/json"

// body params
localVarPostBody = &body
datadog.SetAuthKeys(
ctx,
&localVarHeaderParams,
[2]string{"apiKeyAuth", "DD-API-KEY"},
[2]string{"appKeyAuth", "DD-APPLICATION-KEY"},
)
req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil)
if err != nil {
return localVarReturnValue, nil, err
}

localVarHTTPResponse, err := a.Client.CallAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}

localVarBody, err := datadog.ReadBody(localVarHTTPResponse)
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}

if localVarHTTPResponse.StatusCode >= 300 {
newErr := datadog.GenericOpenAPIError{
ErrorBody: localVarBody,
ErrorMessage: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 {
var v APIErrorResponse
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.ErrorModel = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := datadog.GenericOpenAPIError{
ErrorBody: localVarBody,
ErrorMessage: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

return localVarReturnValue, localVarHTTPResponse, nil
}

// TestSecurityMonitoringRule Test a rule.
// Test a rule.
func (a *SecurityMonitoringApi) TestSecurityMonitoringRule(ctx _context.Context, body SecurityMonitoringRuleTestRequest) (SecurityMonitoringRuleTestResponse, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodPost
localVarPostBody interface{}
localVarReturnValue SecurityMonitoringRuleTestResponse
)

localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.SecurityMonitoringApi.TestSecurityMonitoringRule")
if err != nil {
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
}

localVarPath := localBasePath + "/api/v2/security_monitoring/rules/test"

localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
localVarHeaderParams["Content-Type"] = "application/json"
localVarHeaderParams["Accept"] = "application/json"

// body params
localVarPostBody = &body
datadog.SetAuthKeys(
ctx,
&localVarHeaderParams,
[2]string{"apiKeyAuth", "DD-API-KEY"},
[2]string{"appKeyAuth", "DD-APPLICATION-KEY"},
)
req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil)
if err != nil {
return localVarReturnValue, nil, err
}

localVarHTTPResponse, err := a.Client.CallAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}

localVarBody, err := datadog.ReadBody(localVarHTTPResponse)
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}

if localVarHTTPResponse.StatusCode >= 300 {
newErr := datadog.GenericOpenAPIError{
ErrorBody: localVarBody,
ErrorMessage: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 {
var v APIErrorResponse
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.ErrorModel = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := datadog.GenericOpenAPIError{
ErrorBody: localVarBody,
ErrorMessage: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

return localVarReturnValue, localVarHTTPResponse, nil
}

// UpdateSecurityFilter Update a security filter.
// Update a specific security filter.
// Returns the security filter object when the request is successful.
Expand Down
2 changes: 2 additions & 0 deletions api/datadogV2/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@
// - [SecurityMonitoringApi.ListSecurityMonitoringSuppressions]
// - [SecurityMonitoringApi.MuteFindings]
// - [SecurityMonitoringApi.SearchSecurityMonitoringSignals]
// - [SecurityMonitoringApi.TestExistingSecurityMonitoringRule]
// - [SecurityMonitoringApi.TestSecurityMonitoringRule]
// - [SecurityMonitoringApi.UpdateSecurityFilter]
// - [SecurityMonitoringApi.UpdateSecurityMonitoringRule]
// - [SecurityMonitoringApi.UpdateSecurityMonitoringSuppression]
Expand Down
Loading

0 comments on commit 791308f

Please sign in to comment.