Skip to content

Commit fb82920

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add support for vulnerability management - Add ListScannedAssetsMetadata new endpoint and update existing ones (#3400)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 154b542 commit fb82920

24 files changed

+1970
-225
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 461 additions & 210 deletions
Large diffs are not rendered by default.

api/datadog/configuration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ func NewConfiguration() *Configuration {
617617
"v2.ListAssetsSBOMs": false,
618618
"v2.ListFindings": false,
619619
"v2.ListHistoricalJobs": false,
620+
"v2.ListScannedAssetsMetadata": false,
620621
"v2.ListSecurityMonitoringHistsignals": false,
621622
"v2.ListVulnerabilities": false,
622623
"v2.ListVulnerableAssets": false,

api/datadogV2/api_security_monitoring.go

Lines changed: 237 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,7 @@ func (a *SecurityMonitoringApi) GetRuleVersionHistory(ctx _context.Context, rule
20912091
// GetSBOMOptionalParameters holds optional parameters for GetSBOM.
20922092
type GetSBOMOptionalParameters struct {
20932093
FilterRepoDigest *string
2094+
ExtFormat *SBOMFormat
20942095
}
20952096

20962097
// NewGetSBOMOptionalParameters creates an empty struct for parameters.
@@ -2105,6 +2106,12 @@ func (r *GetSBOMOptionalParameters) WithFilterRepoDigest(filterRepoDigest string
21052106
return r
21062107
}
21072108

2109+
// WithExtFormat sets the corresponding parameter name and returns the struct.
2110+
func (r *GetSBOMOptionalParameters) WithExtFormat(extFormat SBOMFormat) *GetSBOMOptionalParameters {
2111+
r.ExtFormat = &extFormat
2112+
return r
2113+
}
2114+
21082115
// GetSBOM Get SBOM.
21092116
// Get a single SBOM related to an asset by its type and name.
21102117
func (a *SecurityMonitoringApi) GetSBOM(ctx _context.Context, assetType AssetType, filterAssetName string, o ...GetSBOMOptionalParameters) (GetSBOMResponse, *_nethttp.Response, error) {
@@ -2146,6 +2153,9 @@ func (a *SecurityMonitoringApi) GetSBOM(ctx _context.Context, assetType AssetTyp
21462153
if optionalParams.FilterRepoDigest != nil {
21472154
localVarQueryParams.Add("filter[repo_digest]", datadog.ParameterToString(*optionalParams.FilterRepoDigest, ""))
21482155
}
2156+
if optionalParams.ExtFormat != nil {
2157+
localVarQueryParams.Add("ext:format", datadog.ParameterToString(*optionalParams.ExtFormat, ""))
2158+
}
21492159
localVarHeaderParams["Accept"] = "application/json"
21502160

21512161
if a.Client.Cfg.DelegatedTokenConfig != nil {
@@ -3960,6 +3970,222 @@ func (a *SecurityMonitoringApi) ListHistoricalJobs(ctx _context.Context, o ...Li
39603970
return localVarReturnValue, localVarHTTPResponse, nil
39613971
}
39623972

3973+
// ListScannedAssetsMetadataOptionalParameters holds optional parameters for ListScannedAssetsMetadata.
3974+
type ListScannedAssetsMetadataOptionalParameters struct {
3975+
PageToken *string
3976+
PageNumber *int64
3977+
FilterAssetType *CloudAssetType
3978+
FilterAssetName *string
3979+
FilterLastSuccessOrigin *string
3980+
FilterLastSuccessEnv *string
3981+
}
3982+
3983+
// NewListScannedAssetsMetadataOptionalParameters creates an empty struct for parameters.
3984+
func NewListScannedAssetsMetadataOptionalParameters() *ListScannedAssetsMetadataOptionalParameters {
3985+
this := ListScannedAssetsMetadataOptionalParameters{}
3986+
return &this
3987+
}
3988+
3989+
// WithPageToken sets the corresponding parameter name and returns the struct.
3990+
func (r *ListScannedAssetsMetadataOptionalParameters) WithPageToken(pageToken string) *ListScannedAssetsMetadataOptionalParameters {
3991+
r.PageToken = &pageToken
3992+
return r
3993+
}
3994+
3995+
// WithPageNumber sets the corresponding parameter name and returns the struct.
3996+
func (r *ListScannedAssetsMetadataOptionalParameters) WithPageNumber(pageNumber int64) *ListScannedAssetsMetadataOptionalParameters {
3997+
r.PageNumber = &pageNumber
3998+
return r
3999+
}
4000+
4001+
// WithFilterAssetType sets the corresponding parameter name and returns the struct.
4002+
func (r *ListScannedAssetsMetadataOptionalParameters) WithFilterAssetType(filterAssetType CloudAssetType) *ListScannedAssetsMetadataOptionalParameters {
4003+
r.FilterAssetType = &filterAssetType
4004+
return r
4005+
}
4006+
4007+
// WithFilterAssetName sets the corresponding parameter name and returns the struct.
4008+
func (r *ListScannedAssetsMetadataOptionalParameters) WithFilterAssetName(filterAssetName string) *ListScannedAssetsMetadataOptionalParameters {
4009+
r.FilterAssetName = &filterAssetName
4010+
return r
4011+
}
4012+
4013+
// WithFilterLastSuccessOrigin sets the corresponding parameter name and returns the struct.
4014+
func (r *ListScannedAssetsMetadataOptionalParameters) WithFilterLastSuccessOrigin(filterLastSuccessOrigin string) *ListScannedAssetsMetadataOptionalParameters {
4015+
r.FilterLastSuccessOrigin = &filterLastSuccessOrigin
4016+
return r
4017+
}
4018+
4019+
// WithFilterLastSuccessEnv sets the corresponding parameter name and returns the struct.
4020+
func (r *ListScannedAssetsMetadataOptionalParameters) WithFilterLastSuccessEnv(filterLastSuccessEnv string) *ListScannedAssetsMetadataOptionalParameters {
4021+
r.FilterLastSuccessEnv = &filterLastSuccessEnv
4022+
return r
4023+
}
4024+
4025+
// ListScannedAssetsMetadata List scanned assets metadata.
4026+
// Get a list of security scanned assets metadata for an organization.
4027+
//
4028+
// ### Pagination
4029+
//
4030+
// For the "List Vulnerabilities" endpoint, see the [Pagination section](#pagination).
4031+
//
4032+
// ### Filtering
4033+
//
4034+
// For the "List Vulnerabilities" endpoint, see the [Filtering section](#filtering).
4035+
//
4036+
// ### Metadata
4037+
//
4038+
// For the "List Vulnerabilities" endpoint, see the [Metadata section](#metadata).
4039+
//
4040+
// ### Related endpoints
4041+
//
4042+
// This endpoint returns additional metadata for cloud resources that is not available from the standard resource endpoints. To access a richer dataset, call this endpoint together with the relevant resource endpoint(s) and merge (join) their results using the resource identifier.
4043+
//
4044+
// **Hosts**
4045+
//
4046+
// To enrich host data, join the response from the [Hosts](https://docs.datadoghq.com/api/latest/hosts/) endpoint with the response from the scanned-assets-metadata endpoint on the following key fields:
4047+
//
4048+
// | ENDPOINT | JOIN KEY | TYPE |
4049+
// | --- | --- | --- |
4050+
// | [/api/v1/hosts](https://docs.datadoghq.com/api/latest/hosts/) | host_list.host_name | string |
4051+
// | /api/v2/security/scanned-assets-metadata | data.attributes.asset.name | string |
4052+
//
4053+
// **Host Images**
4054+
//
4055+
// To enrich host image data, join the response from the [Hosts](https://docs.datadoghq.com/api/latest/hosts/) endpoint with the response from the scanned-assets-metadata endpoint on the following key fields:
4056+
//
4057+
// | ENDPOINT | JOIN KEY | TYPE |
4058+
// | --- | --- | --- |
4059+
// | [/api/v1/hosts](https://docs.datadoghq.com/api/latest/hosts/) | host_list.tags_by_source["Amazon Web Services"]["image"] | string |
4060+
// | /api/v2/security/scanned-assets-metadata | data.attributes.asset.name | string |
4061+
//
4062+
// **Container Images**
4063+
//
4064+
// To enrich container image data, join the response from the [Container Images](https://docs.datadoghq.com/api/latest/container-images/) endpoint with the response from the scanned-assets-metadata endpoint on the following key fields:
4065+
//
4066+
// | ENDPOINT | JOIN KEY | TYPE |
4067+
// | --- | --- | --- |
4068+
// | [/api/v2/container_images](https://docs.datadoghq.com/api/latest/container-images/) | `data.attributes.name`@`data.attributes.repo_digest` | string |
4069+
// | /api/v2/security/scanned-assets-metadata | data.attributes.asset.name | string |
4070+
func (a *SecurityMonitoringApi) ListScannedAssetsMetadata(ctx _context.Context, o ...ListScannedAssetsMetadataOptionalParameters) (ScannedAssetsMetadata, *_nethttp.Response, error) {
4071+
var (
4072+
localVarHTTPMethod = _nethttp.MethodGet
4073+
localVarPostBody interface{}
4074+
localVarReturnValue ScannedAssetsMetadata
4075+
optionalParams ListScannedAssetsMetadataOptionalParameters
4076+
)
4077+
4078+
if len(o) > 1 {
4079+
return localVarReturnValue, nil, datadog.ReportError("only one argument of type ListScannedAssetsMetadataOptionalParameters is allowed")
4080+
}
4081+
if len(o) == 1 {
4082+
optionalParams = o[0]
4083+
}
4084+
4085+
operationId := "v2.ListScannedAssetsMetadata"
4086+
isOperationEnabled := a.Client.Cfg.IsUnstableOperationEnabled(operationId)
4087+
if !isOperationEnabled {
4088+
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)}
4089+
}
4090+
if isOperationEnabled && a.Client.Cfg.Debug {
4091+
_log.Printf("WARNING: Using unstable operation '%s'", operationId)
4092+
}
4093+
4094+
localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.SecurityMonitoringApi.ListScannedAssetsMetadata")
4095+
if err != nil {
4096+
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
4097+
}
4098+
4099+
localVarPath := localBasePath + "/api/v2/security/scanned-assets-metadata"
4100+
4101+
localVarHeaderParams := make(map[string]string)
4102+
localVarQueryParams := _neturl.Values{}
4103+
localVarFormParams := _neturl.Values{}
4104+
if optionalParams.PageToken != nil {
4105+
localVarQueryParams.Add("page[token]", datadog.ParameterToString(*optionalParams.PageToken, ""))
4106+
}
4107+
if optionalParams.PageNumber != nil {
4108+
localVarQueryParams.Add("page[number]", datadog.ParameterToString(*optionalParams.PageNumber, ""))
4109+
}
4110+
if optionalParams.FilterAssetType != nil {
4111+
localVarQueryParams.Add("filter[asset.type]", datadog.ParameterToString(*optionalParams.FilterAssetType, ""))
4112+
}
4113+
if optionalParams.FilterAssetName != nil {
4114+
localVarQueryParams.Add("filter[asset.name]", datadog.ParameterToString(*optionalParams.FilterAssetName, ""))
4115+
}
4116+
if optionalParams.FilterLastSuccessOrigin != nil {
4117+
localVarQueryParams.Add("filter[last_success.origin]", datadog.ParameterToString(*optionalParams.FilterLastSuccessOrigin, ""))
4118+
}
4119+
if optionalParams.FilterLastSuccessEnv != nil {
4120+
localVarQueryParams.Add("filter[last_success.env]", datadog.ParameterToString(*optionalParams.FilterLastSuccessEnv, ""))
4121+
}
4122+
localVarHeaderParams["Accept"] = "application/json"
4123+
4124+
if a.Client.Cfg.DelegatedTokenConfig != nil {
4125+
err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig)
4126+
if err != nil {
4127+
return localVarReturnValue, nil, err
4128+
}
4129+
} else {
4130+
datadog.SetAuthKeys(
4131+
ctx,
4132+
&localVarHeaderParams,
4133+
[2]string{"apiKeyAuth", "DD-API-KEY"},
4134+
[2]string{"appKeyAuth", "DD-APPLICATION-KEY"},
4135+
)
4136+
}
4137+
req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil)
4138+
if err != nil {
4139+
return localVarReturnValue, nil, err
4140+
}
4141+
4142+
localVarHTTPResponse, err := a.Client.CallAPI(req)
4143+
if err != nil || localVarHTTPResponse == nil {
4144+
return localVarReturnValue, localVarHTTPResponse, err
4145+
}
4146+
4147+
localVarBody, err := datadog.ReadBody(localVarHTTPResponse)
4148+
if err != nil {
4149+
return localVarReturnValue, localVarHTTPResponse, err
4150+
}
4151+
4152+
if localVarHTTPResponse.StatusCode >= 300 {
4153+
newErr := datadog.GenericOpenAPIError{
4154+
ErrorBody: localVarBody,
4155+
ErrorMessage: localVarHTTPResponse.Status,
4156+
}
4157+
if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 {
4158+
var v JSONAPIErrorResponse
4159+
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
4160+
if err != nil {
4161+
return localVarReturnValue, localVarHTTPResponse, newErr
4162+
}
4163+
newErr.ErrorModel = v
4164+
return localVarReturnValue, localVarHTTPResponse, newErr
4165+
}
4166+
if localVarHTTPResponse.StatusCode == 429 {
4167+
var v APIErrorResponse
4168+
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
4169+
if err != nil {
4170+
return localVarReturnValue, localVarHTTPResponse, newErr
4171+
}
4172+
newErr.ErrorModel = v
4173+
}
4174+
return localVarReturnValue, localVarHTTPResponse, newErr
4175+
}
4176+
4177+
err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
4178+
if err != nil {
4179+
newErr := datadog.GenericOpenAPIError{
4180+
ErrorBody: localVarBody,
4181+
ErrorMessage: err.Error(),
4182+
}
4183+
return localVarReturnValue, localVarHTTPResponse, newErr
4184+
}
4185+
4186+
return localVarReturnValue, localVarHTTPResponse, nil
4187+
}
4188+
39634189
// ListSecurityFilters Get all security filters.
39644190
// Get the list of configured security filters with their definitions.
39654191
func (a *SecurityMonitoringApi) ListSecurityFilters(ctx _context.Context) (SecurityFiltersResponse, *_nethttp.Response, error) {
@@ -4983,6 +5209,8 @@ func (r *ListVulnerabilitiesOptionalParameters) WithFilterAssetOperatingSystemVe
49835209
//
49845210
// This token can then be used in the subsequent paginated requests.
49855211
//
5212+
// *Note: The first request may take longer to complete than subsequent requests.*
5213+
//
49865214
// #### Subsequent requests
49875215
//
49885216
// Any request containing valid `page[token]` and `page[number]` parameters will be considered a subsequent request.
@@ -4991,6 +5219,8 @@ func (r *ListVulnerabilitiesOptionalParameters) WithFilterAssetOperatingSystemVe
49915219
//
49925220
// If the page `number` is invalid, a `400` response will be returned.
49935221
//
5222+
// The returned `token` is valid for all requests in the pagination sequence. To send paginated requests in parallel, reuse the same `token` and change only the `page[number]` parameter.
5223+
//
49945224
// ### Filtering
49955225
//
49965226
// The request can include some filter parameters to filter the data to be retrieved. The format of the filter parameters follows the [JSON:API format](https://jsonapi.org/format/#fetching-filtering): `filter[$prop_name]`, where `prop_name` is the property name in the entity being filtered by.
@@ -5024,6 +5254,11 @@ func (r *ListVulnerabilitiesOptionalParameters) WithFilterAssetOperatingSystemVe
50245254
// }
50255255
//
50265256
// ```
5257+
// ### Extensions
5258+
//
5259+
// Requests may include extensions to modify the behavior of the requested endpoint. The filter parameters follow the [JSON:API format](https://jsonapi.org/extensions/#extensions) format: `ext:$extension_name`, where `extension_name` is the name of the modifier that is being applied.
5260+
//
5261+
// Extensions can only include one value: `ext:modifier=value`.
50275262
func (a *SecurityMonitoringApi) ListVulnerabilities(ctx _context.Context, o ...ListVulnerabilitiesOptionalParameters) (ListVulnerabilitiesResponse, *_nethttp.Response, error) {
50285263
var (
50295264
localVarHTTPMethod = _nethttp.MethodGet
@@ -5098,7 +5333,7 @@ func (a *SecurityMonitoringApi) ListVulnerabilities(ctx _context.Context, o ...L
50985333
localVarQueryParams.Add("filter[library.version]", datadog.ParameterToString(*optionalParams.FilterLibraryVersion, ""))
50995334
}
51005335
if optionalParams.FilterAdvisoryId != nil {
5101-
localVarQueryParams.Add("filter[advisory_id]", datadog.ParameterToString(*optionalParams.FilterAdvisoryId, ""))
5336+
localVarQueryParams.Add("filter[advisory.id]", datadog.ParameterToString(*optionalParams.FilterAdvisoryId, ""))
51025337
}
51035338
if optionalParams.FilterRisksExploitationProbability != nil {
51045339
localVarQueryParams.Add("filter[risks.exploitation_probability]", datadog.ParameterToString(*optionalParams.FilterRisksExploitationProbability, ""))
@@ -5423,7 +5658,7 @@ func (a *SecurityMonitoringApi) ListVulnerableAssets(ctx _context.Context, o ...
54235658
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
54245659
}
54255660

5426-
localVarPath := localBasePath + "/api/v2/security/assets"
5661+
localVarPath := localBasePath + "/api/v2/security/vulnerable-assets"
54275662

54285663
localVarHeaderParams := make(map[string]string)
54295664
localVarQueryParams := _neturl.Values{}

api/datadogV2/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@
502502
// - [SecurityMonitoringApi.ListAssetsSBOMs]
503503
// - [SecurityMonitoringApi.ListFindings]
504504
// - [SecurityMonitoringApi.ListHistoricalJobs]
505+
// - [SecurityMonitoringApi.ListScannedAssetsMetadata]
505506
// - [SecurityMonitoringApi.ListSecurityFilters]
506507
// - [SecurityMonitoringApi.ListSecurityMonitoringHistsignals]
507508
// - [SecurityMonitoringApi.ListSecurityMonitoringRules]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
package datadogV2
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
11+
)
12+
13+
// CloudAssetType The cloud asset type
14+
type CloudAssetType string
15+
16+
// List of CloudAssetType.
17+
const (
18+
CLOUDASSETTYPE_HOST CloudAssetType = "Host"
19+
CLOUDASSETTYPE_HOST_IMAGE CloudAssetType = "HostImage"
20+
CLOUDASSETTYPE_IMAGE CloudAssetType = "Image"
21+
)
22+
23+
var allowedCloudAssetTypeEnumValues = []CloudAssetType{
24+
CLOUDASSETTYPE_HOST,
25+
CLOUDASSETTYPE_HOST_IMAGE,
26+
CLOUDASSETTYPE_IMAGE,
27+
}
28+
29+
// GetAllowedValues reeturns the list of possible values.
30+
func (v *CloudAssetType) GetAllowedValues() []CloudAssetType {
31+
return allowedCloudAssetTypeEnumValues
32+
}
33+
34+
// UnmarshalJSON deserializes the given payload.
35+
func (v *CloudAssetType) UnmarshalJSON(src []byte) error {
36+
var value string
37+
err := datadog.Unmarshal(src, &value)
38+
if err != nil {
39+
return err
40+
}
41+
*v = CloudAssetType(value)
42+
return nil
43+
}
44+
45+
// NewCloudAssetTypeFromValue returns a pointer to a valid CloudAssetType
46+
// for the value passed as argument, or an error if the value passed is not allowed by the enum.
47+
func NewCloudAssetTypeFromValue(v string) (*CloudAssetType, error) {
48+
ev := CloudAssetType(v)
49+
if ev.IsValid() {
50+
return &ev, nil
51+
}
52+
return nil, fmt.Errorf("invalid value '%v' for CloudAssetType: valid values are %v", v, allowedCloudAssetTypeEnumValues)
53+
}
54+
55+
// IsValid return true if the value is valid for the enum, false otherwise.
56+
func (v CloudAssetType) IsValid() bool {
57+
for _, existing := range allowedCloudAssetTypeEnumValues {
58+
if existing == v {
59+
return true
60+
}
61+
}
62+
return false
63+
}
64+
65+
// Ptr returns reference to CloudAssetType value.
66+
func (v CloudAssetType) Ptr() *CloudAssetType {
67+
return &v
68+
}

0 commit comments

Comments
 (0)