Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for retrieving a security signal by ID #1681

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.4",
"regenerated": "2022-09-22 15:10:29.291260",
"spec_repo_commit": "7f715655"
"regenerated": "2022-09-26 07:51:13.564660",
"spec_repo_commit": "af78fdc4"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2022-09-22 15:10:29.309352",
"spec_repo_commit": "7f715655"
"regenerated": "2022-09-26 07:51:13.582923",
"spec_repo_commit": "af78fdc4"
}
}
}
25 changes: 25 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12863,6 +12863,31 @@ paths:
cursorPath: meta.page.after
limitParam: body.page.limit
resultsPath: data
/api/v2/security_monitoring/signals/{signal_id}:
get:
description: Get a signal's details.
operationId: GetSecurityMonitoringSignal
parameters:
- $ref: '#/components/parameters/SignalID'
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/SecurityMonitoringSignal'
description: OK
'404':
$ref: '#/components/responses/NotFoundResponse'
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
security:
- apiKeyAuth: []
appKeyAuth: []
- AuthZ:
- security_monitoring_rules_read
summary: Get a signal's details
tags:
- Security Monitoring
/api/v2/security_monitoring/signals/{signal_id}/assignee:
patch:
description: Modify the triage assignee of a security signal.
Expand Down
119 changes: 119 additions & 0 deletions api/datadogV2/api_security_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,125 @@ func (a *SecurityMonitoringApi) getSecurityMonitoringRuleExecute(r apiGetSecurit
return localVarReturnValue, localVarHTTPResponse, nil
}

type apiGetSecurityMonitoringSignalRequest struct {
ctx _context.Context
signalId string
}

func (a *SecurityMonitoringApi) buildGetSecurityMonitoringSignalRequest(ctx _context.Context, signalId string) (apiGetSecurityMonitoringSignalRequest, error) {
req := apiGetSecurityMonitoringSignalRequest{
ctx: ctx,
signalId: signalId,
}
return req, nil
}

// GetSecurityMonitoringSignal Get a signal's details.
// Get a signal's details.
func (a *SecurityMonitoringApi) GetSecurityMonitoringSignal(ctx _context.Context, signalId string) (SecurityMonitoringSignal, *_nethttp.Response, error) {
req, err := a.buildGetSecurityMonitoringSignalRequest(ctx, signalId)
if err != nil {
var localVarReturnValue SecurityMonitoringSignal
return localVarReturnValue, nil, err
}

return a.getSecurityMonitoringSignalExecute(req)
}

// getSecurityMonitoringSignalExecute executes the request.
func (a *SecurityMonitoringApi) getSecurityMonitoringSignalExecute(r apiGetSecurityMonitoringSignalRequest) (SecurityMonitoringSignal, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodGet
localVarPostBody interface{}
localVarReturnValue SecurityMonitoringSignal
)

localBasePath, err := a.Client.Cfg.ServerURLWithContext(r.ctx, "v2.SecurityMonitoringApi.GetSecurityMonitoringSignal")
if err != nil {
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
}

localVarPath := localBasePath + "/api/v2/security_monitoring/signals/{signal_id}"
localVarPath = strings.Replace(localVarPath, "{"+"signal_id"+"}", _neturl.PathEscape(datadog.ParameterToString(r.signalId, "")), -1)

localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
localVarHeaderParams["Accept"] = "application/json"

if r.ctx != nil {
// API Key Authentication
if auth, ok := r.ctx.Value(datadog.ContextAPIKeys).(map[string]datadog.APIKey); ok {
if apiKey, ok := auth["apiKeyAuth"]; ok {
var key string
if apiKey.Prefix != "" {
key = apiKey.Prefix + " " + apiKey.Key
} else {
key = apiKey.Key
}
localVarHeaderParams["DD-API-KEY"] = key
}
}
}
if r.ctx != nil {
// API Key Authentication
if auth, ok := r.ctx.Value(datadog.ContextAPIKeys).(map[string]datadog.APIKey); ok {
if apiKey, ok := auth["appKeyAuth"]; ok {
var key string
if apiKey.Prefix != "" {
key = apiKey.Prefix + " " + apiKey.Key
} else {
key = apiKey.Key
}
localVarHeaderParams["DD-APPLICATION-KEY"] = key
}
}
}
req, err := a.Client.PrepareRequest(r.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 := _ioutil.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = _ioutil.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}

if localVarHTTPResponse.StatusCode >= 300 {
newErr := datadog.GenericOpenAPIError{
ErrorBody: localVarBody,
ErrorMessage: localVarHTTPResponse.Status,
}
if 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
}

type apiListSecurityFiltersRequest struct {
ctx _context.Context
}
Expand Down
29 changes: 29 additions & 0 deletions examples/v2/security-monitoring/GetSecurityMonitoringSignal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Get a signal's details 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.NewSecurityMonitoringApi(apiClient)
resp, r, err := api.GetSecurityMonitoringSignal(ctx, "AQAAAYNqUBVU4-rffwAAAABBWU5xVUJWVUFBQjJBd3ptMDdQUnF3QUE")

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `SecurityMonitoringApi.GetSecurityMonitoringSignal`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}

responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `SecurityMonitoringApi.GetSecurityMonitoringSignal`:\n%s\n", responseContent)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2022-09-23T14:12:23.353Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
interactions:
- request:
body: ''
form: {}
headers:
Accept:
- application/json
method: GET
url: https://api.datadoghq.com/api/v2/security_monitoring/signals/AQAAAYNqUBVU4-rffwAAAABBWU5xVUJWVUFBQjJBd3ptCL3QUEm3nt2
response:
body: '{"errors":["Signal not found"]}'
code: 404
duration: ''
headers:
Content-Type:
- application/json
status: 404 Not Found
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2022-09-23T14:12:23.776Z
Loading