diff --git a/.apigentools-info b/.apigentools-info index 3f28dfc3b1b..71252b4f27f 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-08-02 13:53:58.905782", - "spec_repo_commit": "74b2ffcb" + "regenerated": "2024-08-05 16:34:54.924716", + "spec_repo_commit": "578f6c8c" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-08-02 13:53:58.923820", - "spec_repo_commit": "74b2ffcb" + "regenerated": "2024-08-05 16:34:54.942887", + "spec_repo_commit": "578f6c8c" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 494a77414d4..07fb9e9c02f 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -11330,6 +11330,37 @@ components: example: /api/v2/scorecard/rules?page%5Blimit%5D=2&page%5Boffset%5D=2&page%5Bsize%5D=2 type: string type: object + ListTagsResponse: + description: List tags response. + properties: + data: + $ref: '#/components/schemas/ListTagsResponseData' + type: object + ListTagsResponseData: + description: The list tags response data. + properties: + attributes: + $ref: '#/components/schemas/ListTagsResponseDataAttributes' + id: + description: The device ID + example: example:1.2.3.4 + type: string + type: + description: The type of the resource. The value should always be tags. + type: string + type: object + ListTagsResponseDataAttributes: + description: The definition of ListTagsResponseDataAttributes object. + properties: + tags: + description: The list of tags + example: + - tag:test + - tag:testbis + items: + type: string + type: array + type: object ListTeamsInclude: description: Included related resources optionally requested. enum: @@ -31582,6 +31613,67 @@ paths: summary: Get the list of interfaces of the device tags: - Network Device Monitoring + /api/v2/ndm/tags/devices/{device_id}: + get: + description: Get the list of tags for a device. + operationId: ListDeviceUserTags + parameters: + - description: The id of the device to fetch tags for. + example: example:1.2.3.4 + in: path + name: device_id + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ListTagsResponse' + description: OK + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Get the list of tags for a device + tags: + - Network Device Monitoring + patch: + description: Update the tags for a device. + operationId: UpdateDeviceUserTags + parameters: + - description: The id of the device to update tags for. + example: example:1.2.3.4 + in: path + name: device_id + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ListTagsResponse' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ListTagsResponse' + description: OK + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Update the tags for a device + tags: + - Network Device Monitoring /api/v2/org_configs: get: description: Returns all Org Configs (name, description, and value). diff --git a/api/datadogV2/api_network_device_monitoring.go b/api/datadogV2/api_network_device_monitoring.go index fe1a0b7a170..105de413700 100644 --- a/api/datadogV2/api_network_device_monitoring.go +++ b/api/datadogV2/api_network_device_monitoring.go @@ -158,6 +158,77 @@ func (a *NetworkDeviceMonitoringApi) GetInterfaces(ctx _context.Context, deviceI return localVarReturnValue, localVarHTTPResponse, nil } +// ListDeviceUserTags Get the list of tags for a device. +// Get the list of tags for a device. +func (a *NetworkDeviceMonitoringApi) ListDeviceUserTags(ctx _context.Context, deviceId string) (ListTagsResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarReturnValue ListTagsResponse + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.NetworkDeviceMonitoringApi.ListDeviceUserTags") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/ndm/tags/devices/{device_id}" + localVarPath = strings.Replace(localVarPath, "{"+"device_id"+"}", _neturl.PathEscape(datadog.ParameterToString(deviceId, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Accept"] = "application/json" + + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + // ListDevicesOptionalParameters holds optional parameters for ListDevices. type ListDevicesOptionalParameters struct { PageNumber *int64 @@ -286,6 +357,80 @@ func (a *NetworkDeviceMonitoringApi) ListDevices(ctx _context.Context, o ...List return localVarReturnValue, localVarHTTPResponse, nil } +// UpdateDeviceUserTags Update the tags for a device. +// Update the tags for a device. +func (a *NetworkDeviceMonitoringApi) UpdateDeviceUserTags(ctx _context.Context, deviceId string, body ListTagsResponse) (ListTagsResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPatch + localVarPostBody interface{} + localVarReturnValue ListTagsResponse + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.NetworkDeviceMonitoringApi.UpdateDeviceUserTags") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/ndm/tags/devices/{device_id}" + localVarPath = strings.Replace(localVarPath, "{"+"device_id"+"}", _neturl.PathEscape(datadog.ParameterToString(deviceId, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "application/json" + localVarHeaderParams["Accept"] = "application/json" + + // body params + localVarPostBody = &body + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + // NewNetworkDeviceMonitoringApi Returns NewNetworkDeviceMonitoringApi. func NewNetworkDeviceMonitoringApi(client *datadog.APIClient) *NetworkDeviceMonitoringApi { return &NetworkDeviceMonitoringApi{ diff --git a/api/datadogV2/doc.go b/api/datadogV2/doc.go index 7e26e20e320..381029a65d6 100644 --- a/api/datadogV2/doc.go +++ b/api/datadogV2/doc.go @@ -204,7 +204,9 @@ // - [MonitorsApi.UpdateMonitorConfigPolicy] // - [NetworkDeviceMonitoringApi.GetDevice] // - [NetworkDeviceMonitoringApi.GetInterfaces] +// - [NetworkDeviceMonitoringApi.ListDeviceUserTags] // - [NetworkDeviceMonitoringApi.ListDevices] +// - [NetworkDeviceMonitoringApi.UpdateDeviceUserTags] // - [OktaIntegrationApi.CreateOktaAccount] // - [OktaIntegrationApi.DeleteOktaAccount] // - [OktaIntegrationApi.GetOktaAccount] diff --git a/api/datadogV2/model_list_tags_response.go b/api/datadogV2/model_list_tags_response.go new file mode 100644 index 00000000000..0c58a8348f0 --- /dev/null +++ b/api/datadogV2/model_list_tags_response.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" +) + +// ListTagsResponse List tags response. +type ListTagsResponse struct { + // The list tags response data. + Data *ListTagsResponseData `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:"-"` +} + +// NewListTagsResponse instantiates a new ListTagsResponse 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 NewListTagsResponse() *ListTagsResponse { + this := ListTagsResponse{} + return &this +} + +// NewListTagsResponseWithDefaults instantiates a new ListTagsResponse 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 NewListTagsResponseWithDefaults() *ListTagsResponse { + this := ListTagsResponse{} + return &this +} + +// GetData returns the Data field value if set, zero value otherwise. +func (o *ListTagsResponse) GetData() ListTagsResponseData { + if o == nil || o.Data == nil { + var ret ListTagsResponseData + 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 *ListTagsResponse) GetDataOk() (*ListTagsResponseData, 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 *ListTagsResponse) HasData() bool { + return o != nil && o.Data != nil +} + +// SetData gets a reference to the given ListTagsResponseData and assigns it to the Data field. +func (o *ListTagsResponse) SetData(v ListTagsResponseData) { + o.Data = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ListTagsResponse) 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 *ListTagsResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *ListTagsResponseData `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 + } + + hasInvalidField := false + if all.Data != nil && all.Data.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Data = all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_list_tags_response_data.go b/api/datadogV2/model_list_tags_response_data.go new file mode 100644 index 00000000000..8cb15a16921 --- /dev/null +++ b/api/datadogV2/model_list_tags_response_data.go @@ -0,0 +1,181 @@ +// 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" +) + +// ListTagsResponseData The list tags response data. +type ListTagsResponseData struct { + // The definition of ListTagsResponseDataAttributes object. + Attributes *ListTagsResponseDataAttributes `json:"attributes,omitempty"` + // The device ID + Id *string `json:"id,omitempty"` + // The type of the resource. The value should always be tags. + 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:"-"` +} + +// NewListTagsResponseData instantiates a new ListTagsResponseData 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 NewListTagsResponseData() *ListTagsResponseData { + this := ListTagsResponseData{} + return &this +} + +// NewListTagsResponseDataWithDefaults instantiates a new ListTagsResponseData 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 NewListTagsResponseDataWithDefaults() *ListTagsResponseData { + this := ListTagsResponseData{} + return &this +} + +// GetAttributes returns the Attributes field value if set, zero value otherwise. +func (o *ListTagsResponseData) GetAttributes() ListTagsResponseDataAttributes { + if o == nil || o.Attributes == nil { + var ret ListTagsResponseDataAttributes + 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 *ListTagsResponseData) GetAttributesOk() (*ListTagsResponseDataAttributes, 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 *ListTagsResponseData) HasAttributes() bool { + return o != nil && o.Attributes != nil +} + +// SetAttributes gets a reference to the given ListTagsResponseDataAttributes and assigns it to the Attributes field. +func (o *ListTagsResponseData) SetAttributes(v ListTagsResponseDataAttributes) { + o.Attributes = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *ListTagsResponseData) 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 *ListTagsResponseData) 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 *ListTagsResponseData) 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 *ListTagsResponseData) SetId(v string) { + o.Id = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *ListTagsResponseData) 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 *ListTagsResponseData) 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 *ListTagsResponseData) 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 *ListTagsResponseData) SetType(v string) { + o.Type = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ListTagsResponseData) 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 *ListTagsResponseData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *ListTagsResponseDataAttributes `json:"attributes,omitempty"` + Id *string `json:"id,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", "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 + 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_list_tags_response_data_attributes.go b/api/datadogV2/model_list_tags_response_data_attributes.go new file mode 100644 index 00000000000..9be0ee2be28 --- /dev/null +++ b/api/datadogV2/model_list_tags_response_data_attributes.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" +) + +// ListTagsResponseDataAttributes The definition of ListTagsResponseDataAttributes object. +type ListTagsResponseDataAttributes struct { + // The list of tags + Tags []string `json:"tags,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:"-"` +} + +// NewListTagsResponseDataAttributes instantiates a new ListTagsResponseDataAttributes 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 NewListTagsResponseDataAttributes() *ListTagsResponseDataAttributes { + this := ListTagsResponseDataAttributes{} + return &this +} + +// NewListTagsResponseDataAttributesWithDefaults instantiates a new ListTagsResponseDataAttributes 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 NewListTagsResponseDataAttributesWithDefaults() *ListTagsResponseDataAttributes { + this := ListTagsResponseDataAttributes{} + return &this +} + +// GetTags returns the Tags field value if set, zero value otherwise. +func (o *ListTagsResponseDataAttributes) 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 *ListTagsResponseDataAttributes) 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 *ListTagsResponseDataAttributes) 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 *ListTagsResponseDataAttributes) SetTags(v []string) { + o.Tags = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o ListTagsResponseDataAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Tags != nil { + toSerialize["tags"] = o.Tags + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *ListTagsResponseDataAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Tags []string `json:"tags,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{"tags"}) + } else { + return err + } + o.Tags = all.Tags + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/examples/v2/network-device-monitoring/ListDeviceUserTags.go b/examples/v2/network-device-monitoring/ListDeviceUserTags.go new file mode 100644 index 00000000000..d5f27b95404 --- /dev/null +++ b/examples/v2/network-device-monitoring/ListDeviceUserTags.go @@ -0,0 +1,29 @@ +// Get the list of tags for a device 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() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewNetworkDeviceMonitoringApi(apiClient) + resp, r, err := api.ListDeviceUserTags(ctx, "default_device") + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `NetworkDeviceMonitoringApi.ListDeviceUserTags`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `NetworkDeviceMonitoringApi.ListDeviceUserTags`:\n%s\n", responseContent) +} diff --git a/examples/v2/network-device-monitoring/UpdateDeviceUserTags.go b/examples/v2/network-device-monitoring/UpdateDeviceUserTags.go new file mode 100644 index 00000000000..040b9072228 --- /dev/null +++ b/examples/v2/network-device-monitoring/UpdateDeviceUserTags.go @@ -0,0 +1,41 @@ +// Update the tags for a device 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.ListTagsResponse{ + Data: &datadogV2.ListTagsResponseData{ + Attributes: &datadogV2.ListTagsResponseDataAttributes{ + Tags: []string{ + "tag:test", + "tag:testbis", + }, + }, + Id: datadog.PtrString("default_device"), + Type: datadog.PtrString("tags"), + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewNetworkDeviceMonitoringApi(apiClient) + resp, r, err := api.UpdateDeviceUserTags(ctx, "default_device", body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `NetworkDeviceMonitoringApi.UpdateDeviceUserTags`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `NetworkDeviceMonitoringApi.UpdateDeviceUserTags`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_device_details_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_device_details_returns_OK_response.freeze index 00f14c77f36..69034e11aff 100644 --- a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_device_details_returns_OK_response.freeze +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_device_details_returns_OK_response.freeze @@ -1 +1 @@ -2024-07-04T16:51:27.417Z \ No newline at end of file +2024-07-25T12:51:06.792Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_Not_Found_response.freeze b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_Not_Found_response.freeze new file mode 100644 index 00000000000..032b13863c2 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_Not_Found_response.freeze @@ -0,0 +1 @@ +2024-07-29T13:20:36.111Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_Not_Found_response.yaml b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_Not_Found_response.yaml new file mode 100644 index 00000000000..c4b8980beaf --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_Not_Found_response.yaml @@ -0,0 +1,19 @@ +interactions: +- request: + body: '' + form: {} + headers: + Accept: + - application/json + id: 0 + method: GET + url: https://api.datadoghq.com/api/v2/ndm/tags/devices/unknown_device_id + response: + body: '{"errors":[{"status":"404","title":"Not Found"}]}' + code: 404 + duration: 0ms + headers: + Content-Type: + - application/vnd.api+json + status: 404 Not Found +version: 2 diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_OK_response.freeze new file mode 100644 index 00000000000..d69509f7b17 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_OK_response.freeze @@ -0,0 +1 @@ +2024-07-30T13:27:40.522Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_OK_response.yaml b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_OK_response.yaml new file mode 100644 index 00000000000..9a0b3bab443 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Get_the_list_of_tags_for_a_device_returns_OK_response.yaml @@ -0,0 +1,19 @@ +interactions: +- request: + body: '' + form: {} + headers: + Accept: + - application/json + id: 0 + method: GET + url: https://api.datadoghq.com/api/v2/ndm/tags/devices/default_device + response: + body: '{"data":{"id":"default_device","type":"tags","attributes":{"tags":["tag:test","tag:testbis"]}}}' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK +version: 2 diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_Not_Found_response.freeze b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_Not_Found_response.freeze new file mode 100644 index 00000000000..ed8b19d9c38 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_Not_Found_response.freeze @@ -0,0 +1 @@ +2024-07-29T13:20:36.885Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_Not_Found_response.yaml b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_Not_Found_response.yaml new file mode 100644 index 00000000000..ceccc342e11 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_Not_Found_response.yaml @@ -0,0 +1,22 @@ +interactions: +- request: + body: | + {"data":{"attributes":{"tags":["tag:test","tag:testbis"]},"id":"unknown_device_id","type":"tags"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: PATCH + url: https://api.datadoghq.com/api/v2/ndm/tags/devices/unknown_device_id + response: + body: '{"errors":[{"status":"404","title":"Not Found"}]}' + code: 404 + duration: 0ms + headers: + Content-Type: + - application/vnd.api+json + status: 404 Not Found +version: 2 diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_OK_response.freeze new file mode 100644 index 00000000000..c589ad4e809 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_OK_response.freeze @@ -0,0 +1 @@ +2024-07-29T13:20:37.177Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_OK_response.yaml b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_OK_response.yaml new file mode 100644 index 00000000000..f1b1a3cccef --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_Network_Device_Monitoring/Scenario_Update_the_tags_for_a_device_returns_OK_response.yaml @@ -0,0 +1,22 @@ +interactions: +- request: + body: | + {"data":{"attributes":{"tags":["tag:test","tag:testbis"]},"id":"default_device","type":"tags"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: PATCH + url: https://api.datadoghq.com/api/v2/ndm/tags/devices/default_device + response: + body: '{"data":{"id":"default_device","type":"tags","attributes":{"tags":["tag:test","tag:testbis"]}}}' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK +version: 2 diff --git a/tests/scenarios/features/v2/network_device_monitoring.feature b/tests/scenarios/features/v2/network_device_monitoring.feature index c07ab943c46..6952a281f0f 100644 --- a/tests/scenarios/features/v2/network_device_monitoring.feature +++ b/tests/scenarios/features/v2/network_device_monitoring.feature @@ -97,3 +97,41 @@ Feature: Network Device Monitoring And the response "data[1].attributes.alias" is equal to "interface_999" And the response "data[1].attributes.index" is equal to 999 And the response "data[1].attributes.status" is equal to "down" + + @replay-only @team:DataDog/network-device-monitoring + Scenario: Get the list of tags for a device returns "Not Found" response + Given new "ListDeviceUserTags" request + And request contains "device_id" parameter with value "unknown_device_id" + When the request is sent + Then the response status is 404 Not Found + + @replay-only @team:DataDog/network-device-monitoring + Scenario: Get the list of tags for a device returns "OK" response + Given new "ListDeviceUserTags" request + And request contains "device_id" parameter with value "default_device" + When the request is sent + Then the response status is 200 OK + And the response "data.id" is equal to "default_device" + And the response "data.type" is equal to "tags" + And the response "data.attributes.tags[0]" is equal to "tag:test" + And the response "data.attributes.tags[1]" is equal to "tag:testbis" + + @replay-only @team:DataDog/network-device-monitoring + Scenario: Update the tags for a device returns "Not Found" response + Given new "UpdateDeviceUserTags" request + And request contains "device_id" parameter with value "unknown_device_id" + And body with value {"data": {"attributes": {"tags": ["tag:test", "tag:testbis"]}, "id": "unknown_device_id", "type":"tags"}} + When the request is sent + Then the response status is 404 Not Found + + @replay-only @team:DataDog/network-device-monitoring + Scenario: Update the tags for a device returns "OK" response + Given new "UpdateDeviceUserTags" request + And request contains "device_id" parameter with value "default_device" + And body with value {"data": {"attributes": {"tags": ["tag:test", "tag:testbis"]}, "id": "default_device", "type":"tags"}} + When the request is sent + Then the response status is 200 OK + And the response "data.id" is equal to "default_device" + And the response "data.type" is equal to "tags" + And the response "data.attributes.tags[0]" is equal to "tag:test" + And the response "data.attributes.tags[1]" is equal to "tag:testbis" diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 9c6ec9d71ca..dc362a26a8d 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -1339,6 +1339,18 @@ "type": "safe" } }, + "ListDeviceUserTags": { + "tag": "Network Device Monitoring", + "undo": { + "type": "safe" + } + }, + "UpdateDeviceUserTags": { + "tag": "Network Device Monitoring", + "undo": { + "type": "idempotent" + } + }, "ListOrgConfigs": { "tag": "Organizations", "undo": {