From c1b46649cefd27ced12acf07e9476f04128e39d8 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Thu, 23 Jan 2025 15:35:08 +0000 Subject: [PATCH] Regenerate client from commit 3d683e08 of spec repo --- .apigentools-info | 8 +- .generator/schemas/v2/openapi.yaml | 86 +++++++++ api/datadog/configuration.go | 1 + api/datadogV2/api_security_monitoring.go | 118 ++++++++++++ api/datadogV2/doc.go | 1 + ...model_get_rule_version_history_response.go | 137 +++++++++++++ api/datadogV2/model_rule_version_history.go | 137 +++++++++++++ api/datadogV2/model_rule_version_update.go | 182 ++++++++++++++++++ .../model_rule_version_update_type.go | 68 +++++++ .../GetRuleVersionHistory.go | 30 +++ .../GetRuleVersionHistory_2467565841.go | 32 +++ ...version_history_returns_OK_response.freeze | 1 + ...e_version_history_returns_OK_response.yaml | 40 ++++ .../features/v2/security_monitoring.feature | 35 ++++ tests/scenarios/features/v2/undo.json | 6 + 15 files changed, 878 insertions(+), 4 deletions(-) create mode 100644 api/datadogV2/model_get_rule_version_history_response.go create mode 100644 api/datadogV2/model_rule_version_history.go create mode 100644 api/datadogV2/model_rule_version_update.go create mode 100644 api/datadogV2/model_rule_version_update_type.go create mode 100644 examples/v2/security-monitoring/GetRuleVersionHistory.go create mode 100644 examples/v2/security-monitoring/GetRuleVersionHistory_2467565841.go create mode 100644 tests/scenarios/cassettes/TestScenarios/v2/Feature_Security_Monitoring/Scenario_Get_rule_version_history_returns_OK_response.freeze create mode 100644 tests/scenarios/cassettes/TestScenarios/v2/Feature_Security_Monitoring/Scenario_Get_rule_version_history_returns_OK_response.yaml diff --git a/.apigentools-info b/.apigentools-info index 94d6a87e38c..80387c57d7b 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2025-01-22 15:54:14.899066", - "spec_repo_commit": "7a8ea4b1" + "regenerated": "2025-01-23 15:33:47.299586", + "spec_repo_commit": "3d683e08" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2025-01-22 15:54:14.915479", - "spec_repo_commit": "7a8ea4b1" + "regenerated": "2025-01-23 15:33:47.315185", + "spec_repo_commit": "3d683e08" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index a06d74ae8e6..2543bd5a639 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -12666,6 +12666,20 @@ components: $ref: '#/components/schemas/GetInterfacesData' type: array type: object + GetRuleVersionHistoryResponse: + 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: + description: A list of rule versions. + items: + $ref: '#/components/schemas/RuleVersionHistory' + type: array + type: object GetSBOMResponse: description: The expected response schema when getting an SBOM. properties: @@ -22930,6 +22944,42 @@ components: type: string x-enum-varnames: - RULE + RuleVersionHistory: + 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 + 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 RumMetricCompute: description: The compute rule to compute the rum-based metric. properties: @@ -44751,6 +44801,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 diff --git a/api/datadog/configuration.go b/api/datadog/configuration.go index 3f07d128d7f..2d180a5411b 100644 --- a/api/datadog/configuration.go +++ b/api/datadog/configuration.go @@ -380,6 +380,7 @@ func NewConfiguration() *Configuration { "v2.DeleteHistoricalJob": false, "v2.GetFinding": false, "v2.GetHistoricalJob": false, + "v2.GetRuleVersionHistory": false, "v2.GetSBOM": false, "v2.ListFindings": false, "v2.ListHistoricalJobs": false, diff --git a/api/datadogV2/api_security_monitoring.go b/api/datadogV2/api_security_monitoring.go index f98108991a7..4183e348b36 100644 --- a/api/datadogV2/api_security_monitoring.go +++ b/api/datadogV2/api_security_monitoring.go @@ -1192,6 +1192,124 @@ func (a *SecurityMonitoringApi) GetHistoricalJob(ctx _context.Context, jobId str return localVarReturnValue, localVarHTTPResponse, nil } +// GetRuleVersionHistoryOptionalParameters holds optional parameters for GetRuleVersionHistory. +type GetRuleVersionHistoryOptionalParameters struct { + PageSize *int64 + PageNumber *int64 +} + +// NewGetRuleVersionHistoryOptionalParameters creates an empty struct for parameters. +func NewGetRuleVersionHistoryOptionalParameters() *GetRuleVersionHistoryOptionalParameters { + this := GetRuleVersionHistoryOptionalParameters{} + return &this +} + +// WithPageSize sets the corresponding parameter name and returns the struct. +func (r *GetRuleVersionHistoryOptionalParameters) WithPageSize(pageSize int64) *GetRuleVersionHistoryOptionalParameters { + r.PageSize = &pageSize + return r +} + +// WithPageNumber sets the corresponding parameter name and returns the struct. +func (r *GetRuleVersionHistoryOptionalParameters) WithPageNumber(pageNumber int64) *GetRuleVersionHistoryOptionalParameters { + r.PageNumber = &pageNumber + return r +} + +// GetRuleVersionHistory Get a rule's version history. +// Get a rule's version history. +func (a *SecurityMonitoringApi) GetRuleVersionHistory(ctx _context.Context, ruleId string, o ...GetRuleVersionHistoryOptionalParameters) (GetRuleVersionHistoryResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarReturnValue GetRuleVersionHistoryResponse + optionalParams GetRuleVersionHistoryOptionalParameters + ) + + if len(o) > 1 { + return localVarReturnValue, nil, datadog.ReportError("only one argument of type GetRuleVersionHistoryOptionalParameters is allowed") + } + if len(o) == 1 { + optionalParams = o[0] + } + + operationId := "v2.GetRuleVersionHistory" + isOperationEnabled := a.Client.Cfg.IsUnstableOperationEnabled(operationId) + if !isOperationEnabled { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} + } + if isOperationEnabled && a.Client.Cfg.Debug { + _log.Printf("WARNING: Using unstable operation '%s'", operationId) + } + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.SecurityMonitoringApi.GetRuleVersionHistory") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/security_monitoring/rules/{rule_id}/version_history" + localVarPath = datadog.ReplacePathParameter(localVarPath, "{rule_id}", _neturl.PathEscape(datadog.ParameterToString(ruleId, ""))) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + if optionalParams.PageSize != nil { + localVarQueryParams.Add("page[size]", datadog.ParameterToString(*optionalParams.PageSize, "")) + } + if optionalParams.PageNumber != nil { + localVarQueryParams.Add("page[number]", datadog.ParameterToString(*optionalParams.PageNumber, "")) + } + localVarHeaderParams["Accept"] = "application/json" + + 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 == 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 +} + // GetSBOMOptionalParameters holds optional parameters for GetSBOM. type GetSBOMOptionalParameters struct { FilterRepoDigest *string diff --git a/api/datadogV2/doc.go b/api/datadogV2/doc.go index b95975c6842..eb63a3c3cd9 100644 --- a/api/datadogV2/doc.go +++ b/api/datadogV2/doc.go @@ -313,6 +313,7 @@ // - [SecurityMonitoringApi.EditSecurityMonitoringSignalState] // - [SecurityMonitoringApi.GetFinding] // - [SecurityMonitoringApi.GetHistoricalJob] +// - [SecurityMonitoringApi.GetRuleVersionHistory] // - [SecurityMonitoringApi.GetSBOM] // - [SecurityMonitoringApi.GetSecurityFilter] // - [SecurityMonitoringApi.GetSecurityMonitoringRule] diff --git a/api/datadogV2/model_get_rule_version_history_response.go b/api/datadogV2/model_get_rule_version_history_response.go new file mode 100644 index 00000000000..ecb7d36ae9c --- /dev/null +++ b/api/datadogV2/model_get_rule_version_history_response.go @@ -0,0 +1,137 @@ +// 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. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// GetRuleVersionHistoryResponse Response object containing the version history of a rule. +type GetRuleVersionHistoryResponse struct { + // The number of rule versions. + Count *int32 `json:"count,omitempty"` + // A list of rule versions. + Data []RuleVersionHistory `json:"data,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewGetRuleVersionHistoryResponse instantiates a new GetRuleVersionHistoryResponse object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewGetRuleVersionHistoryResponse() *GetRuleVersionHistoryResponse { + this := GetRuleVersionHistoryResponse{} + return &this +} + +// NewGetRuleVersionHistoryResponseWithDefaults instantiates a new GetRuleVersionHistoryResponse object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewGetRuleVersionHistoryResponseWithDefaults() *GetRuleVersionHistoryResponse { + this := GetRuleVersionHistoryResponse{} + return &this +} + +// GetCount returns the Count field value if set, zero value otherwise. +func (o *GetRuleVersionHistoryResponse) GetCount() int32 { + if o == nil || o.Count == nil { + var ret int32 + return ret + } + return *o.Count +} + +// GetCountOk returns a tuple with the Count field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetRuleVersionHistoryResponse) GetCountOk() (*int32, bool) { + if o == nil || o.Count == nil { + return nil, false + } + return o.Count, true +} + +// HasCount returns a boolean if a field has been set. +func (o *GetRuleVersionHistoryResponse) HasCount() bool { + return o != nil && o.Count != nil +} + +// SetCount gets a reference to the given int32 and assigns it to the Count field. +func (o *GetRuleVersionHistoryResponse) SetCount(v int32) { + o.Count = &v +} + +// GetData returns the Data field value if set, zero value otherwise. +func (o *GetRuleVersionHistoryResponse) GetData() []RuleVersionHistory { + if o == nil || o.Data == nil { + var ret []RuleVersionHistory + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetRuleVersionHistoryResponse) GetDataOk() (*[]RuleVersionHistory, bool) { + if o == nil || o.Data == nil { + return nil, false + } + return &o.Data, true +} + +// HasData returns a boolean if a field has been set. +func (o *GetRuleVersionHistoryResponse) HasData() bool { + return o != nil && o.Data != nil +} + +// SetData gets a reference to the given []RuleVersionHistory and assigns it to the Data field. +func (o *GetRuleVersionHistoryResponse) SetData(v []RuleVersionHistory) { + o.Data = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o GetRuleVersionHistoryResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Count != nil { + toSerialize["count"] = o.Count + } + if o.Data != nil { + toSerialize["data"] = o.Data + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *GetRuleVersionHistoryResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Count *int32 `json:"count,omitempty"` + Data []RuleVersionHistory `json:"data,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"count", "data"}) + } else { + return err + } + o.Count = all.Count + o.Data = all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_rule_version_history.go b/api/datadogV2/model_rule_version_history.go new file mode 100644 index 00000000000..457d7f97c45 --- /dev/null +++ b/api/datadogV2/model_rule_version_history.go @@ -0,0 +1,137 @@ +// 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. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// RuleVersionHistory A rule version with a list of updates. +type RuleVersionHistory struct { + // A list of changes. + Changes []RuleVersionUpdate `json:"changes,omitempty"` + // Create a new rule. + Rule *SecurityMonitoringRuleResponse `json:"rule,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewRuleVersionHistory instantiates a new RuleVersionHistory object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewRuleVersionHistory() *RuleVersionHistory { + this := RuleVersionHistory{} + return &this +} + +// NewRuleVersionHistoryWithDefaults instantiates a new RuleVersionHistory object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewRuleVersionHistoryWithDefaults() *RuleVersionHistory { + this := RuleVersionHistory{} + return &this +} + +// GetChanges returns the Changes field value if set, zero value otherwise. +func (o *RuleVersionHistory) GetChanges() []RuleVersionUpdate { + if o == nil || o.Changes == nil { + var ret []RuleVersionUpdate + return ret + } + return o.Changes +} + +// GetChangesOk returns a tuple with the Changes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *RuleVersionHistory) GetChangesOk() (*[]RuleVersionUpdate, bool) { + if o == nil || o.Changes == nil { + return nil, false + } + return &o.Changes, true +} + +// HasChanges returns a boolean if a field has been set. +func (o *RuleVersionHistory) HasChanges() bool { + return o != nil && o.Changes != nil +} + +// SetChanges gets a reference to the given []RuleVersionUpdate and assigns it to the Changes field. +func (o *RuleVersionHistory) SetChanges(v []RuleVersionUpdate) { + o.Changes = v +} + +// GetRule returns the Rule field value if set, zero value otherwise. +func (o *RuleVersionHistory) GetRule() SecurityMonitoringRuleResponse { + if o == nil || o.Rule == nil { + var ret SecurityMonitoringRuleResponse + return ret + } + return *o.Rule +} + +// GetRuleOk returns a tuple with the Rule field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *RuleVersionHistory) GetRuleOk() (*SecurityMonitoringRuleResponse, bool) { + if o == nil || o.Rule == nil { + return nil, false + } + return o.Rule, true +} + +// HasRule returns a boolean if a field has been set. +func (o *RuleVersionHistory) HasRule() bool { + return o != nil && o.Rule != nil +} + +// SetRule gets a reference to the given SecurityMonitoringRuleResponse and assigns it to the Rule field. +func (o *RuleVersionHistory) SetRule(v SecurityMonitoringRuleResponse) { + o.Rule = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o RuleVersionHistory) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Changes != nil { + toSerialize["changes"] = o.Changes + } + if o.Rule != nil { + toSerialize["rule"] = o.Rule + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *RuleVersionHistory) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Changes []RuleVersionUpdate `json:"changes,omitempty"` + Rule *SecurityMonitoringRuleResponse `json:"rule,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"changes", "rule"}) + } else { + return err + } + o.Changes = all.Changes + o.Rule = all.Rule + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_rule_version_update.go b/api/datadogV2/model_rule_version_update.go new file mode 100644 index 00000000000..f86259e35db --- /dev/null +++ b/api/datadogV2/model_rule_version_update.go @@ -0,0 +1,182 @@ +// 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. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// RuleVersionUpdate A change in a rule version. +type RuleVersionUpdate struct { + // The new value of the field. + Change *string `json:"change,omitempty"` + // The field that was changed. + Field *string `json:"field,omitempty"` + // The type of change. + Type *RuleVersionUpdateType `json:"type,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewRuleVersionUpdate instantiates a new RuleVersionUpdate object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewRuleVersionUpdate() *RuleVersionUpdate { + this := RuleVersionUpdate{} + return &this +} + +// NewRuleVersionUpdateWithDefaults instantiates a new RuleVersionUpdate object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewRuleVersionUpdateWithDefaults() *RuleVersionUpdate { + this := RuleVersionUpdate{} + return &this +} + +// GetChange returns the Change field value if set, zero value otherwise. +func (o *RuleVersionUpdate) GetChange() string { + if o == nil || o.Change == nil { + var ret string + return ret + } + return *o.Change +} + +// GetChangeOk returns a tuple with the Change field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *RuleVersionUpdate) GetChangeOk() (*string, bool) { + if o == nil || o.Change == nil { + return nil, false + } + return o.Change, true +} + +// HasChange returns a boolean if a field has been set. +func (o *RuleVersionUpdate) HasChange() bool { + return o != nil && o.Change != nil +} + +// SetChange gets a reference to the given string and assigns it to the Change field. +func (o *RuleVersionUpdate) SetChange(v string) { + o.Change = &v +} + +// GetField returns the Field field value if set, zero value otherwise. +func (o *RuleVersionUpdate) GetField() string { + if o == nil || o.Field == nil { + var ret string + return ret + } + return *o.Field +} + +// GetFieldOk returns a tuple with the Field field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *RuleVersionUpdate) GetFieldOk() (*string, bool) { + if o == nil || o.Field == nil { + return nil, false + } + return o.Field, true +} + +// HasField returns a boolean if a field has been set. +func (o *RuleVersionUpdate) HasField() bool { + return o != nil && o.Field != nil +} + +// SetField gets a reference to the given string and assigns it to the Field field. +func (o *RuleVersionUpdate) SetField(v string) { + o.Field = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *RuleVersionUpdate) GetType() RuleVersionUpdateType { + if o == nil || o.Type == nil { + var ret RuleVersionUpdateType + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *RuleVersionUpdate) GetTypeOk() (*RuleVersionUpdateType, bool) { + if o == nil || o.Type == nil { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *RuleVersionUpdate) HasType() bool { + return o != nil && o.Type != nil +} + +// SetType gets a reference to the given RuleVersionUpdateType and assigns it to the Type field. +func (o *RuleVersionUpdate) SetType(v RuleVersionUpdateType) { + o.Type = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o RuleVersionUpdate) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Change != nil { + toSerialize["change"] = o.Change + } + if o.Field != nil { + toSerialize["field"] = o.Field + } + if o.Type != nil { + toSerialize["type"] = o.Type + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *RuleVersionUpdate) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Change *string `json:"change,omitempty"` + Field *string `json:"field,omitempty"` + Type *RuleVersionUpdateType `json:"type,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"change", "field", "type"}) + } else { + return err + } + + hasInvalidField := false + o.Change = all.Change + o.Field = all.Field + if all.Type != nil && !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_rule_version_update_type.go b/api/datadogV2/model_rule_version_update_type.go new file mode 100644 index 00000000000..24674c8efbe --- /dev/null +++ b/api/datadogV2/model_rule_version_update_type.go @@ -0,0 +1,68 @@ +// 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. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// RuleVersionUpdateType The type of change. +type RuleVersionUpdateType string + +// List of RuleVersionUpdateType. +const ( + RULEVERSIONUPDATETYPE_CREATE RuleVersionUpdateType = "create" + RULEVERSIONUPDATETYPE_UPDATE RuleVersionUpdateType = "update" + RULEVERSIONUPDATETYPE_DELETE RuleVersionUpdateType = "delete" +) + +var allowedRuleVersionUpdateTypeEnumValues = []RuleVersionUpdateType{ + RULEVERSIONUPDATETYPE_CREATE, + RULEVERSIONUPDATETYPE_UPDATE, + RULEVERSIONUPDATETYPE_DELETE, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *RuleVersionUpdateType) GetAllowedValues() []RuleVersionUpdateType { + return allowedRuleVersionUpdateTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *RuleVersionUpdateType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = RuleVersionUpdateType(value) + return nil +} + +// NewRuleVersionUpdateTypeFromValue returns a pointer to a valid RuleVersionUpdateType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewRuleVersionUpdateTypeFromValue(v string) (*RuleVersionUpdateType, error) { + ev := RuleVersionUpdateType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for RuleVersionUpdateType: valid values are %v", v, allowedRuleVersionUpdateTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v RuleVersionUpdateType) IsValid() bool { + for _, existing := range allowedRuleVersionUpdateTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to RuleVersionUpdateType value. +func (v RuleVersionUpdateType) Ptr() *RuleVersionUpdateType { + return &v +} diff --git a/examples/v2/security-monitoring/GetRuleVersionHistory.go b/examples/v2/security-monitoring/GetRuleVersionHistory.go new file mode 100644 index 00000000000..5833f5e0001 --- /dev/null +++ b/examples/v2/security-monitoring/GetRuleVersionHistory.go @@ -0,0 +1,30 @@ +// Get a rule's version history returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + configuration.SetUnstableOperationEnabled("v2.GetRuleVersionHistory", true) + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewSecurityMonitoringApi(apiClient) + resp, r, err := api.GetRuleVersionHistory(ctx, "rule_id", *datadogV2.NewGetRuleVersionHistoryOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SecurityMonitoringApi.GetRuleVersionHistory`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `SecurityMonitoringApi.GetRuleVersionHistory`:\n%s\n", responseContent) +} diff --git a/examples/v2/security-monitoring/GetRuleVersionHistory_2467565841.go b/examples/v2/security-monitoring/GetRuleVersionHistory_2467565841.go new file mode 100644 index 00000000000..de69c6004a9 --- /dev/null +++ b/examples/v2/security-monitoring/GetRuleVersionHistory_2467565841.go @@ -0,0 +1,32 @@ +// Get rule version history returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + // there is a valid "security_rule" in the system + SecurityRuleID := os.Getenv("SECURITY_RULE_ID") + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewSecurityMonitoringApi(apiClient) + resp, r, err := api.GetRuleVersionHistory(ctx, SecurityRuleID, *datadogV2.NewGetRuleVersionHistoryOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SecurityMonitoringApi.GetRuleVersionHistory`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `SecurityMonitoringApi.GetRuleVersionHistory`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Security_Monitoring/Scenario_Get_rule_version_history_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Security_Monitoring/Scenario_Get_rule_version_history_returns_OK_response.freeze new file mode 100644 index 00000000000..670a38cd3bd --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Security_Monitoring/Scenario_Get_rule_version_history_returns_OK_response.freeze @@ -0,0 +1 @@ +2025-01-22T19:09:57.587Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Security_Monitoring/Scenario_Get_rule_version_history_returns_OK_response.yaml b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Security_Monitoring/Scenario_Get_rule_version_history_returns_OK_response.yaml new file mode 100644 index 00000000000..fb7283ba77b --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Security_Monitoring/Scenario_Get_rule_version_history_returns_OK_response.yaml @@ -0,0 +1,40 @@ +interactions: +- request: + body: | + {"cases":[{"condition":"a \u003e 0","name":"","notifications":[],"status":"info"}],"filters":[],"isEnabled":true,"message":"Test rule","name":"Test-Get_rule_version_history_returns_OK_response-1737572997","options":{"evaluationWindow":900,"keepAlive":3600,"maxSignalDuration":86400},"queries":[{"aggregation":"count","distinctFields":[],"groupByFields":[],"metrics":[],"query":"@test:true"}],"tags":[],"type":"log_detection"} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: POST + url: https://api.datadoghq.com/api/v2/security_monitoring/rules + response: + body: '{"name":"Test-Get_rule_version_history_returns_OK_response-1737572997","createdAt":1737572997841,"isDefault":false,"isPartner":false,"isEnabled":true,"isBeta":false,"isDeleted":false,"isDeprecated":false,"queries":[{"query":"@test:true","groupByFields":[],"hasOptionalGroupByFields":false,"distinctFields":[],"aggregation":"count","name":""}],"options":{"evaluationWindow":900,"detectionMethod":"threshold","maxSignalDuration":86400,"keepAlive":3600},"cases":[{"name":"","status":"info","notifications":[],"condition":"a + \u003e 0"}],"message":"Test rule","tags":[],"hasExtendedTitle":false,"type":"log_detection","filters":[],"version":1,"id":"fs9-8co-iib","blocking":false,"metadata":{"entities":null,"sources":null},"creationAuthorId":1445416,"creator":{"handle":"frog@datadoghq.com","name":"frog"},"updater":{"handle":"","name":""}}' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: '' + form: {} + headers: + Accept: + - '*/*' + id: 1 + method: DELETE + url: https://api.datadoghq.com/api/v2/security_monitoring/rules/fs9-8co-iib + response: + body: '' + code: 204 + duration: 0ms + headers: + Content-Type: + - text/html; charset=utf-8 + status: 204 No Content +version: 2 diff --git a/tests/scenarios/features/v2/security_monitoring.feature b/tests/scenarios/features/v2/security_monitoring.feature index 5a2330a8f35..93d55d4556c 100644 --- a/tests/scenarios/features/v2/security_monitoring.feature +++ b/tests/scenarios/features/v2/security_monitoring.feature @@ -534,6 +534,30 @@ Feature: Security Monitoring And the response "name" is equal to "{{ unique }}" And the response "id" has the same value as "security_rule.id" + @generated @skip @team:DataDog/k9-cloud-security-platform + Scenario: Get a rule's version history returns "Bad Request" response + Given operation "GetRuleVersionHistory" enabled + And new "GetRuleVersionHistory" request + And request contains "rule_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/k9-cloud-security-platform + Scenario: Get a rule's version history returns "Not Found" response + Given operation "GetRuleVersionHistory" enabled + And new "GetRuleVersionHistory" request + And request contains "rule_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/k9-cloud-security-platform + Scenario: Get a rule's version history returns "OK" response + Given operation "GetRuleVersionHistory" enabled + And new "GetRuleVersionHistory" request + And request contains "rule_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + @generated @skip @team:DataDog/k9-cloud-security-platform Scenario: Get a security filter returns "Not Found" response Given new "GetSecurityFilter" request @@ -599,6 +623,17 @@ Feature: Security Monitoring When the request is sent Then the response status is 200 OK + @replay-only @skip-validation @team:DataDog/k9-cloud-security-platform + Scenario: Get rule version history returns "OK" response + Given new "GetRuleVersionHistory" request + And there is a valid "security_rule" in the system + And request contains "rule_id" parameter from "security_rule.id" + When the request is sent + Then the response status is 200 OK + And the response "data.id" has the same value as "security_rule.id" + And the response "data.attributes.count" is equal to 1 + And the response "data.attributes.data[1].rule.name" has the same value as "security_rule.name" + @generated @skip @team:DataDog/cloud-security-posture-management Scenario: List findings returns "Bad Request: The server cannot process the request due to invalid syntax in the request." response Given operation "ListFindings" enabled diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index a195ddc9e5e..e06f3332f45 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -2251,6 +2251,12 @@ "type": "idempotent" } }, + "GetRuleVersionHistory": { + "tag": "Security Monitoring", + "undo": { + "type": "safe" + } + }, "ListSecurityMonitoringSignals": { "tag": "Security Monitoring", "undo": {