diff --git a/.apigentools-info b/.apigentools-info index 297f5e4f13b..c06552db28d 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-09 15:03:02.042923", - "spec_repo_commit": "43ae024c" + "regenerated": "2024-10-09 19:50:41.505984", + "spec_repo_commit": "e2da1982" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-09 15:03:02.062476", - "spec_repo_commit": "43ae024c" + "regenerated": "2024-10-09 19:50:41.524188", + "spec_repo_commit": "e2da1982" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 3ee9a258d25..4d8a047e5bd 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -3951,6 +3951,226 @@ components: format: int64 type: integer type: object + ChangeEvent: + description: Object representing a change event. + properties: + aggregation_key: + description: 'An arbitrary string to use for aggregation. Limited to 100 + characters. + + If you specify a key, all events using that key are grouped together in + the Event Stream.' + maxLength: 100 + type: string + attributes: + $ref: '#/components/schemas/ChangeEventCustomAttributes' + category: + $ref: '#/components/schemas/ChangeEventCategory' + message: + description: The body of the event. Limited to 4000 characters. + example: payment_processed feature flag has been enabled + maxLength: 4000 + type: string + tags: + description: 'A list of tags to apply to the event. + + Refer to [Tags docs](https://docs.datadoghq.com/getting_started/tagging/).' + example: + - environment:test + items: + description: A tag. + type: string + type: array + timestamp: + description: 'Timestamp in which the event occurred. Must follow [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) + format. + + For example `"2017-01-15T01:30:15.010000Z"`. + + Defaults to now. Limited to values no older than 18 hours.' + type: string + title: + description: The event title. Limited to 500 characters. + example: payment_processed feature flag updated + maxLength: 500 + type: string + required: + - title + - category + - attributes + type: object + ChangeEventCategory: + description: Event category to identify the type of event. Only the value `change` + is supported. + enum: + - change + example: change + type: string + x-enum-varnames: + - CHANGE + ChangeEventCreateRequest: + description: Object representing an event. + properties: + attributes: + $ref: '#/components/schemas/ChangeEvent' + type: + $ref: '#/components/schemas/ChangeEventCreateRequestType' + type: object + ChangeEventCreateRequestType: + description: Entity type. + enum: + - event + type: string + x-enum-varnames: + - EVENT + ChangeEventCreateResponse: + description: Object containing an event response. + properties: + attributes: + $ref: '#/components/schemas/ChangeEventCreateResponseAttributes' + type: + description: Event type + type: string + type: object + ChangeEventCreateResponseAttributes: + description: The definition of `ChangeEventCreateResponseAttributes` object. + properties: + attributes: + $ref: '#/components/schemas/ChangeEventCreateResponseAttributesAttributes' + type: object + ChangeEventCreateResponseAttributesAttributes: + description: The definition of `ChangeEventCreateResponseAttributesAttributes` + object. + properties: + evt: + $ref: '#/components/schemas/ChangeEventCreateResponseAttributesAttributesEvt' + type: object + ChangeEventCreateResponseAttributesAttributesEvt: + description: The definition of `ChangeEventCreateResponseAttributesAttributesEvt` + object. + properties: + id: + description: Event id + type: string + type: object + ChangeEventCustomAttributes: + description: Object representing custom event attributes. + properties: + author: + $ref: '#/components/schemas/ChangeEventCustomAttributesAuthor' + change_metadata: + additionalProperties: {} + description: Free form object with any related information of the `change` + event. + example: + resource_link: /feature/fallback_payments_test + user: + email: dd_user_email + name: dd_user + type: object + changed_resource: + $ref: '#/components/schemas/ChangeEventCustomAttributesChangedResource' + impacted_resources: + description: 'A list of resources impacted by this change. At least one + resource is required. Only resources + + of type `service` are supported.' + example: + - name: payments_api + type: service + items: + $ref: '#/components/schemas/ChangeEventCustomAttributesImpactedResourcesItems' + type: array + new_value: + additionalProperties: {} + description: Free form object to track new value of the changed resource. + example: + enabled: true + percentage: 50% + rule: + datacenter: us1.prod + type: object + prev_value: + additionalProperties: {} + description: Free form object to track previous value of the changed resource. + example: + enabled: true + percentage: 10% + rule: + datacenter: us1.prod + type: object + required: + - changed_resource + type: object + ChangeEventCustomAttributesAuthor: + description: Object representing the entity which made the change. Optional + field but if provided should include `type` and `name`. + properties: + name: + description: Author's name. Limited to 128 characters. + example: '' + maxLength: 128.0 + type: string + type: + $ref: '#/components/schemas/ChangeEventCustomAttributesAuthorType' + required: + - name + - type + type: object + ChangeEventCustomAttributesAuthorType: + description: Author's type. + enum: + - user + - system + example: user + type: string + x-enum-varnames: + - USER + - SYSTEM + ChangeEventCustomAttributesChangedResource: + description: Object representing a uniquely identified resource. Only the resource + type `feature_flag` is supported. + properties: + name: + description: Resource's name. + example: fallback_payments_test + type: string + type: + $ref: '#/components/schemas/ChangeEventCustomAttributesChangedResourceType' + required: + - type + - name + type: object + ChangeEventCustomAttributesChangedResourceType: + description: Resource's type. + enum: + - feature_flag + example: feature_flag + type: string + x-enum-varnames: + - FEATURE_FLAG + ChangeEventCustomAttributesImpactedResourcesItems: + description: Object representing a uniquely identified resource. Only the resource + type `service` is supported. + properties: + name: + description: Resource's name. + example: payments_api + type: string + type: + $ref: '#/components/schemas/ChangeEventCustomAttributesImpactedResourcesItemsType' + required: + - type + - name + type: object + ChangeEventCustomAttributesImpactedResourcesItemsType: + description: Resource's type. + enum: + - service + example: service + type: string + x-enum-varnames: + - SERVICE ChargebackBreakdown: description: Charges breakdown. properties: @@ -29664,6 +29884,44 @@ paths: operator: OR permissions: - events_read + post: + description: This endpoint allows you to post events. Only events with `change` + category are supported. + operationId: CreateEvent + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ChangeEventCreateRequest' + description: Event request object + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ChangeEventCreateResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Bad request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Forbidden + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + summary: Post a change event + tags: + - Events + x-codegen-request-body-name: body /api/v2/events/search: post: description: 'List endpoint returns events that match an events search query. diff --git a/api/datadogV2/api_events.go b/api/datadogV2/api_events.go index e5478921593..bd32d458cb1 100644 --- a/api/datadogV2/api_events.go +++ b/api/datadogV2/api_events.go @@ -15,6 +15,87 @@ import ( // EventsApi service type type EventsApi datadog.Service +// CreateEvent Post a change event. +// This endpoint allows you to post events. Only events with `change` category are supported. +func (a *EventsApi) CreateEvent(ctx _context.Context, body ChangeEventCreateRequest) (ChangeEventCreateResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarReturnValue ChangeEventCreateResponse + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.EventsApi.CreateEvent") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/events" + + 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"}, + ) + 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 { + var v JSONAPIErrorResponse + 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 + } + if 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 +} + // ListEventsOptionalParameters holds optional parameters for ListEvents. type ListEventsOptionalParameters struct { FilterQuery *string diff --git a/api/datadogV2/doc.go b/api/datadogV2/doc.go index 8a27584b8b8..b23448f53f9 100644 --- a/api/datadogV2/doc.go +++ b/api/datadogV2/doc.go @@ -96,6 +96,7 @@ // - [DowntimesApi.ListDowntimes] // - [DowntimesApi.ListMonitorDowntimes] // - [DowntimesApi.UpdateDowntime] +// - [EventsApi.CreateEvent] // - [EventsApi.ListEvents] // - [EventsApi.SearchEvents] // - [FastlyIntegrationApi.CreateFastlyAccount] diff --git a/api/datadogV2/model_change_event.go b/api/datadogV2/model_change_event.go new file mode 100644 index 00000000000..8012600cefd --- /dev/null +++ b/api/datadogV2/model_change_event.go @@ -0,0 +1,322 @@ +// 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" +) + +// ChangeEvent Object representing a change event. +type ChangeEvent struct { + // An arbitrary string to use for aggregation. Limited to 100 characters. + // If you specify a key, all events using that key are grouped together in the Event Stream. + AggregationKey *string `json:"aggregation_key,omitempty"` + // Object representing custom event attributes. + Attributes ChangeEventCustomAttributes `json:"attributes"` + // Event category to identify the type of event. Only the value `change` is supported. + Category ChangeEventCategory `json:"category"` + // The body of the event. Limited to 4000 characters. + Message *string `json:"message,omitempty"` + // A list of tags to apply to the event. + // Refer to [Tags docs](https://docs.datadoghq.com/getting_started/tagging/). + Tags []string `json:"tags,omitempty"` + // Timestamp in which the event occurred. Must follow [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. + // For example `"2017-01-15T01:30:15.010000Z"`. + // Defaults to now. Limited to values no older than 18 hours. + Timestamp *string `json:"timestamp,omitempty"` + // The event title. Limited to 500 characters. + Title string `json:"title"` + // 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:"-"` +} + +// NewChangeEvent instantiates a new ChangeEvent 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 NewChangeEvent(attributes ChangeEventCustomAttributes, category ChangeEventCategory, title string) *ChangeEvent { + this := ChangeEvent{} + this.Attributes = attributes + this.Category = category + this.Title = title + return &this +} + +// NewChangeEventWithDefaults instantiates a new ChangeEvent 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 NewChangeEventWithDefaults() *ChangeEvent { + this := ChangeEvent{} + return &this +} + +// GetAggregationKey returns the AggregationKey field value if set, zero value otherwise. +func (o *ChangeEvent) GetAggregationKey() string { + if o == nil || o.AggregationKey == nil { + var ret string + return ret + } + return *o.AggregationKey +} + +// GetAggregationKeyOk returns a tuple with the AggregationKey field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEvent) GetAggregationKeyOk() (*string, bool) { + if o == nil || o.AggregationKey == nil { + return nil, false + } + return o.AggregationKey, true +} + +// HasAggregationKey returns a boolean if a field has been set. +func (o *ChangeEvent) HasAggregationKey() bool { + return o != nil && o.AggregationKey != nil +} + +// SetAggregationKey gets a reference to the given string and assigns it to the AggregationKey field. +func (o *ChangeEvent) SetAggregationKey(v string) { + o.AggregationKey = &v +} + +// GetAttributes returns the Attributes field value. +func (o *ChangeEvent) GetAttributes() ChangeEventCustomAttributes { + if o == nil { + var ret ChangeEventCustomAttributes + return ret + } + return o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value +// and a boolean to check if the value has been set. +func (o *ChangeEvent) GetAttributesOk() (*ChangeEventCustomAttributes, bool) { + if o == nil { + return nil, false + } + return &o.Attributes, true +} + +// SetAttributes sets field value. +func (o *ChangeEvent) SetAttributes(v ChangeEventCustomAttributes) { + o.Attributes = v +} + +// GetCategory returns the Category field value. +func (o *ChangeEvent) GetCategory() ChangeEventCategory { + if o == nil { + var ret ChangeEventCategory + return ret + } + return o.Category +} + +// GetCategoryOk returns a tuple with the Category field value +// and a boolean to check if the value has been set. +func (o *ChangeEvent) GetCategoryOk() (*ChangeEventCategory, bool) { + if o == nil { + return nil, false + } + return &o.Category, true +} + +// SetCategory sets field value. +func (o *ChangeEvent) SetCategory(v ChangeEventCategory) { + o.Category = v +} + +// GetMessage returns the Message field value if set, zero value otherwise. +func (o *ChangeEvent) GetMessage() string { + if o == nil || o.Message == nil { + var ret string + return ret + } + return *o.Message +} + +// GetMessageOk returns a tuple with the Message field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEvent) GetMessageOk() (*string, bool) { + if o == nil || o.Message == nil { + return nil, false + } + return o.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (o *ChangeEvent) HasMessage() bool { + return o != nil && o.Message != nil +} + +// SetMessage gets a reference to the given string and assigns it to the Message field. +func (o *ChangeEvent) SetMessage(v string) { + o.Message = &v +} + +// GetTags returns the Tags field value if set, zero value otherwise. +func (o *ChangeEvent) GetTags() []string { + if o == nil || o.Tags == nil { + var ret []string + return ret + } + return o.Tags +} + +// GetTagsOk returns a tuple with the Tags field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEvent) GetTagsOk() (*[]string, bool) { + if o == nil || o.Tags == nil { + return nil, false + } + return &o.Tags, true +} + +// HasTags returns a boolean if a field has been set. +func (o *ChangeEvent) HasTags() bool { + return o != nil && o.Tags != nil +} + +// SetTags gets a reference to the given []string and assigns it to the Tags field. +func (o *ChangeEvent) SetTags(v []string) { + o.Tags = v +} + +// GetTimestamp returns the Timestamp field value if set, zero value otherwise. +func (o *ChangeEvent) GetTimestamp() string { + if o == nil || o.Timestamp == nil { + var ret string + return ret + } + return *o.Timestamp +} + +// GetTimestampOk returns a tuple with the Timestamp field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEvent) GetTimestampOk() (*string, bool) { + if o == nil || o.Timestamp == nil { + return nil, false + } + return o.Timestamp, true +} + +// HasTimestamp returns a boolean if a field has been set. +func (o *ChangeEvent) HasTimestamp() bool { + return o != nil && o.Timestamp != nil +} + +// SetTimestamp gets a reference to the given string and assigns it to the Timestamp field. +func (o *ChangeEvent) SetTimestamp(v string) { + o.Timestamp = &v +} + +// GetTitle returns the Title field value. +func (o *ChangeEvent) GetTitle() string { + if o == nil { + var ret string + return ret + } + return o.Title +} + +// GetTitleOk returns a tuple with the Title field value +// and a boolean to check if the value has been set. +func (o *ChangeEvent) GetTitleOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Title, true +} + +// SetTitle sets field value. +func (o *ChangeEvent) SetTitle(v string) { + o.Title = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEvent) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.AggregationKey != nil { + toSerialize["aggregation_key"] = o.AggregationKey + } + toSerialize["attributes"] = o.Attributes + toSerialize["category"] = o.Category + if o.Message != nil { + toSerialize["message"] = o.Message + } + if o.Tags != nil { + toSerialize["tags"] = o.Tags + } + if o.Timestamp != nil { + toSerialize["timestamp"] = o.Timestamp + } + toSerialize["title"] = o.Title + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *ChangeEvent) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + AggregationKey *string `json:"aggregation_key,omitempty"` + Attributes *ChangeEventCustomAttributes `json:"attributes"` + Category *ChangeEventCategory `json:"category"` + Message *string `json:"message,omitempty"` + Tags []string `json:"tags,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` + Title *string `json:"title"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Attributes == nil { + return fmt.Errorf("required field attributes missing") + } + if all.Category == nil { + return fmt.Errorf("required field category missing") + } + if all.Title == nil { + return fmt.Errorf("required field title missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"aggregation_key", "attributes", "category", "message", "tags", "timestamp", "title"}) + } else { + return err + } + + hasInvalidField := false + o.AggregationKey = all.AggregationKey + if all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = *all.Attributes + if !all.Category.IsValid() { + hasInvalidField = true + } else { + o.Category = *all.Category + } + o.Message = all.Message + o.Tags = all.Tags + o.Timestamp = all.Timestamp + o.Title = *all.Title + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_change_event_category.go b/api/datadogV2/model_change_event_category.go new file mode 100644 index 00000000000..3ce9ab31798 --- /dev/null +++ b/api/datadogV2/model_change_event_category.go @@ -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. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// ChangeEventCategory Event category to identify the type of event. Only the value `change` is supported. +type ChangeEventCategory string + +// List of ChangeEventCategory. +const ( + CHANGEEVENTCATEGORY_CHANGE ChangeEventCategory = "change" +) + +var allowedChangeEventCategoryEnumValues = []ChangeEventCategory{ + CHANGEEVENTCATEGORY_CHANGE, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *ChangeEventCategory) GetAllowedValues() []ChangeEventCategory { + return allowedChangeEventCategoryEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *ChangeEventCategory) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = ChangeEventCategory(value) + return nil +} + +// NewChangeEventCategoryFromValue returns a pointer to a valid ChangeEventCategory +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewChangeEventCategoryFromValue(v string) (*ChangeEventCategory, error) { + ev := ChangeEventCategory(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for ChangeEventCategory: valid values are %v", v, allowedChangeEventCategoryEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v ChangeEventCategory) IsValid() bool { + for _, existing := range allowedChangeEventCategoryEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to ChangeEventCategory value. +func (v ChangeEventCategory) Ptr() *ChangeEventCategory { + return &v +} diff --git a/api/datadogV2/model_change_event_create_request.go b/api/datadogV2/model_change_event_create_request.go new file mode 100644 index 00000000000..bf6aa3927d5 --- /dev/null +++ b/api/datadogV2/model_change_event_create_request.go @@ -0,0 +1,150 @@ +// 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" +) + +// ChangeEventCreateRequest Object representing an event. +type ChangeEventCreateRequest struct { + // Object representing a change event. + Attributes *ChangeEvent `json:"attributes,omitempty"` + // Entity type. + Type *ChangeEventCreateRequestType `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:"-"` +} + +// NewChangeEventCreateRequest instantiates a new ChangeEventCreateRequest 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 NewChangeEventCreateRequest() *ChangeEventCreateRequest { + this := ChangeEventCreateRequest{} + return &this +} + +// NewChangeEventCreateRequestWithDefaults instantiates a new ChangeEventCreateRequest 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 NewChangeEventCreateRequestWithDefaults() *ChangeEventCreateRequest { + this := ChangeEventCreateRequest{} + return &this +} + +// GetAttributes returns the Attributes field value if set, zero value otherwise. +func (o *ChangeEventCreateRequest) GetAttributes() ChangeEvent { + if o == nil || o.Attributes == nil { + var ret ChangeEvent + return ret + } + return *o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCreateRequest) GetAttributesOk() (*ChangeEvent, bool) { + if o == nil || o.Attributes == nil { + return nil, false + } + return o.Attributes, true +} + +// HasAttributes returns a boolean if a field has been set. +func (o *ChangeEventCreateRequest) HasAttributes() bool { + return o != nil && o.Attributes != nil +} + +// SetAttributes gets a reference to the given ChangeEvent and assigns it to the Attributes field. +func (o *ChangeEventCreateRequest) SetAttributes(v ChangeEvent) { + o.Attributes = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *ChangeEventCreateRequest) GetType() ChangeEventCreateRequestType { + if o == nil || o.Type == nil { + var ret ChangeEventCreateRequestType + 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 *ChangeEventCreateRequest) GetTypeOk() (*ChangeEventCreateRequestType, 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 *ChangeEventCreateRequest) HasType() bool { + return o != nil && o.Type != nil +} + +// SetType gets a reference to the given ChangeEventCreateRequestType and assigns it to the Type field. +func (o *ChangeEventCreateRequest) SetType(v ChangeEventCreateRequestType) { + o.Type = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEventCreateRequest) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Attributes != nil { + toSerialize["attributes"] = o.Attributes + } + 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 *ChangeEventCreateRequest) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *ChangeEvent `json:"attributes,omitempty"` + Type *ChangeEventCreateRequestType `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{"attributes", "type"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes != nil && all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = all.Attributes + 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_change_event_create_request_type.go b/api/datadogV2/model_change_event_create_request_type.go new file mode 100644 index 00000000000..4b7d05d5bd5 --- /dev/null +++ b/api/datadogV2/model_change_event_create_request_type.go @@ -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. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// ChangeEventCreateRequestType Entity type. +type ChangeEventCreateRequestType string + +// List of ChangeEventCreateRequestType. +const ( + CHANGEEVENTCREATEREQUESTTYPE_EVENT ChangeEventCreateRequestType = "event" +) + +var allowedChangeEventCreateRequestTypeEnumValues = []ChangeEventCreateRequestType{ + CHANGEEVENTCREATEREQUESTTYPE_EVENT, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *ChangeEventCreateRequestType) GetAllowedValues() []ChangeEventCreateRequestType { + return allowedChangeEventCreateRequestTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *ChangeEventCreateRequestType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = ChangeEventCreateRequestType(value) + return nil +} + +// NewChangeEventCreateRequestTypeFromValue returns a pointer to a valid ChangeEventCreateRequestType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewChangeEventCreateRequestTypeFromValue(v string) (*ChangeEventCreateRequestType, error) { + ev := ChangeEventCreateRequestType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for ChangeEventCreateRequestType: valid values are %v", v, allowedChangeEventCreateRequestTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v ChangeEventCreateRequestType) IsValid() bool { + for _, existing := range allowedChangeEventCreateRequestTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to ChangeEventCreateRequestType value. +func (v ChangeEventCreateRequestType) Ptr() *ChangeEventCreateRequestType { + return &v +} diff --git a/api/datadogV2/model_change_event_create_response.go b/api/datadogV2/model_change_event_create_response.go new file mode 100644 index 00000000000..ecd5888c738 --- /dev/null +++ b/api/datadogV2/model_change_event_create_response.go @@ -0,0 +1,146 @@ +// 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" +) + +// ChangeEventCreateResponse Object containing an event response. +type ChangeEventCreateResponse struct { + // The definition of `ChangeEventCreateResponseAttributes` object. + Attributes *ChangeEventCreateResponseAttributes `json:"attributes,omitempty"` + // Event type + Type *string `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:"-"` +} + +// NewChangeEventCreateResponse instantiates a new ChangeEventCreateResponse 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 NewChangeEventCreateResponse() *ChangeEventCreateResponse { + this := ChangeEventCreateResponse{} + return &this +} + +// NewChangeEventCreateResponseWithDefaults instantiates a new ChangeEventCreateResponse 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 NewChangeEventCreateResponseWithDefaults() *ChangeEventCreateResponse { + this := ChangeEventCreateResponse{} + return &this +} + +// GetAttributes returns the Attributes field value if set, zero value otherwise. +func (o *ChangeEventCreateResponse) GetAttributes() ChangeEventCreateResponseAttributes { + if o == nil || o.Attributes == nil { + var ret ChangeEventCreateResponseAttributes + return ret + } + return *o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCreateResponse) GetAttributesOk() (*ChangeEventCreateResponseAttributes, bool) { + if o == nil || o.Attributes == nil { + return nil, false + } + return o.Attributes, true +} + +// HasAttributes returns a boolean if a field has been set. +func (o *ChangeEventCreateResponse) HasAttributes() bool { + return o != nil && o.Attributes != nil +} + +// SetAttributes gets a reference to the given ChangeEventCreateResponseAttributes and assigns it to the Attributes field. +func (o *ChangeEventCreateResponse) SetAttributes(v ChangeEventCreateResponseAttributes) { + o.Attributes = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *ChangeEventCreateResponse) GetType() string { + if o == nil || o.Type == nil { + var ret string + 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 *ChangeEventCreateResponse) GetTypeOk() (*string, 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 *ChangeEventCreateResponse) HasType() bool { + return o != nil && o.Type != nil +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *ChangeEventCreateResponse) SetType(v string) { + o.Type = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEventCreateResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Attributes != nil { + toSerialize["attributes"] = o.Attributes + } + 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 *ChangeEventCreateResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *ChangeEventCreateResponseAttributes `json:"attributes,omitempty"` + Type *string `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{"attributes", "type"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes != nil && all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = all.Attributes + 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_change_event_create_response_attributes.go b/api/datadogV2/model_change_event_create_response_attributes.go new file mode 100644 index 00000000000..fc41d10d20f --- /dev/null +++ b/api/datadogV2/model_change_event_create_response_attributes.go @@ -0,0 +1,111 @@ +// 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" +) + +// ChangeEventCreateResponseAttributes The definition of `ChangeEventCreateResponseAttributes` object. +type ChangeEventCreateResponseAttributes struct { + // The definition of `ChangeEventCreateResponseAttributesAttributes` object. + Attributes *ChangeEventCreateResponseAttributesAttributes `json:"attributes,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:"-"` +} + +// NewChangeEventCreateResponseAttributes instantiates a new ChangeEventCreateResponseAttributes 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 NewChangeEventCreateResponseAttributes() *ChangeEventCreateResponseAttributes { + this := ChangeEventCreateResponseAttributes{} + return &this +} + +// NewChangeEventCreateResponseAttributesWithDefaults instantiates a new ChangeEventCreateResponseAttributes 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 NewChangeEventCreateResponseAttributesWithDefaults() *ChangeEventCreateResponseAttributes { + this := ChangeEventCreateResponseAttributes{} + return &this +} + +// GetAttributes returns the Attributes field value if set, zero value otherwise. +func (o *ChangeEventCreateResponseAttributes) GetAttributes() ChangeEventCreateResponseAttributesAttributes { + if o == nil || o.Attributes == nil { + var ret ChangeEventCreateResponseAttributesAttributes + return ret + } + return *o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCreateResponseAttributes) GetAttributesOk() (*ChangeEventCreateResponseAttributesAttributes, bool) { + if o == nil || o.Attributes == nil { + return nil, false + } + return o.Attributes, true +} + +// HasAttributes returns a boolean if a field has been set. +func (o *ChangeEventCreateResponseAttributes) HasAttributes() bool { + return o != nil && o.Attributes != nil +} + +// SetAttributes gets a reference to the given ChangeEventCreateResponseAttributesAttributes and assigns it to the Attributes field. +func (o *ChangeEventCreateResponseAttributes) SetAttributes(v ChangeEventCreateResponseAttributesAttributes) { + o.Attributes = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEventCreateResponseAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Attributes != nil { + toSerialize["attributes"] = o.Attributes + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *ChangeEventCreateResponseAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *ChangeEventCreateResponseAttributesAttributes `json:"attributes,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{"attributes"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes != nil && all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = all.Attributes + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_change_event_create_response_attributes_attributes.go b/api/datadogV2/model_change_event_create_response_attributes_attributes.go new file mode 100644 index 00000000000..b82137d8948 --- /dev/null +++ b/api/datadogV2/model_change_event_create_response_attributes_attributes.go @@ -0,0 +1,111 @@ +// 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" +) + +// ChangeEventCreateResponseAttributesAttributes The definition of `ChangeEventCreateResponseAttributesAttributes` object. +type ChangeEventCreateResponseAttributesAttributes struct { + // The definition of `ChangeEventCreateResponseAttributesAttributesEvt` object. + Evt *ChangeEventCreateResponseAttributesAttributesEvt `json:"evt,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:"-"` +} + +// NewChangeEventCreateResponseAttributesAttributes instantiates a new ChangeEventCreateResponseAttributesAttributes 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 NewChangeEventCreateResponseAttributesAttributes() *ChangeEventCreateResponseAttributesAttributes { + this := ChangeEventCreateResponseAttributesAttributes{} + return &this +} + +// NewChangeEventCreateResponseAttributesAttributesWithDefaults instantiates a new ChangeEventCreateResponseAttributesAttributes 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 NewChangeEventCreateResponseAttributesAttributesWithDefaults() *ChangeEventCreateResponseAttributesAttributes { + this := ChangeEventCreateResponseAttributesAttributes{} + return &this +} + +// GetEvt returns the Evt field value if set, zero value otherwise. +func (o *ChangeEventCreateResponseAttributesAttributes) GetEvt() ChangeEventCreateResponseAttributesAttributesEvt { + if o == nil || o.Evt == nil { + var ret ChangeEventCreateResponseAttributesAttributesEvt + return ret + } + return *o.Evt +} + +// GetEvtOk returns a tuple with the Evt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCreateResponseAttributesAttributes) GetEvtOk() (*ChangeEventCreateResponseAttributesAttributesEvt, bool) { + if o == nil || o.Evt == nil { + return nil, false + } + return o.Evt, true +} + +// HasEvt returns a boolean if a field has been set. +func (o *ChangeEventCreateResponseAttributesAttributes) HasEvt() bool { + return o != nil && o.Evt != nil +} + +// SetEvt gets a reference to the given ChangeEventCreateResponseAttributesAttributesEvt and assigns it to the Evt field. +func (o *ChangeEventCreateResponseAttributesAttributes) SetEvt(v ChangeEventCreateResponseAttributesAttributesEvt) { + o.Evt = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEventCreateResponseAttributesAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Evt != nil { + toSerialize["evt"] = o.Evt + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *ChangeEventCreateResponseAttributesAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Evt *ChangeEventCreateResponseAttributesAttributesEvt `json:"evt,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{"evt"}) + } else { + return err + } + + hasInvalidField := false + if all.Evt != nil && all.Evt.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Evt = all.Evt + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_change_event_create_response_attributes_attributes_evt.go b/api/datadogV2/model_change_event_create_response_attributes_attributes_evt.go new file mode 100644 index 00000000000..a83e48d1897 --- /dev/null +++ b/api/datadogV2/model_change_event_create_response_attributes_attributes_evt.go @@ -0,0 +1,102 @@ +// 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" +) + +// ChangeEventCreateResponseAttributesAttributesEvt The definition of `ChangeEventCreateResponseAttributesAttributesEvt` object. +type ChangeEventCreateResponseAttributesAttributesEvt struct { + // Event id + Id *string `json:"id,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:"-"` +} + +// NewChangeEventCreateResponseAttributesAttributesEvt instantiates a new ChangeEventCreateResponseAttributesAttributesEvt 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 NewChangeEventCreateResponseAttributesAttributesEvt() *ChangeEventCreateResponseAttributesAttributesEvt { + this := ChangeEventCreateResponseAttributesAttributesEvt{} + return &this +} + +// NewChangeEventCreateResponseAttributesAttributesEvtWithDefaults instantiates a new ChangeEventCreateResponseAttributesAttributesEvt 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 NewChangeEventCreateResponseAttributesAttributesEvtWithDefaults() *ChangeEventCreateResponseAttributesAttributesEvt { + this := ChangeEventCreateResponseAttributesAttributesEvt{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *ChangeEventCreateResponseAttributesAttributesEvt) GetId() string { + if o == nil || o.Id == nil { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCreateResponseAttributesAttributesEvt) GetIdOk() (*string, bool) { + if o == nil || o.Id == nil { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *ChangeEventCreateResponseAttributesAttributesEvt) HasId() bool { + return o != nil && o.Id != nil +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *ChangeEventCreateResponseAttributesAttributesEvt) SetId(v string) { + o.Id = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEventCreateResponseAttributesAttributesEvt) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Id != nil { + toSerialize["id"] = o.Id + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *ChangeEventCreateResponseAttributesAttributesEvt) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Id *string `json:"id,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{"id"}) + } else { + return err + } + o.Id = all.Id + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_change_event_custom_attributes.go b/api/datadogV2/model_change_event_custom_attributes.go new file mode 100644 index 00000000000..b870615c03c --- /dev/null +++ b/api/datadogV2/model_change_event_custom_attributes.go @@ -0,0 +1,289 @@ +// 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" +) + +// ChangeEventCustomAttributes Object representing custom event attributes. +type ChangeEventCustomAttributes struct { + // Object representing the entity which made the change. Optional field but if provided should include `type` and `name`. + Author *ChangeEventCustomAttributesAuthor `json:"author,omitempty"` + // Free form object with any related information of the `change` event. + ChangeMetadata map[string]interface{} `json:"change_metadata,omitempty"` + // Object representing a uniquely identified resource. Only the resource type `feature_flag` is supported. + ChangedResource ChangeEventCustomAttributesChangedResource `json:"changed_resource"` + // A list of resources impacted by this change. At least one resource is required. Only resources + // of type `service` are supported. + ImpactedResources []ChangeEventCustomAttributesImpactedResourcesItems `json:"impacted_resources,omitempty"` + // Free form object to track new value of the changed resource. + NewValue map[string]interface{} `json:"new_value,omitempty"` + // Free form object to track previous value of the changed resource. + PrevValue map[string]interface{} `json:"prev_value,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:"-"` +} + +// NewChangeEventCustomAttributes instantiates a new ChangeEventCustomAttributes 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 NewChangeEventCustomAttributes(changedResource ChangeEventCustomAttributesChangedResource) *ChangeEventCustomAttributes { + this := ChangeEventCustomAttributes{} + this.ChangedResource = changedResource + return &this +} + +// NewChangeEventCustomAttributesWithDefaults instantiates a new ChangeEventCustomAttributes 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 NewChangeEventCustomAttributesWithDefaults() *ChangeEventCustomAttributes { + this := ChangeEventCustomAttributes{} + return &this +} + +// GetAuthor returns the Author field value if set, zero value otherwise. +func (o *ChangeEventCustomAttributes) GetAuthor() ChangeEventCustomAttributesAuthor { + if o == nil || o.Author == nil { + var ret ChangeEventCustomAttributesAuthor + return ret + } + return *o.Author +} + +// GetAuthorOk returns a tuple with the Author field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributes) GetAuthorOk() (*ChangeEventCustomAttributesAuthor, bool) { + if o == nil || o.Author == nil { + return nil, false + } + return o.Author, true +} + +// HasAuthor returns a boolean if a field has been set. +func (o *ChangeEventCustomAttributes) HasAuthor() bool { + return o != nil && o.Author != nil +} + +// SetAuthor gets a reference to the given ChangeEventCustomAttributesAuthor and assigns it to the Author field. +func (o *ChangeEventCustomAttributes) SetAuthor(v ChangeEventCustomAttributesAuthor) { + o.Author = &v +} + +// GetChangeMetadata returns the ChangeMetadata field value if set, zero value otherwise. +func (o *ChangeEventCustomAttributes) GetChangeMetadata() map[string]interface{} { + if o == nil || o.ChangeMetadata == nil { + var ret map[string]interface{} + return ret + } + return o.ChangeMetadata +} + +// GetChangeMetadataOk returns a tuple with the ChangeMetadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributes) GetChangeMetadataOk() (*map[string]interface{}, bool) { + if o == nil || o.ChangeMetadata == nil { + return nil, false + } + return &o.ChangeMetadata, true +} + +// HasChangeMetadata returns a boolean if a field has been set. +func (o *ChangeEventCustomAttributes) HasChangeMetadata() bool { + return o != nil && o.ChangeMetadata != nil +} + +// SetChangeMetadata gets a reference to the given map[string]interface{} and assigns it to the ChangeMetadata field. +func (o *ChangeEventCustomAttributes) SetChangeMetadata(v map[string]interface{}) { + o.ChangeMetadata = v +} + +// GetChangedResource returns the ChangedResource field value. +func (o *ChangeEventCustomAttributes) GetChangedResource() ChangeEventCustomAttributesChangedResource { + if o == nil { + var ret ChangeEventCustomAttributesChangedResource + return ret + } + return o.ChangedResource +} + +// GetChangedResourceOk returns a tuple with the ChangedResource field value +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributes) GetChangedResourceOk() (*ChangeEventCustomAttributesChangedResource, bool) { + if o == nil { + return nil, false + } + return &o.ChangedResource, true +} + +// SetChangedResource sets field value. +func (o *ChangeEventCustomAttributes) SetChangedResource(v ChangeEventCustomAttributesChangedResource) { + o.ChangedResource = v +} + +// GetImpactedResources returns the ImpactedResources field value if set, zero value otherwise. +func (o *ChangeEventCustomAttributes) GetImpactedResources() []ChangeEventCustomAttributesImpactedResourcesItems { + if o == nil || o.ImpactedResources == nil { + var ret []ChangeEventCustomAttributesImpactedResourcesItems + return ret + } + return o.ImpactedResources +} + +// GetImpactedResourcesOk returns a tuple with the ImpactedResources field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributes) GetImpactedResourcesOk() (*[]ChangeEventCustomAttributesImpactedResourcesItems, bool) { + if o == nil || o.ImpactedResources == nil { + return nil, false + } + return &o.ImpactedResources, true +} + +// HasImpactedResources returns a boolean if a field has been set. +func (o *ChangeEventCustomAttributes) HasImpactedResources() bool { + return o != nil && o.ImpactedResources != nil +} + +// SetImpactedResources gets a reference to the given []ChangeEventCustomAttributesImpactedResourcesItems and assigns it to the ImpactedResources field. +func (o *ChangeEventCustomAttributes) SetImpactedResources(v []ChangeEventCustomAttributesImpactedResourcesItems) { + o.ImpactedResources = v +} + +// GetNewValue returns the NewValue field value if set, zero value otherwise. +func (o *ChangeEventCustomAttributes) GetNewValue() map[string]interface{} { + if o == nil || o.NewValue == nil { + var ret map[string]interface{} + return ret + } + return o.NewValue +} + +// GetNewValueOk returns a tuple with the NewValue field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributes) GetNewValueOk() (*map[string]interface{}, bool) { + if o == nil || o.NewValue == nil { + return nil, false + } + return &o.NewValue, true +} + +// HasNewValue returns a boolean if a field has been set. +func (o *ChangeEventCustomAttributes) HasNewValue() bool { + return o != nil && o.NewValue != nil +} + +// SetNewValue gets a reference to the given map[string]interface{} and assigns it to the NewValue field. +func (o *ChangeEventCustomAttributes) SetNewValue(v map[string]interface{}) { + o.NewValue = v +} + +// GetPrevValue returns the PrevValue field value if set, zero value otherwise. +func (o *ChangeEventCustomAttributes) GetPrevValue() map[string]interface{} { + if o == nil || o.PrevValue == nil { + var ret map[string]interface{} + return ret + } + return o.PrevValue +} + +// GetPrevValueOk returns a tuple with the PrevValue field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributes) GetPrevValueOk() (*map[string]interface{}, bool) { + if o == nil || o.PrevValue == nil { + return nil, false + } + return &o.PrevValue, true +} + +// HasPrevValue returns a boolean if a field has been set. +func (o *ChangeEventCustomAttributes) HasPrevValue() bool { + return o != nil && o.PrevValue != nil +} + +// SetPrevValue gets a reference to the given map[string]interface{} and assigns it to the PrevValue field. +func (o *ChangeEventCustomAttributes) SetPrevValue(v map[string]interface{}) { + o.PrevValue = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEventCustomAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Author != nil { + toSerialize["author"] = o.Author + } + if o.ChangeMetadata != nil { + toSerialize["change_metadata"] = o.ChangeMetadata + } + toSerialize["changed_resource"] = o.ChangedResource + if o.ImpactedResources != nil { + toSerialize["impacted_resources"] = o.ImpactedResources + } + if o.NewValue != nil { + toSerialize["new_value"] = o.NewValue + } + if o.PrevValue != nil { + toSerialize["prev_value"] = o.PrevValue + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *ChangeEventCustomAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Author *ChangeEventCustomAttributesAuthor `json:"author,omitempty"` + ChangeMetadata map[string]interface{} `json:"change_metadata,omitempty"` + ChangedResource *ChangeEventCustomAttributesChangedResource `json:"changed_resource"` + ImpactedResources []ChangeEventCustomAttributesImpactedResourcesItems `json:"impacted_resources,omitempty"` + NewValue map[string]interface{} `json:"new_value,omitempty"` + PrevValue map[string]interface{} `json:"prev_value,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.ChangedResource == nil { + return fmt.Errorf("required field changed_resource missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"author", "change_metadata", "changed_resource", "impacted_resources", "new_value", "prev_value"}) + } else { + return err + } + + hasInvalidField := false + if all.Author != nil && all.Author.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Author = all.Author + o.ChangeMetadata = all.ChangeMetadata + if all.ChangedResource.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.ChangedResource = *all.ChangedResource + o.ImpactedResources = all.ImpactedResources + o.NewValue = all.NewValue + o.PrevValue = all.PrevValue + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_change_event_custom_attributes_author.go b/api/datadogV2/model_change_event_custom_attributes_author.go new file mode 100644 index 00000000000..d9d235e8b4b --- /dev/null +++ b/api/datadogV2/model_change_event_custom_attributes_author.go @@ -0,0 +1,143 @@ +// 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" +) + +// ChangeEventCustomAttributesAuthor Object representing the entity which made the change. Optional field but if provided should include `type` and `name`. +type ChangeEventCustomAttributesAuthor struct { + // Author's name. Limited to 128 characters. + Name string `json:"name"` + // Author's type. + Type ChangeEventCustomAttributesAuthorType `json:"type"` + // 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:"-"` +} + +// NewChangeEventCustomAttributesAuthor instantiates a new ChangeEventCustomAttributesAuthor 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 NewChangeEventCustomAttributesAuthor(name string, typeVar ChangeEventCustomAttributesAuthorType) *ChangeEventCustomAttributesAuthor { + this := ChangeEventCustomAttributesAuthor{} + this.Name = name + this.Type = typeVar + return &this +} + +// NewChangeEventCustomAttributesAuthorWithDefaults instantiates a new ChangeEventCustomAttributesAuthor 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 NewChangeEventCustomAttributesAuthorWithDefaults() *ChangeEventCustomAttributesAuthor { + this := ChangeEventCustomAttributesAuthor{} + return &this +} + +// GetName returns the Name field value. +func (o *ChangeEventCustomAttributesAuthor) GetName() string { + if o == nil { + var ret string + return ret + } + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributesAuthor) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value. +func (o *ChangeEventCustomAttributesAuthor) SetName(v string) { + o.Name = v +} + +// GetType returns the Type field value. +func (o *ChangeEventCustomAttributesAuthor) GetType() ChangeEventCustomAttributesAuthorType { + if o == nil { + var ret ChangeEventCustomAttributesAuthorType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributesAuthor) GetTypeOk() (*ChangeEventCustomAttributesAuthorType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *ChangeEventCustomAttributesAuthor) SetType(v ChangeEventCustomAttributesAuthorType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEventCustomAttributesAuthor) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["name"] = o.Name + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *ChangeEventCustomAttributesAuthor) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Name *string `json:"name"` + Type *ChangeEventCustomAttributesAuthorType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Name == nil { + return fmt.Errorf("required field name missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"name", "type"}) + } else { + return err + } + + hasInvalidField := false + o.Name = *all.Name + if !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_change_event_custom_attributes_author_type.go b/api/datadogV2/model_change_event_custom_attributes_author_type.go new file mode 100644 index 00000000000..e0a7a9a138f --- /dev/null +++ b/api/datadogV2/model_change_event_custom_attributes_author_type.go @@ -0,0 +1,66 @@ +// 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" +) + +// ChangeEventCustomAttributesAuthorType Author's type. +type ChangeEventCustomAttributesAuthorType string + +// List of ChangeEventCustomAttributesAuthorType. +const ( + CHANGEEVENTCUSTOMATTRIBUTESAUTHORTYPE_USER ChangeEventCustomAttributesAuthorType = "user" + CHANGEEVENTCUSTOMATTRIBUTESAUTHORTYPE_SYSTEM ChangeEventCustomAttributesAuthorType = "system" +) + +var allowedChangeEventCustomAttributesAuthorTypeEnumValues = []ChangeEventCustomAttributesAuthorType{ + CHANGEEVENTCUSTOMATTRIBUTESAUTHORTYPE_USER, + CHANGEEVENTCUSTOMATTRIBUTESAUTHORTYPE_SYSTEM, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *ChangeEventCustomAttributesAuthorType) GetAllowedValues() []ChangeEventCustomAttributesAuthorType { + return allowedChangeEventCustomAttributesAuthorTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *ChangeEventCustomAttributesAuthorType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = ChangeEventCustomAttributesAuthorType(value) + return nil +} + +// NewChangeEventCustomAttributesAuthorTypeFromValue returns a pointer to a valid ChangeEventCustomAttributesAuthorType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewChangeEventCustomAttributesAuthorTypeFromValue(v string) (*ChangeEventCustomAttributesAuthorType, error) { + ev := ChangeEventCustomAttributesAuthorType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for ChangeEventCustomAttributesAuthorType: valid values are %v", v, allowedChangeEventCustomAttributesAuthorTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v ChangeEventCustomAttributesAuthorType) IsValid() bool { + for _, existing := range allowedChangeEventCustomAttributesAuthorTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to ChangeEventCustomAttributesAuthorType value. +func (v ChangeEventCustomAttributesAuthorType) Ptr() *ChangeEventCustomAttributesAuthorType { + return &v +} diff --git a/api/datadogV2/model_change_event_custom_attributes_changed_resource.go b/api/datadogV2/model_change_event_custom_attributes_changed_resource.go new file mode 100644 index 00000000000..1c4637c2e87 --- /dev/null +++ b/api/datadogV2/model_change_event_custom_attributes_changed_resource.go @@ -0,0 +1,143 @@ +// 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" +) + +// ChangeEventCustomAttributesChangedResource Object representing a uniquely identified resource. Only the resource type `feature_flag` is supported. +type ChangeEventCustomAttributesChangedResource struct { + // Resource's name. + Name string `json:"name"` + // Resource's type. + Type ChangeEventCustomAttributesChangedResourceType `json:"type"` + // 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:"-"` +} + +// NewChangeEventCustomAttributesChangedResource instantiates a new ChangeEventCustomAttributesChangedResource 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 NewChangeEventCustomAttributesChangedResource(name string, typeVar ChangeEventCustomAttributesChangedResourceType) *ChangeEventCustomAttributesChangedResource { + this := ChangeEventCustomAttributesChangedResource{} + this.Name = name + this.Type = typeVar + return &this +} + +// NewChangeEventCustomAttributesChangedResourceWithDefaults instantiates a new ChangeEventCustomAttributesChangedResource 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 NewChangeEventCustomAttributesChangedResourceWithDefaults() *ChangeEventCustomAttributesChangedResource { + this := ChangeEventCustomAttributesChangedResource{} + return &this +} + +// GetName returns the Name field value. +func (o *ChangeEventCustomAttributesChangedResource) GetName() string { + if o == nil { + var ret string + return ret + } + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributesChangedResource) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value. +func (o *ChangeEventCustomAttributesChangedResource) SetName(v string) { + o.Name = v +} + +// GetType returns the Type field value. +func (o *ChangeEventCustomAttributesChangedResource) GetType() ChangeEventCustomAttributesChangedResourceType { + if o == nil { + var ret ChangeEventCustomAttributesChangedResourceType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributesChangedResource) GetTypeOk() (*ChangeEventCustomAttributesChangedResourceType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *ChangeEventCustomAttributesChangedResource) SetType(v ChangeEventCustomAttributesChangedResourceType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEventCustomAttributesChangedResource) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["name"] = o.Name + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *ChangeEventCustomAttributesChangedResource) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Name *string `json:"name"` + Type *ChangeEventCustomAttributesChangedResourceType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Name == nil { + return fmt.Errorf("required field name missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"name", "type"}) + } else { + return err + } + + hasInvalidField := false + o.Name = *all.Name + if !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_change_event_custom_attributes_changed_resource_type.go b/api/datadogV2/model_change_event_custom_attributes_changed_resource_type.go new file mode 100644 index 00000000000..c462649a980 --- /dev/null +++ b/api/datadogV2/model_change_event_custom_attributes_changed_resource_type.go @@ -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. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// ChangeEventCustomAttributesChangedResourceType Resource's type. +type ChangeEventCustomAttributesChangedResourceType string + +// List of ChangeEventCustomAttributesChangedResourceType. +const ( + CHANGEEVENTCUSTOMATTRIBUTESCHANGEDRESOURCETYPE_FEATURE_FLAG ChangeEventCustomAttributesChangedResourceType = "feature_flag" +) + +var allowedChangeEventCustomAttributesChangedResourceTypeEnumValues = []ChangeEventCustomAttributesChangedResourceType{ + CHANGEEVENTCUSTOMATTRIBUTESCHANGEDRESOURCETYPE_FEATURE_FLAG, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *ChangeEventCustomAttributesChangedResourceType) GetAllowedValues() []ChangeEventCustomAttributesChangedResourceType { + return allowedChangeEventCustomAttributesChangedResourceTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *ChangeEventCustomAttributesChangedResourceType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = ChangeEventCustomAttributesChangedResourceType(value) + return nil +} + +// NewChangeEventCustomAttributesChangedResourceTypeFromValue returns a pointer to a valid ChangeEventCustomAttributesChangedResourceType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewChangeEventCustomAttributesChangedResourceTypeFromValue(v string) (*ChangeEventCustomAttributesChangedResourceType, error) { + ev := ChangeEventCustomAttributesChangedResourceType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for ChangeEventCustomAttributesChangedResourceType: valid values are %v", v, allowedChangeEventCustomAttributesChangedResourceTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v ChangeEventCustomAttributesChangedResourceType) IsValid() bool { + for _, existing := range allowedChangeEventCustomAttributesChangedResourceTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to ChangeEventCustomAttributesChangedResourceType value. +func (v ChangeEventCustomAttributesChangedResourceType) Ptr() *ChangeEventCustomAttributesChangedResourceType { + return &v +} diff --git a/api/datadogV2/model_change_event_custom_attributes_impacted_resources_items.go b/api/datadogV2/model_change_event_custom_attributes_impacted_resources_items.go new file mode 100644 index 00000000000..6ce74a25468 --- /dev/null +++ b/api/datadogV2/model_change_event_custom_attributes_impacted_resources_items.go @@ -0,0 +1,143 @@ +// 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" +) + +// ChangeEventCustomAttributesImpactedResourcesItems Object representing a uniquely identified resource. Only the resource type `service` is supported. +type ChangeEventCustomAttributesImpactedResourcesItems struct { + // Resource's name. + Name string `json:"name"` + // Resource's type. + Type ChangeEventCustomAttributesImpactedResourcesItemsType `json:"type"` + // 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:"-"` +} + +// NewChangeEventCustomAttributesImpactedResourcesItems instantiates a new ChangeEventCustomAttributesImpactedResourcesItems 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 NewChangeEventCustomAttributesImpactedResourcesItems(name string, typeVar ChangeEventCustomAttributesImpactedResourcesItemsType) *ChangeEventCustomAttributesImpactedResourcesItems { + this := ChangeEventCustomAttributesImpactedResourcesItems{} + this.Name = name + this.Type = typeVar + return &this +} + +// NewChangeEventCustomAttributesImpactedResourcesItemsWithDefaults instantiates a new ChangeEventCustomAttributesImpactedResourcesItems 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 NewChangeEventCustomAttributesImpactedResourcesItemsWithDefaults() *ChangeEventCustomAttributesImpactedResourcesItems { + this := ChangeEventCustomAttributesImpactedResourcesItems{} + return &this +} + +// GetName returns the Name field value. +func (o *ChangeEventCustomAttributesImpactedResourcesItems) GetName() string { + if o == nil { + var ret string + return ret + } + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributesImpactedResourcesItems) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value. +func (o *ChangeEventCustomAttributesImpactedResourcesItems) SetName(v string) { + o.Name = v +} + +// GetType returns the Type field value. +func (o *ChangeEventCustomAttributesImpactedResourcesItems) GetType() ChangeEventCustomAttributesImpactedResourcesItemsType { + if o == nil { + var ret ChangeEventCustomAttributesImpactedResourcesItemsType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *ChangeEventCustomAttributesImpactedResourcesItems) GetTypeOk() (*ChangeEventCustomAttributesImpactedResourcesItemsType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *ChangeEventCustomAttributesImpactedResourcesItems) SetType(v ChangeEventCustomAttributesImpactedResourcesItemsType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ChangeEventCustomAttributesImpactedResourcesItems) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["name"] = o.Name + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *ChangeEventCustomAttributesImpactedResourcesItems) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Name *string `json:"name"` + Type *ChangeEventCustomAttributesImpactedResourcesItemsType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Name == nil { + return fmt.Errorf("required field name missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"name", "type"}) + } else { + return err + } + + hasInvalidField := false + o.Name = *all.Name + if !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_change_event_custom_attributes_impacted_resources_items_type.go b/api/datadogV2/model_change_event_custom_attributes_impacted_resources_items_type.go new file mode 100644 index 00000000000..69dfc09930c --- /dev/null +++ b/api/datadogV2/model_change_event_custom_attributes_impacted_resources_items_type.go @@ -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. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// ChangeEventCustomAttributesImpactedResourcesItemsType Resource's type. +type ChangeEventCustomAttributesImpactedResourcesItemsType string + +// List of ChangeEventCustomAttributesImpactedResourcesItemsType. +const ( + CHANGEEVENTCUSTOMATTRIBUTESIMPACTEDRESOURCESITEMSTYPE_SERVICE ChangeEventCustomAttributesImpactedResourcesItemsType = "service" +) + +var allowedChangeEventCustomAttributesImpactedResourcesItemsTypeEnumValues = []ChangeEventCustomAttributesImpactedResourcesItemsType{ + CHANGEEVENTCUSTOMATTRIBUTESIMPACTEDRESOURCESITEMSTYPE_SERVICE, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *ChangeEventCustomAttributesImpactedResourcesItemsType) GetAllowedValues() []ChangeEventCustomAttributesImpactedResourcesItemsType { + return allowedChangeEventCustomAttributesImpactedResourcesItemsTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *ChangeEventCustomAttributesImpactedResourcesItemsType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = ChangeEventCustomAttributesImpactedResourcesItemsType(value) + return nil +} + +// NewChangeEventCustomAttributesImpactedResourcesItemsTypeFromValue returns a pointer to a valid ChangeEventCustomAttributesImpactedResourcesItemsType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewChangeEventCustomAttributesImpactedResourcesItemsTypeFromValue(v string) (*ChangeEventCustomAttributesImpactedResourcesItemsType, error) { + ev := ChangeEventCustomAttributesImpactedResourcesItemsType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for ChangeEventCustomAttributesImpactedResourcesItemsType: valid values are %v", v, allowedChangeEventCustomAttributesImpactedResourcesItemsTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v ChangeEventCustomAttributesImpactedResourcesItemsType) IsValid() bool { + for _, existing := range allowedChangeEventCustomAttributesImpactedResourcesItemsTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to ChangeEventCustomAttributesImpactedResourcesItemsType value. +func (v ChangeEventCustomAttributesImpactedResourcesItemsType) Ptr() *ChangeEventCustomAttributesImpactedResourcesItemsType { + return &v +} diff --git a/examples/v2/events/CreateEvent.go b/examples/v2/events/CreateEvent.go new file mode 100644 index 00000000000..0a94bb65934 --- /dev/null +++ b/examples/v2/events/CreateEvent.go @@ -0,0 +1,70 @@ +// Post a change event 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() { + body := datadogV2.ChangeEventCreateRequest{ + Attributes: &datadogV2.ChangeEvent{ + Attributes: datadogV2.ChangeEventCustomAttributes{ + Author: &datadogV2.ChangeEventCustomAttributesAuthor{ + Name: "", + Type: datadogV2.CHANGEEVENTCUSTOMATTRIBUTESAUTHORTYPE_USER, + }, + ChangeMetadata: map[string]interface{}{ + "resource_link": "/feature/fallback_payments_test", + "user": "{'email': 'dd_user_email', 'name': 'dd_user'}", + }, + ChangedResource: datadogV2.ChangeEventCustomAttributesChangedResource{ + Name: "fallback_payments_test", + Type: datadogV2.CHANGEEVENTCUSTOMATTRIBUTESCHANGEDRESOURCETYPE_FEATURE_FLAG, + }, + ImpactedResources: []datadogV2.ChangeEventCustomAttributesImpactedResourcesItems{ + { + Name: "payments_api", + Type: datadogV2.CHANGEEVENTCUSTOMATTRIBUTESIMPACTEDRESOURCESITEMSTYPE_SERVICE, + }, + }, + NewValue: map[string]interface{}{ + "enabled": "True", + "percentage": "50%", + "rule": "{'datacenter': 'us1.prod'}", + }, + PrevValue: map[string]interface{}{ + "enabled": "True", + "percentage": "10%", + "rule": "{'datacenter': 'us1.prod'}", + }, + }, + Category: datadogV2.CHANGEEVENTCATEGORY_CHANGE, + Message: datadog.PtrString("payment_processed feature flag has been enabled"), + Tags: []string{ + "environment:test", + }, + Title: "payment_processed feature flag updated", + }, + Type: datadogV2.CHANGEEVENTCREATEREQUESTTYPE_EVENT.Ptr(), + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewEventsApi(apiClient) + resp, r, err := api.CreateEvent(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `EventsApi.CreateEvent`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `EventsApi.CreateEvent`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/features/v1/given.json b/tests/scenarios/features/v1/given.json index 4b7ae56d5b4..c4f7aa6976d 100644 --- a/tests/scenarios/features/v1/given.json +++ b/tests/scenarios/features/v1/given.json @@ -166,7 +166,7 @@ "parameters": [ { "name": "body", - "value": "{\n \"name\": \"{{ unique }}\",\n \"type\": \"log alert\",\n \"query\": \"logs(\\\"service:foo AND type:error\\\").index(\\\"main\\\").rollup(\\\"count\\\").by(\\\"source\\\").last(\\\"5m\\\") > 2\",\n \"message\": \"some message Notify: @hipchat-channel\",\n \"tags\": [\"test:{{ unique_lower_alnum }}\", \"env:ci\"],\n \"priority\": 3,\n \"options\": {\n \"enable_logs_sample\": true,\n \"escalation_message\": \"the situation has escalated\",\n \"evaluation_delay\": 700,\n \"groupby_simple_monitor\": true,\n \"include_tags\": true,\n \"locked\": false,\n \"new_host_delay\": 600,\n \"no_data_timeframe\": null,\n \"notify_audit\": false,\n \"notify_no_data\": false,\n \"on_missing_data\": \"show_and_notify_no_data\",\n \"notification_preset_name\": \"hide_handles\",\n \"renotify_interval\": 60,\n \"require_full_window\": true,\n \"timeout_h\": 24,\n \"thresholds\": { \"critical\": 2, \"warning\": 1 }\n }\n}\n" + "value": "{\n \"name\": \"{{ unique }}\",\n \"type\": \"log alert\",\n \"query\": \"logs(\\\"service:foo AND type:error\\\").index(\\\"main\\\").rollup(\\\"count\\\").by(\\\"source\\\").last(\\\"5m\\\") > 2\",\n \"message\": \"some message Notify: @hipchat-channel\",\n \"tags\": [\"test:{{ unique_lower_alnum }}\", \"env:ci\"],\n \"priority\": 3,\n \"options\": {\n \"enable_logs_sample\": true,\n \"escalation_message\": \"the situation has escalated\",\n \"evaluation_delay\": 700,\n \"include_tags\": true,\n \"locked\": false,\n \"new_host_delay\": 600,\n \"no_data_timeframe\": null,\n \"notify_audit\": false,\n \"notify_no_data\": false,\n \"on_missing_data\": \"show_and_notify_no_data\",\n \"notification_preset_name\": \"hide_handles\",\n \"renotify_interval\": 60,\n \"require_full_window\": true,\n \"timeout_h\": 24,\n \"thresholds\": { \"critical\": 2, \"warning\": 1 }\n }\n}\n" } ], "step": "there is a valid \"monitor\" in the system", diff --git a/tests/scenarios/features/v2/events.feature b/tests/scenarios/features/v2/events.feature index 9a1c79072d1..59156f314d6 100644 --- a/tests/scenarios/features/v2/events.feature +++ b/tests/scenarios/features/v2/events.feature @@ -7,24 +7,26 @@ Feature: Events Background: Given a valid "apiKeyAuth" key in the system - And a valid "appKeyAuth" key in the system And an instance of "Events" API @generated @skip @team:DataDog/event-management Scenario: Get a list of events returns "Bad Request" response - Given new "ListEvents" request + Given a valid "appKeyAuth" key in the system + And new "ListEvents" request When the request is sent Then the response status is 400 Bad Request @skip-validation @team:DataDog/event-management Scenario: Get a list of events returns "OK" response - Given new "ListEvents" request + Given a valid "appKeyAuth" key in the system + And new "ListEvents" request When the request is sent Then the response status is 200 OK @replay-only @skip-validation @team:DataDog/event-management @with-pagination Scenario: Get a list of events returns "OK" response with pagination - Given new "ListEvents" request + Given a valid "appKeyAuth" key in the system + And new "ListEvents" request And request contains "filter[from]" parameter with value "now-15m" And request contains "filter[to]" parameter with value "now" And request contains "page[limit]" parameter with value 2 @@ -34,7 +36,8 @@ Feature: Events @team:DataDog/event-management Scenario: Get a quick list of events returns "OK" response - Given new "ListEvents" request + Given a valid "appKeyAuth" key in the system + And new "ListEvents" request And request contains "filter[query]" parameter with value "datadog-agent" And request contains "filter[from]" parameter with value "2020-09-17T11:48:36+01:00" And request contains "filter[to]" parameter with value "2020-09-17T12:48:36+01:00" @@ -43,16 +46,32 @@ Feature: Events Then the response status is 200 OK And the response "data" has length 0 + @generated @skip @team:DataDog/event-management + Scenario: Post a change event returns "Bad request" response + Given new "CreateEvent" request + And body with value {"attributes": {"attributes": {"author": {"name": "", "type": "user"}, "change_metadata": {"resource_link": "/feature/fallback_payments_test", "user": {"email": "dd_user_email", "name": "dd_user"}}, "changed_resource": {"name": "fallback_payments_test", "type": "feature_flag"}, "impacted_resources": [{"name": "payments_api", "type": "service"}], "new_value": {"enabled": true, "percentage": "50%", "rule": {"datacenter": "us1.prod"}}, "prev_value": {"enabled": true, "percentage": "10%", "rule": {"datacenter": "us1.prod"}}}, "category": "change", "message": "payment_processed feature flag has been enabled", "tags": ["environment:test"], "title": "payment_processed feature flag updated"}, "type": "event"} + When the request is sent + Then the response status is 400 Bad request + + @generated @skip @team:DataDog/event-management + Scenario: Post a change event returns "OK" response + Given new "CreateEvent" request + And body with value {"attributes": {"attributes": {"author": {"name": "", "type": "user"}, "change_metadata": {"resource_link": "/feature/fallback_payments_test", "user": {"email": "dd_user_email", "name": "dd_user"}}, "changed_resource": {"name": "fallback_payments_test", "type": "feature_flag"}, "impacted_resources": [{"name": "payments_api", "type": "service"}], "new_value": {"enabled": true, "percentage": "50%", "rule": {"datacenter": "us1.prod"}}, "prev_value": {"enabled": true, "percentage": "10%", "rule": {"datacenter": "us1.prod"}}}, "category": "change", "message": "payment_processed feature flag has been enabled", "tags": ["environment:test"], "title": "payment_processed feature flag updated"}, "type": "event"} + When the request is sent + Then the response status is 200 OK + @team:DataDog/event-management Scenario: Search events returns "Bad Request" response - Given new "SearchEvents" request + Given a valid "appKeyAuth" key in the system + And new "SearchEvents" request And body with value {"filter": {"from": "now-15m", "query": "service:web* AND @http.status_code:[200 TO 299]", "to": "now"}, "options": {"timezone": "GMT"}, "page": {"cursor": "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", "limit": 25}, "sort": "timestamp"} When the request is sent Then the response status is 400 Bad Request @team:DataDog/event-management Scenario: Search events returns "OK" response - Given new "SearchEvents" request + Given a valid "appKeyAuth" key in the system + And new "SearchEvents" request And body with value {"filter": {"query": "datadog-agent", "from": "2020-09-17T11:48:36+01:00", "to": "2020-09-17T12:48:36+01:00"}, "sort": "timestamp", "page": {"limit": 5}} When the request is sent Then the response status is 200 OK @@ -60,7 +79,8 @@ Feature: Events @replay-only @skip-validation @team:DataDog/event-management @with-pagination Scenario: Search events returns "OK" response with pagination - Given new "SearchEvents" request + Given a valid "appKeyAuth" key in the system + And new "SearchEvents" request And body with value {"filter": {"from": "now-15m", "to": "now"}, "options": {"timezone": "GMT"}, "page": {"limit": 2}, "sort": "timestamp"} When the request with pagination is sent Then the response status is 200 OK diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 62da7c99ef9..a1592e79b71 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -602,6 +602,12 @@ "type": "safe" } }, + "CreateEvent": { + "tag": "Events", + "undo": { + "type": "unsafe" + } + }, "SearchEvents": { "tag": "Events", "undo": {