diff --git a/.apigentools-info b/.apigentools-info index 63e25dc3828..cc61b8c87e7 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-24 20:04:20.108446", - "spec_repo_commit": "aaacb8db" + "regenerated": "2024-10-25 15:40:14.231863", + "spec_repo_commit": "ba295a2c" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-24 20:04:20.126796", - "spec_repo_commit": "aaacb8db" + "regenerated": "2024-10-25 15:40:14.250594", + "spec_repo_commit": "ba295a2c" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index b4665794e53..bfd3029e410 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -2165,6 +2165,73 @@ components: - storage_account - storage_container type: object + BillingDimensionsMappingBody: + description: Billing dimensions mapping data. + items: + $ref: '#/components/schemas/BillingDimensionsMappingBodyItem' + type: array + BillingDimensionsMappingBodyItem: + description: The mapping data for each billing dimension. + properties: + attributes: + $ref: '#/components/schemas/BillingDimensionsMappingBodyItemAttributes' + id: + description: ID of the billing dimension. + type: string + type: + $ref: '#/components/schemas/ActiveBillingDimensionsType' + type: object + BillingDimensionsMappingBodyItemAttributes: + description: Mapping of billing dimensions to endpoint keys. + properties: + endpoints: + description: List of supported endpoints with their keys mapped to the billing_dimension. + items: + $ref: '#/components/schemas/BillingDimensionsMappingBodyItemAttributesEndpointsItems' + type: array + in_app_label: + description: Label used for the billing dimension in the Plan & Usage charts. + example: APM Hosts + type: string + timestamp: + description: 'Month in ISO-8601 format, UTC, precise to second: `[YYYY-MM-DDThh:mm:ss]`.' + format: date-time + type: string + type: object + BillingDimensionsMappingBodyItemAttributesEndpointsItems: + description: An endpoint's keys mapped to the billing_dimension. + properties: + id: + description: The URL for the endpoint. + example: api/v1/usage/billable-summary + type: string + keys: + description: The billing dimension. + example: + - apm_host_top99p + - apm_host_sum + items: + example: apm_host_top99p + type: string + type: array + status: + $ref: '#/components/schemas/BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus' + type: object + BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus: + description: Denotes whether or not mapping keys were available for this endpoint. + enum: + - OK + - NOT_FOUND + type: string + x-enum-varnames: + - OK + - NOT_FOUND + BillingDimensionsMappingResponse: + description: Billing dimensions mapping response. + properties: + data: + $ref: '#/components/schemas/BillingDimensionsMappingBody' + type: object BulkMuteFindingsRequest: description: The new bulk mute finding request. properties: @@ -40070,6 +40137,70 @@ paths: operator: OR permissions: - usage_read + /api/v2/usage/billing_dimension_mapping: + get: + description: 'Get a mapping of billing dimensions to the corresponding keys + for the supported usage metering public API endpoints. + + Mapping data is updated on a monthly cadence. + + + This endpoint is only accessible for [parent-level organizations](https://docs.datadoghq.com/account_management/multi_organization/).' + operationId: GetBillingDimensionMapping + parameters: + - description: Datetime in ISO-8601 format, UTC, for mappings beginning this + month. Defaults to the current month. + in: query + name: filter[month] + required: false + schema: + format: date-time + type: string + - description: String to specify whether to retrieve active billing dimension + mappings for the contract or all available mappings. Allowed views are `active` + and `all`. Defaults to `active`. + in: query + name: filter[view] + required: false + schema: + default: active + type: string + responses: + '200': + content: + application/json;datetime-format=rfc3339: + schema: + $ref: '#/components/schemas/BillingDimensionsMappingResponse' + description: OK + '400': + content: + application/json;datetime-format=rfc3339: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json;datetime-format=rfc3339: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Forbidden - User is not authorized + '429': + content: + application/json;datetime-format=rfc3339: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Too many requests + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - usage_read + summary: Get billing dimension mapping for usage endpoints + tags: + - Usage Metering + x-unstable: '**Note**: This endpoint is in Preview. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' /api/v2/usage/cost_by_org: get: deprecated: true diff --git a/api/datadog/configuration.go b/api/datadog/configuration.go index bf2c11cd763..6fb49ba2272 100644 --- a/api/datadog/configuration.go +++ b/api/datadog/configuration.go @@ -329,6 +329,7 @@ func NewConfiguration() *Configuration { "v2.ListAPIs": false, "v2.UpdateOpenAPI": false, "v2.GetActiveBillingDimensions": false, + "v2.GetBillingDimensionMapping": false, "v2.GetMonthlyCostAttribution": false, "v2.CreateDORADeployment": false, "v2.CreateDORAIncident": false, diff --git a/api/datadogV2/api_usage_metering.go b/api/datadogV2/api_usage_metering.go index bb68e01c1a9..58919d097e6 100644 --- a/api/datadogV2/api_usage_metering.go +++ b/api/datadogV2/api_usage_metering.go @@ -95,6 +95,124 @@ func (a *UsageMeteringApi) GetActiveBillingDimensions(ctx _context.Context) (Act return localVarReturnValue, localVarHTTPResponse, nil } +// GetBillingDimensionMappingOptionalParameters holds optional parameters for GetBillingDimensionMapping. +type GetBillingDimensionMappingOptionalParameters struct { + FilterMonth *time.Time + FilterView *string +} + +// NewGetBillingDimensionMappingOptionalParameters creates an empty struct for parameters. +func NewGetBillingDimensionMappingOptionalParameters() *GetBillingDimensionMappingOptionalParameters { + this := GetBillingDimensionMappingOptionalParameters{} + return &this +} + +// WithFilterMonth sets the corresponding parameter name and returns the struct. +func (r *GetBillingDimensionMappingOptionalParameters) WithFilterMonth(filterMonth time.Time) *GetBillingDimensionMappingOptionalParameters { + r.FilterMonth = &filterMonth + return r +} + +// WithFilterView sets the corresponding parameter name and returns the struct. +func (r *GetBillingDimensionMappingOptionalParameters) WithFilterView(filterView string) *GetBillingDimensionMappingOptionalParameters { + r.FilterView = &filterView + return r +} + +// GetBillingDimensionMapping Get billing dimension mapping for usage endpoints. +// Get a mapping of billing dimensions to the corresponding keys for the supported usage metering public API endpoints. +// Mapping data is updated on a monthly cadence. +// +// This endpoint is only accessible for [parent-level organizations](https://docs.datadoghq.com/account_management/multi_organization/). +func (a *UsageMeteringApi) GetBillingDimensionMapping(ctx _context.Context, o ...GetBillingDimensionMappingOptionalParameters) (BillingDimensionsMappingResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarReturnValue BillingDimensionsMappingResponse + optionalParams GetBillingDimensionMappingOptionalParameters + ) + + if len(o) > 1 { + return localVarReturnValue, nil, datadog.ReportError("only one argument of type GetBillingDimensionMappingOptionalParameters is allowed") + } + if len(o) == 1 { + optionalParams = o[0] + } + + operationId := "v2.GetBillingDimensionMapping" + if a.Client.Cfg.IsUnstableOperationEnabled(operationId) { + _log.Printf("WARNING: Using unstable operation '%s'", operationId) + } else { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} + } + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.UsageMeteringApi.GetBillingDimensionMapping") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/usage/billing_dimension_mapping" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + if optionalParams.FilterMonth != nil { + localVarQueryParams.Add("filter[month]", datadog.ParameterToString(*optionalParams.FilterMonth, "")) + } + if optionalParams.FilterView != nil { + localVarQueryParams.Add("filter[view]", datadog.ParameterToString(*optionalParams.FilterView, "")) + } + localVarHeaderParams["Accept"] = "application/json;datetime-format=rfc3339" + + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 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 +} + // GetCostByOrgOptionalParameters holds optional parameters for GetCostByOrg. type GetCostByOrgOptionalParameters struct { EndMonth *time.Time diff --git a/api/datadogV2/doc.go b/api/datadogV2/doc.go index 8a27584b8b8..9378f633436 100644 --- a/api/datadogV2/doc.go +++ b/api/datadogV2/doc.go @@ -345,6 +345,7 @@ // - [TeamsApi.UpdateTeamMembership] // - [TeamsApi.UpdateTeamPermissionSetting] // - [UsageMeteringApi.GetActiveBillingDimensions] +// - [UsageMeteringApi.GetBillingDimensionMapping] // - [UsageMeteringApi.GetCostByOrg] // - [UsageMeteringApi.GetEstimatedCostByOrg] // - [UsageMeteringApi.GetHistoricalCostByOrg] diff --git a/api/datadogV2/model_billing_dimensions_mapping_body_item.go b/api/datadogV2/model_billing_dimensions_mapping_body_item.go new file mode 100644 index 00000000000..715970c6eb3 --- /dev/null +++ b/api/datadogV2/model_billing_dimensions_mapping_body_item.go @@ -0,0 +1,189 @@ +// 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" +) + +// BillingDimensionsMappingBodyItem The mapping data for each billing dimension. +type BillingDimensionsMappingBodyItem struct { + // Mapping of billing dimensions to endpoint keys. + Attributes *BillingDimensionsMappingBodyItemAttributes `json:"attributes,omitempty"` + // ID of the billing dimension. + Id *string `json:"id,omitempty"` + // Type of active billing dimensions data. + Type *ActiveBillingDimensionsType `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:"-"` +} + +// NewBillingDimensionsMappingBodyItem instantiates a new BillingDimensionsMappingBodyItem 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 NewBillingDimensionsMappingBodyItem() *BillingDimensionsMappingBodyItem { + this := BillingDimensionsMappingBodyItem{} + var typeVar ActiveBillingDimensionsType = ACTIVEBILLINGDIMENSIONSTYPE_BILLING_DIMENSIONS + this.Type = &typeVar + return &this +} + +// NewBillingDimensionsMappingBodyItemWithDefaults instantiates a new BillingDimensionsMappingBodyItem 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 NewBillingDimensionsMappingBodyItemWithDefaults() *BillingDimensionsMappingBodyItem { + this := BillingDimensionsMappingBodyItem{} + var typeVar ActiveBillingDimensionsType = ACTIVEBILLINGDIMENSIONSTYPE_BILLING_DIMENSIONS + this.Type = &typeVar + return &this +} + +// GetAttributes returns the Attributes field value if set, zero value otherwise. +func (o *BillingDimensionsMappingBodyItem) GetAttributes() BillingDimensionsMappingBodyItemAttributes { + if o == nil || o.Attributes == nil { + var ret BillingDimensionsMappingBodyItemAttributes + 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 *BillingDimensionsMappingBodyItem) GetAttributesOk() (*BillingDimensionsMappingBodyItemAttributes, 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 *BillingDimensionsMappingBodyItem) HasAttributes() bool { + return o != nil && o.Attributes != nil +} + +// SetAttributes gets a reference to the given BillingDimensionsMappingBodyItemAttributes and assigns it to the Attributes field. +func (o *BillingDimensionsMappingBodyItem) SetAttributes(v BillingDimensionsMappingBodyItemAttributes) { + o.Attributes = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *BillingDimensionsMappingBodyItem) 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 *BillingDimensionsMappingBodyItem) 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 *BillingDimensionsMappingBodyItem) 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 *BillingDimensionsMappingBodyItem) SetId(v string) { + o.Id = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *BillingDimensionsMappingBodyItem) GetType() ActiveBillingDimensionsType { + if o == nil || o.Type == nil { + var ret ActiveBillingDimensionsType + 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 *BillingDimensionsMappingBodyItem) GetTypeOk() (*ActiveBillingDimensionsType, 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 *BillingDimensionsMappingBodyItem) HasType() bool { + return o != nil && o.Type != nil +} + +// SetType gets a reference to the given ActiveBillingDimensionsType and assigns it to the Type field. +func (o *BillingDimensionsMappingBodyItem) SetType(v ActiveBillingDimensionsType) { + o.Type = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o BillingDimensionsMappingBodyItem) 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.Id != nil { + toSerialize["id"] = o.Id + } + 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 *BillingDimensionsMappingBodyItem) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *BillingDimensionsMappingBodyItemAttributes `json:"attributes,omitempty"` + Id *string `json:"id,omitempty"` + Type *ActiveBillingDimensionsType `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", "id", "type"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes != nil && all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = all.Attributes + o.Id = all.Id + 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_billing_dimensions_mapping_body_item_attributes.go b/api/datadogV2/model_billing_dimensions_mapping_body_item_attributes.go new file mode 100644 index 00000000000..fdded93a1f6 --- /dev/null +++ b/api/datadogV2/model_billing_dimensions_mapping_body_item_attributes.go @@ -0,0 +1,178 @@ +// 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 ( + "time" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// BillingDimensionsMappingBodyItemAttributes Mapping of billing dimensions to endpoint keys. +type BillingDimensionsMappingBodyItemAttributes struct { + // List of supported endpoints with their keys mapped to the billing_dimension. + Endpoints []BillingDimensionsMappingBodyItemAttributesEndpointsItems `json:"endpoints,omitempty"` + // Label used for the billing dimension in the Plan & Usage charts. + InAppLabel *string `json:"in_app_label,omitempty"` + // Month in ISO-8601 format, UTC, precise to second: `[YYYY-MM-DDThh:mm:ss]`. + Timestamp *time.Time `json:"timestamp,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:"-"` +} + +// NewBillingDimensionsMappingBodyItemAttributes instantiates a new BillingDimensionsMappingBodyItemAttributes 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 NewBillingDimensionsMappingBodyItemAttributes() *BillingDimensionsMappingBodyItemAttributes { + this := BillingDimensionsMappingBodyItemAttributes{} + return &this +} + +// NewBillingDimensionsMappingBodyItemAttributesWithDefaults instantiates a new BillingDimensionsMappingBodyItemAttributes 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 NewBillingDimensionsMappingBodyItemAttributesWithDefaults() *BillingDimensionsMappingBodyItemAttributes { + this := BillingDimensionsMappingBodyItemAttributes{} + return &this +} + +// GetEndpoints returns the Endpoints field value if set, zero value otherwise. +func (o *BillingDimensionsMappingBodyItemAttributes) GetEndpoints() []BillingDimensionsMappingBodyItemAttributesEndpointsItems { + if o == nil || o.Endpoints == nil { + var ret []BillingDimensionsMappingBodyItemAttributesEndpointsItems + return ret + } + return o.Endpoints +} + +// GetEndpointsOk returns a tuple with the Endpoints field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BillingDimensionsMappingBodyItemAttributes) GetEndpointsOk() (*[]BillingDimensionsMappingBodyItemAttributesEndpointsItems, bool) { + if o == nil || o.Endpoints == nil { + return nil, false + } + return &o.Endpoints, true +} + +// HasEndpoints returns a boolean if a field has been set. +func (o *BillingDimensionsMappingBodyItemAttributes) HasEndpoints() bool { + return o != nil && o.Endpoints != nil +} + +// SetEndpoints gets a reference to the given []BillingDimensionsMappingBodyItemAttributesEndpointsItems and assigns it to the Endpoints field. +func (o *BillingDimensionsMappingBodyItemAttributes) SetEndpoints(v []BillingDimensionsMappingBodyItemAttributesEndpointsItems) { + o.Endpoints = v +} + +// GetInAppLabel returns the InAppLabel field value if set, zero value otherwise. +func (o *BillingDimensionsMappingBodyItemAttributes) GetInAppLabel() string { + if o == nil || o.InAppLabel == nil { + var ret string + return ret + } + return *o.InAppLabel +} + +// GetInAppLabelOk returns a tuple with the InAppLabel field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BillingDimensionsMappingBodyItemAttributes) GetInAppLabelOk() (*string, bool) { + if o == nil || o.InAppLabel == nil { + return nil, false + } + return o.InAppLabel, true +} + +// HasInAppLabel returns a boolean if a field has been set. +func (o *BillingDimensionsMappingBodyItemAttributes) HasInAppLabel() bool { + return o != nil && o.InAppLabel != nil +} + +// SetInAppLabel gets a reference to the given string and assigns it to the InAppLabel field. +func (o *BillingDimensionsMappingBodyItemAttributes) SetInAppLabel(v string) { + o.InAppLabel = &v +} + +// GetTimestamp returns the Timestamp field value if set, zero value otherwise. +func (o *BillingDimensionsMappingBodyItemAttributes) GetTimestamp() time.Time { + if o == nil || o.Timestamp == nil { + var ret time.Time + 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 *BillingDimensionsMappingBodyItemAttributes) GetTimestampOk() (*time.Time, 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 *BillingDimensionsMappingBodyItemAttributes) HasTimestamp() bool { + return o != nil && o.Timestamp != nil +} + +// SetTimestamp gets a reference to the given time.Time and assigns it to the Timestamp field. +func (o *BillingDimensionsMappingBodyItemAttributes) SetTimestamp(v time.Time) { + o.Timestamp = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o BillingDimensionsMappingBodyItemAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Endpoints != nil { + toSerialize["endpoints"] = o.Endpoints + } + if o.InAppLabel != nil { + toSerialize["in_app_label"] = o.InAppLabel + } + if o.Timestamp != nil { + if o.Timestamp.Nanosecond() == 0 { + toSerialize["timestamp"] = o.Timestamp.Format("2006-01-02T15:04:05Z07:00") + } else { + toSerialize["timestamp"] = o.Timestamp.Format("2006-01-02T15:04:05.000Z07:00") + } + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *BillingDimensionsMappingBodyItemAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Endpoints []BillingDimensionsMappingBodyItemAttributesEndpointsItems `json:"endpoints,omitempty"` + InAppLabel *string `json:"in_app_label,omitempty"` + Timestamp *time.Time `json:"timestamp,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{"endpoints", "in_app_label", "timestamp"}) + } else { + return err + } + o.Endpoints = all.Endpoints + o.InAppLabel = all.InAppLabel + o.Timestamp = all.Timestamp + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_billing_dimensions_mapping_body_item_attributes_endpoints_items.go b/api/datadogV2/model_billing_dimensions_mapping_body_item_attributes_endpoints_items.go new file mode 100644 index 00000000000..582f420e9de --- /dev/null +++ b/api/datadogV2/model_billing_dimensions_mapping_body_item_attributes_endpoints_items.go @@ -0,0 +1,182 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// BillingDimensionsMappingBodyItemAttributesEndpointsItems An endpoint's keys mapped to the billing_dimension. +type BillingDimensionsMappingBodyItemAttributesEndpointsItems struct { + // The URL for the endpoint. + Id *string `json:"id,omitempty"` + // The billing dimension. + Keys []string `json:"keys,omitempty"` + // Denotes whether or not mapping keys were available for this endpoint. + Status *BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus `json:"status,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:"-"` +} + +// NewBillingDimensionsMappingBodyItemAttributesEndpointsItems instantiates a new BillingDimensionsMappingBodyItemAttributesEndpointsItems 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 NewBillingDimensionsMappingBodyItemAttributesEndpointsItems() *BillingDimensionsMappingBodyItemAttributesEndpointsItems { + this := BillingDimensionsMappingBodyItemAttributesEndpointsItems{} + return &this +} + +// NewBillingDimensionsMappingBodyItemAttributesEndpointsItemsWithDefaults instantiates a new BillingDimensionsMappingBodyItemAttributesEndpointsItems 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 NewBillingDimensionsMappingBodyItemAttributesEndpointsItemsWithDefaults() *BillingDimensionsMappingBodyItemAttributesEndpointsItems { + this := BillingDimensionsMappingBodyItemAttributesEndpointsItems{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) 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 *BillingDimensionsMappingBodyItemAttributesEndpointsItems) 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 *BillingDimensionsMappingBodyItemAttributesEndpointsItems) 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 *BillingDimensionsMappingBodyItemAttributesEndpointsItems) SetId(v string) { + o.Id = &v +} + +// GetKeys returns the Keys field value if set, zero value otherwise. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) GetKeys() []string { + if o == nil || o.Keys == nil { + var ret []string + return ret + } + return o.Keys +} + +// GetKeysOk returns a tuple with the Keys field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) GetKeysOk() (*[]string, bool) { + if o == nil || o.Keys == nil { + return nil, false + } + return &o.Keys, true +} + +// HasKeys returns a boolean if a field has been set. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) HasKeys() bool { + return o != nil && o.Keys != nil +} + +// SetKeys gets a reference to the given []string and assigns it to the Keys field. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) SetKeys(v []string) { + o.Keys = v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) GetStatus() BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus { + if o == nil || o.Status == nil { + var ret BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) GetStatusOk() (*BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus, bool) { + if o == nil || o.Status == nil { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) HasStatus() bool { + return o != nil && o.Status != nil +} + +// SetStatus gets a reference to the given BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus and assigns it to the Status field. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) SetStatus(v BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus) { + o.Status = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o BillingDimensionsMappingBodyItemAttributesEndpointsItems) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Id != nil { + toSerialize["id"] = o.Id + } + if o.Keys != nil { + toSerialize["keys"] = o.Keys + } + if o.Status != nil { + toSerialize["status"] = o.Status + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *BillingDimensionsMappingBodyItemAttributesEndpointsItems) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Id *string `json:"id,omitempty"` + Keys []string `json:"keys,omitempty"` + Status *BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus `json:"status,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", "keys", "status"}) + } else { + return err + } + + hasInvalidField := false + o.Id = all.Id + o.Keys = all.Keys + if all.Status != nil && !all.Status.IsValid() { + hasInvalidField = true + } else { + o.Status = all.Status + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_billing_dimensions_mapping_body_item_attributes_endpoints_items_status.go b/api/datadogV2/model_billing_dimensions_mapping_body_item_attributes_endpoints_items_status.go new file mode 100644 index 00000000000..62a757df52a --- /dev/null +++ b/api/datadogV2/model_billing_dimensions_mapping_body_item_attributes_endpoints_items_status.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" +) + +// BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus Denotes whether or not mapping keys were available for this endpoint. +type BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus string + +// List of BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus. +const ( + BILLINGDIMENSIONSMAPPINGBODYITEMATTRIBUTESENDPOINTSITEMSSTATUS_OK BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus = "OK" + BILLINGDIMENSIONSMAPPINGBODYITEMATTRIBUTESENDPOINTSITEMSSTATUS_NOT_FOUND BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus = "NOT_FOUND" +) + +var allowedBillingDimensionsMappingBodyItemAttributesEndpointsItemsStatusEnumValues = []BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus{ + BILLINGDIMENSIONSMAPPINGBODYITEMATTRIBUTESENDPOINTSITEMSSTATUS_OK, + BILLINGDIMENSIONSMAPPINGBODYITEMATTRIBUTESENDPOINTSITEMSSTATUS_NOT_FOUND, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus) GetAllowedValues() []BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus { + return allowedBillingDimensionsMappingBodyItemAttributesEndpointsItemsStatusEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus(value) + return nil +} + +// NewBillingDimensionsMappingBodyItemAttributesEndpointsItemsStatusFromValue returns a pointer to a valid BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewBillingDimensionsMappingBodyItemAttributesEndpointsItemsStatusFromValue(v string) (*BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus, error) { + ev := BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus: valid values are %v", v, allowedBillingDimensionsMappingBodyItemAttributesEndpointsItemsStatusEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus) IsValid() bool { + for _, existing := range allowedBillingDimensionsMappingBodyItemAttributesEndpointsItemsStatusEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus value. +func (v BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus) Ptr() *BillingDimensionsMappingBodyItemAttributesEndpointsItemsStatus { + return &v +} diff --git a/api/datadogV2/model_billing_dimensions_mapping_response.go b/api/datadogV2/model_billing_dimensions_mapping_response.go new file mode 100644 index 00000000000..ea179c80b57 --- /dev/null +++ b/api/datadogV2/model_billing_dimensions_mapping_response.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" +) + +// BillingDimensionsMappingResponse Billing dimensions mapping response. +type BillingDimensionsMappingResponse struct { + // Billing dimensions mapping data. + Data []BillingDimensionsMappingBodyItem `json:"data,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewBillingDimensionsMappingResponse instantiates a new BillingDimensionsMappingResponse 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 NewBillingDimensionsMappingResponse() *BillingDimensionsMappingResponse { + this := BillingDimensionsMappingResponse{} + return &this +} + +// NewBillingDimensionsMappingResponseWithDefaults instantiates a new BillingDimensionsMappingResponse 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 NewBillingDimensionsMappingResponseWithDefaults() *BillingDimensionsMappingResponse { + this := BillingDimensionsMappingResponse{} + return &this +} + +// GetData returns the Data field value if set, zero value otherwise. +func (o *BillingDimensionsMappingResponse) GetData() []BillingDimensionsMappingBodyItem { + if o == nil || o.Data == nil { + var ret []BillingDimensionsMappingBodyItem + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BillingDimensionsMappingResponse) GetDataOk() (*[]BillingDimensionsMappingBodyItem, bool) { + if o == nil || o.Data == nil { + return nil, false + } + return &o.Data, true +} + +// HasData returns a boolean if a field has been set. +func (o *BillingDimensionsMappingResponse) HasData() bool { + return o != nil && o.Data != nil +} + +// SetData gets a reference to the given []BillingDimensionsMappingBodyItem and assigns it to the Data field. +func (o *BillingDimensionsMappingResponse) SetData(v []BillingDimensionsMappingBodyItem) { + o.Data = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o BillingDimensionsMappingResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Data != nil { + toSerialize["data"] = o.Data + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *BillingDimensionsMappingResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data []BillingDimensionsMappingBodyItem `json:"data,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + o.Data = all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/examples/v2/usage-metering/GetBillingDimensionMapping.go b/examples/v2/usage-metering/GetBillingDimensionMapping.go new file mode 100644 index 00000000000..0517c2931b8 --- /dev/null +++ b/examples/v2/usage-metering/GetBillingDimensionMapping.go @@ -0,0 +1,30 @@ +// Get billing dimension mapping for usage endpoints returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + configuration.SetUnstableOperationEnabled("v2.GetBillingDimensionMapping", true) + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewUsageMeteringApi(apiClient) + resp, r, err := api.GetBillingDimensionMapping(ctx, *datadogV2.NewGetBillingDimensionMappingOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `UsageMeteringApi.GetBillingDimensionMapping`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `UsageMeteringApi.GetBillingDimensionMapping`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 62da7c99ef9..283f9e4ace9 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -2408,6 +2408,12 @@ "type": "safe" } }, + "GetBillingDimensionMapping": { + "tag": "Usage Metering", + "undo": { + "type": "safe" + } + }, "GetCostByOrg": { "tag": "Usage Metering", "undo": { diff --git a/tests/scenarios/features/v2/usage_metering.feature b/tests/scenarios/features/v2/usage_metering.feature index 4773ad01338..bc4e2553b16 100644 --- a/tests/scenarios/features/v2/usage_metering.feature +++ b/tests/scenarios/features/v2/usage_metering.feature @@ -48,6 +48,20 @@ Feature: Usage Metering When the request is sent Then the response status is 200 OK + @skip @team:DataDog/revenue-query + Scenario: Get billing dimension mapping for usage endpoints returns "Bad Request" response + Given operation "GetBillingDimensionMapping" enabled + And new "GetBillingDimensionMapping" request + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/revenue-query + Scenario: Get billing dimension mapping for usage endpoints returns "OK" response + Given operation "GetBillingDimensionMapping" enabled + And new "GetBillingDimensionMapping" request + When the request is sent + Then the response status is 200 OK + @generated @skip @team:DataDog/revenue-query Scenario: Get cost across multi-org account returns "Bad Request" response Given new "GetCostByOrg" request