Skip to content

Commit c0c5459

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
security_monitoring - Document rules bulk export (DataDog#3615)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 92708ee commit c0c5459

12 files changed

Lines changed: 756 additions & 0 deletions

.generator/schemas/v2/openapi.yaml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49985,6 +49985,55 @@ components:
4998549985
- TWO_DAYS
4998649986
- ONE_WEEK
4998749987
- TWO_WEEKS
49988+
SecurityMonitoringRuleBulkExportAttributes:
49989+
description: Attributes for bulk exporting security monitoring rules.
49990+
properties:
49991+
ruleIds:
49992+
description: 'List of rule IDs to export. Each rule will be included in
49993+
the resulting ZIP file
49994+
49995+
as a separate JSON file.'
49996+
example:
49997+
- def-000-u7q
49998+
- def-000-7dd
49999+
items:
50000+
type: string
50001+
minItems: 1
50002+
type: array
50003+
required:
50004+
- ruleIds
50005+
type: object
50006+
SecurityMonitoringRuleBulkExportData:
50007+
description: Data for bulk exporting security monitoring rules.
50008+
properties:
50009+
attributes:
50010+
$ref: '#/components/schemas/SecurityMonitoringRuleBulkExportAttributes'
50011+
id:
50012+
description: Request ID.
50013+
example: bulk_export
50014+
type: string
50015+
type:
50016+
$ref: '#/components/schemas/SecurityMonitoringRuleBulkExportDataType'
50017+
required:
50018+
- attributes
50019+
- type
50020+
type: object
50021+
SecurityMonitoringRuleBulkExportDataType:
50022+
description: The type of the resource.
50023+
enum:
50024+
- security_monitoring_rules_bulk_export
50025+
example: security_monitoring_rules_bulk_export
50026+
type: string
50027+
x-enum-varnames:
50028+
- SECURITY_MONITORING_RULES_BULK_EXPORT
50029+
SecurityMonitoringRuleBulkExportPayload:
50030+
description: Payload for bulk exporting security monitoring rules.
50031+
properties:
50032+
data:
50033+
$ref: '#/components/schemas/SecurityMonitoringRuleBulkExportData'
50034+
required:
50035+
- data
50036+
type: object
4998850037
SecurityMonitoringRuleCase:
4998950038
description: Case when signal is generated.
4999050039
properties:
@@ -87257,6 +87306,51 @@ paths:
8725787306
operator: OR
8725887307
permissions:
8725987308
- security_monitoring_rules_write
87309+
/api/v2/security_monitoring/rules/bulk_export:
87310+
post:
87311+
description: 'Export a list of security monitoring rules as a ZIP file containing
87312+
JSON rule definitions.
87313+
87314+
The endpoint accepts a list of rule IDs and returns a ZIP archive where each
87315+
rule is
87316+
87317+
saved as a separate JSON file named after the rule.'
87318+
operationId: BulkExportSecurityMonitoringRules
87319+
requestBody:
87320+
content:
87321+
application/json:
87322+
schema:
87323+
$ref: '#/components/schemas/SecurityMonitoringRuleBulkExportPayload'
87324+
required: true
87325+
responses:
87326+
'200':
87327+
content:
87328+
application/zip:
87329+
schema:
87330+
format: binary
87331+
type: string
87332+
description: OK
87333+
'400':
87334+
$ref: '#/components/responses/BadRequestResponse'
87335+
'403':
87336+
$ref: '#/components/responses/NotAuthorizedResponse'
87337+
'404':
87338+
$ref: '#/components/responses/NotFoundResponse'
87339+
'429':
87340+
$ref: '#/components/responses/TooManyRequestsResponse'
87341+
security:
87342+
- apiKeyAuth: []
87343+
appKeyAuth: []
87344+
- AuthZ:
87345+
- security_monitoring_rules_read
87346+
summary: Bulk export security monitoring rules
87347+
tags:
87348+
- Security Monitoring
87349+
x-codegen-request-body-name: body
87350+
x-permission:
87351+
operator: OR
87352+
permissions:
87353+
- security_monitoring_rules_read
8726087354
/api/v2/security_monitoring/rules/convert:
8726187355
post:
8726287356
description: 'Convert a rule that doesn''t (yet) exist from JSON to Terraform

api/datadogV2/api_security_monitoring.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package datadogV2
77
import (
88
_context "context"
99
_fmt "fmt"
10+
_io "io"
1011
_log "log"
1112
_nethttp "net/http"
1213
_neturl "net/url"
@@ -191,6 +192,80 @@ func (a *SecurityMonitoringApi) AttachJiraIssue(ctx _context.Context, body Attac
191192
return localVarReturnValue, localVarHTTPResponse, nil
192193
}
193194

195+
// BulkExportSecurityMonitoringRules Bulk export security monitoring rules.
196+
// Export a list of security monitoring rules as a ZIP file containing JSON rule definitions.
197+
// The endpoint accepts a list of rule IDs and returns a ZIP archive where each rule is
198+
// saved as a separate JSON file named after the rule.
199+
func (a *SecurityMonitoringApi) BulkExportSecurityMonitoringRules(ctx _context.Context, body SecurityMonitoringRuleBulkExportPayload) (_io.Reader, *_nethttp.Response, error) {
200+
var (
201+
localVarHTTPMethod = _nethttp.MethodPost
202+
localVarPostBody interface{}
203+
localVarReturnValue _io.Reader
204+
)
205+
206+
localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.SecurityMonitoringApi.BulkExportSecurityMonitoringRules")
207+
if err != nil {
208+
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
209+
}
210+
211+
localVarPath := localBasePath + "/api/v2/security_monitoring/rules/bulk_export"
212+
213+
localVarHeaderParams := make(map[string]string)
214+
localVarQueryParams := _neturl.Values{}
215+
localVarFormParams := _neturl.Values{}
216+
localVarHeaderParams["Content-Type"] = "application/json"
217+
localVarHeaderParams["Accept"] = "application/json"
218+
219+
// body params
220+
localVarPostBody = &body
221+
if a.Client.Cfg.DelegatedTokenConfig != nil {
222+
err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig)
223+
if err != nil {
224+
return localVarReturnValue, nil, err
225+
}
226+
} else {
227+
datadog.SetAuthKeys(
228+
ctx,
229+
&localVarHeaderParams,
230+
[2]string{"apiKeyAuth", "DD-API-KEY"},
231+
[2]string{"appKeyAuth", "DD-APPLICATION-KEY"},
232+
)
233+
}
234+
req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil)
235+
if err != nil {
236+
return localVarReturnValue, nil, err
237+
}
238+
239+
localVarHTTPResponse, err := a.Client.CallAPI(req)
240+
if err != nil || localVarHTTPResponse == nil {
241+
return localVarReturnValue, localVarHTTPResponse, err
242+
}
243+
244+
if localVarHTTPResponse.StatusCode >= 300 {
245+
246+
localVarBody, err := datadog.ReadBody(localVarHTTPResponse)
247+
if err != nil {
248+
return localVarReturnValue, localVarHTTPResponse, err
249+
}
250+
newErr := datadog.GenericOpenAPIError{
251+
ErrorBody: localVarBody,
252+
ErrorMessage: localVarHTTPResponse.Status,
253+
}
254+
if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 {
255+
var v APIErrorResponse
256+
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
257+
if err != nil {
258+
return localVarReturnValue, localVarHTTPResponse, newErr
259+
}
260+
newErr.ErrorModel = v
261+
}
262+
return localVarReturnValue, localVarHTTPResponse, newErr
263+
}
264+
localVarReturnValue = localVarHTTPResponse.Body
265+
266+
return localVarReturnValue, localVarHTTPResponse, nil
267+
}
268+
194269
// CancelThreatHuntingJob Cancel a threat hunting job.
195270
// Cancel a threat hunting job.
196271
func (a *SecurityMonitoringApi) CancelThreatHuntingJob(ctx _context.Context, jobId string) (*_nethttp.Response, error) {

api/datadogV2/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@
548548
// - [RumRetentionFiltersApi.UpdateRetentionFilter]
549549
// - [SecurityMonitoringApi.AttachCase]
550550
// - [SecurityMonitoringApi.AttachJiraIssue]
551+
// - [SecurityMonitoringApi.BulkExportSecurityMonitoringRules]
551552
// - [SecurityMonitoringApi.CancelThreatHuntingJob]
552553
// - [SecurityMonitoringApi.ConvertExistingSecurityMonitoringRule]
553554
// - [SecurityMonitoringApi.ConvertJobResultToSignal]
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
package datadogV2
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
11+
)
12+
13+
// SecurityMonitoringRuleBulkExportAttributes Attributes for bulk exporting security monitoring rules.
14+
type SecurityMonitoringRuleBulkExportAttributes struct {
15+
// List of rule IDs to export. Each rule will be included in the resulting ZIP file
16+
// as a separate JSON file.
17+
RuleIds []string `json:"ruleIds"`
18+
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
19+
UnparsedObject map[string]interface{} `json:"-"`
20+
AdditionalProperties map[string]interface{} `json:"-"`
21+
}
22+
23+
// NewSecurityMonitoringRuleBulkExportAttributes instantiates a new SecurityMonitoringRuleBulkExportAttributes object.
24+
// This constructor will assign default values to properties that have it defined,
25+
// and makes sure properties required by API are set, but the set of arguments
26+
// will change when the set of required properties is changed.
27+
func NewSecurityMonitoringRuleBulkExportAttributes(ruleIds []string) *SecurityMonitoringRuleBulkExportAttributes {
28+
this := SecurityMonitoringRuleBulkExportAttributes{}
29+
this.RuleIds = ruleIds
30+
return &this
31+
}
32+
33+
// NewSecurityMonitoringRuleBulkExportAttributesWithDefaults instantiates a new SecurityMonitoringRuleBulkExportAttributes object.
34+
// This constructor will only assign default values to properties that have it defined,
35+
// but it doesn't guarantee that properties required by API are set.
36+
func NewSecurityMonitoringRuleBulkExportAttributesWithDefaults() *SecurityMonitoringRuleBulkExportAttributes {
37+
this := SecurityMonitoringRuleBulkExportAttributes{}
38+
return &this
39+
}
40+
41+
// GetRuleIds returns the RuleIds field value.
42+
func (o *SecurityMonitoringRuleBulkExportAttributes) GetRuleIds() []string {
43+
if o == nil {
44+
var ret []string
45+
return ret
46+
}
47+
return o.RuleIds
48+
}
49+
50+
// GetRuleIdsOk returns a tuple with the RuleIds field value
51+
// and a boolean to check if the value has been set.
52+
func (o *SecurityMonitoringRuleBulkExportAttributes) GetRuleIdsOk() (*[]string, bool) {
53+
if o == nil {
54+
return nil, false
55+
}
56+
return &o.RuleIds, true
57+
}
58+
59+
// SetRuleIds sets field value.
60+
func (o *SecurityMonitoringRuleBulkExportAttributes) SetRuleIds(v []string) {
61+
o.RuleIds = v
62+
}
63+
64+
// MarshalJSON serializes the struct using spec logic.
65+
func (o SecurityMonitoringRuleBulkExportAttributes) MarshalJSON() ([]byte, error) {
66+
toSerialize := map[string]interface{}{}
67+
if o.UnparsedObject != nil {
68+
return datadog.Marshal(o.UnparsedObject)
69+
}
70+
toSerialize["ruleIds"] = o.RuleIds
71+
72+
for key, value := range o.AdditionalProperties {
73+
toSerialize[key] = value
74+
}
75+
return datadog.Marshal(toSerialize)
76+
}
77+
78+
// UnmarshalJSON deserializes the given payload.
79+
func (o *SecurityMonitoringRuleBulkExportAttributes) UnmarshalJSON(bytes []byte) (err error) {
80+
all := struct {
81+
RuleIds *[]string `json:"ruleIds"`
82+
}{}
83+
if err = datadog.Unmarshal(bytes, &all); err != nil {
84+
return datadog.Unmarshal(bytes, &o.UnparsedObject)
85+
}
86+
if all.RuleIds == nil {
87+
return fmt.Errorf("required field ruleIds missing")
88+
}
89+
additionalProperties := make(map[string]interface{})
90+
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
91+
datadog.DeleteKeys(additionalProperties, &[]string{"ruleIds"})
92+
} else {
93+
return err
94+
}
95+
o.RuleIds = *all.RuleIds
96+
97+
if len(additionalProperties) > 0 {
98+
o.AdditionalProperties = additionalProperties
99+
}
100+
101+
return nil
102+
}

0 commit comments

Comments
 (0)