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

Update spec to change findings limit and security monitoring menu order #1335

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": "2023-04-21 15:11:53.532633",
"spec_repo_commit": "7fa27269"
"regenerated": "2023-04-24 09:04:24.530205",
"spec_repo_commit": "6be43f02"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2023-04-21 15:11:53.545929",
"spec_repo_commit": "7fa27269"
"regenerated": "2023-04-24 09:04:24.543938",
"spec_repo_commit": "6be43f02"
}
}
}
29 changes: 26 additions & 3 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19455,15 +19455,33 @@ paths:
- Roles
/api/v2/posture_management/findings:
get:
description: Get a list of CSPM findings.
description: "Get a list of CSPM findings.\n\n### Filtering\n\nFilters can be
applied by appending query parameters to the URL.\n\n - Using a single filter:
`?filter[attribute_key]=attribute_value`\n - Chaining filters: `?filter[attribute_key]=attribute_value&filter[attribute_key]=attribute_value...`\n
\ - Filtering on tags: `?filter[tags]=tag_key:tag_value&filter[tags]=tag_key_2:tag_value_2`\n\nHere,
`attribute_key` can be any of the filter keys described further below.\n\nQuery
parameters of type `integer` support comparison operators (`>`, `>=`, `<`,
`<=`). This is particularly useful when filtering by `evaluation_changed_at`
or `resource_discovery_timestamp`. For example: `?filter[evaluation_changed_at]=>20123123121`.\n\nYou
can also use the negation operator on strings. For example, use `filter[resource_type]=-aws*`
to filter for any non-AWS resources.\n\nThe operator must come after the equal
sign. For example, to filter with the `>=` operator, add the operator after
the equal sign: `filter[evaluation_changed_at]=>=1678809373257`.\n\n### Response\n\nThe
response includes an array of finding objects, pagination metadata, and a
count of items that match the query.\n\nEach finding object contains the following:\n\n-
The finding ID that can be used in a `GetFinding` request to retrieve the
full finding details.\n- Core attributes, including status, evaluation, high-level
resource details, muted state, and rule details.\n- `evaluation_changed_at`
and `resource_discovery_date` time stamps.\n- An array of associated tags.\n"
operationId: ListFindings
parameters:
- description: Limit the number of findings returned.
- description: Limit the number of findings returned. Must be <= 1000.
example: 50
in: query
name: limit
name: page[limit]
required: false
schema:
default: 100
format: int64
maximum: 1000
minimum: 1
Expand Down Expand Up @@ -19573,6 +19591,11 @@ paths:
summary: List findings
tags:
- Security Monitoring
x-pagination:
cursorParam: page[cursor]
cursorPath: meta.page.cursor
limitParam: page[limit]
resultsPath: data
x-unstable: '**Note**: This endpoint is in public beta.

If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
Expand Down
8 changes: 8 additions & 0 deletions examples/v2/security-monitoring/ListFindings_3865842421.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# List findings returns "OK" response with pagination

require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.unstable_operations["v2.list_findings".to_sym] = true
end
api_instance = DatadogAPIClient::V2::SecurityMonitoringAPI.new
api_instance.list_findings_with_pagination() { |item| puts item }
2 changes: 1 addition & 1 deletion features/scenarios_model_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@
"body" => "RelationshipToUser",
},
"v2.ListFindings" => {
"limit" => "Integer",
"page_limit" => "Integer",
"snapshot_timestamp" => "Integer",
"page_cursor" => "String",
"filter_tags" => "String",
Expand Down
7 changes: 7 additions & 0 deletions features/v2/security_monitoring.feature
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ Feature: Security Monitoring
Then the response status is 200 OK
And the response "data[0].type" is equal to "finding"

@generated @skip @team:DataDog/cloud-security-posture-management @with-pagination
Scenario: List findings returns "OK" response with pagination
Given operation "ListFindings" enabled
And new "ListFindings" request
When the request with pagination is sent
Then the response status is 200 OK

@generated @skip @team:DataDog/k9-cloud-security-platform
Scenario: List rules returns "Bad Request" response
Given new "ListSecurityMonitoringRules" request
Expand Down
61 changes: 55 additions & 6 deletions lib/datadog_api_client/v2/api/security_monitoring_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,36 @@ def list_findings(opts = {})
#
# Get a list of CSPM findings.
#
# ### Filtering
#
# Filters can be applied by appending query parameters to the URL.
#
# - Using a single filter: `?filter[attribute_key]=attribute_value`
# - Chaining filters: `?filter[attribute_key]=attribute_value&filter[attribute_key]=attribute_value...`
# - Filtering on tags: `?filter[tags]=tag_key:tag_value&filter[tags]=tag_key_2:tag_value_2`
#
# Here, `attribute_key` can be any of the filter keys described further below.
#
# Query parameters of type `integer` support comparison operators (`>`, `>=`, `<`, `<=`). This is particularly useful when filtering by `evaluation_changed_at` or `resource_discovery_timestamp`. For example: `?filter[evaluation_changed_at]=>20123123121`.
#
# You can also use the negation operator on strings. For example, use `filter[resource_type]=-aws*` to filter for any non-AWS resources.
#
# The operator must come after the equal sign. For example, to filter with the `>=` operator, add the operator after the equal sign: `filter[evaluation_changed_at]=>=1678809373257`.
#
# ### Response
#
# The response includes an array of finding objects, pagination metadata, and a count of items that match the query.
#
# Each finding object contains the following:
#
# - The finding ID that can be used in a `GetFinding` request to retrieve the full finding details.
# - Core attributes, including status, evaluation, high-level resource details, muted state, and rule details.
# - `evaluation_changed_at` and `resource_discovery_date` time stamps.
# - An array of associated tags.
#
#
# @param opts [Hash] the optional parameters
# @option opts [Integer] :limit Limit the number of findings returned.
# @option opts [Integer] :page_limit Limit the number of findings returned. Must be <= 1000.
# @option opts [Integer] :snapshot_timestamp Return findings for a given snapshot of time (Unix ms).
# @option opts [String] :page_cursor Return the next page of findings pointed to by the cursor.
# @option opts [String] :filter_tags Return findings that have these associated tags (repeatable).
Expand All @@ -812,11 +840,11 @@ def list_findings_with_http_info(opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: SecurityMonitoringAPI.list_findings ...'
end
if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] > 1000
fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling SecurityMonitoringAPI.list_findings, must be smaller than or equal to 1000.'
if @api_client.config.client_side_validation && !opts[:'page_limit'].nil? && opts[:'page_limit'] > 1000
fail ArgumentError, 'invalid value for "opts[:"page_limit"]" when calling SecurityMonitoringAPI.list_findings, must be smaller than or equal to 1000.'
end
if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] < 1
fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling SecurityMonitoringAPI.list_findings, must be greater than or equal to 1.'
if @api_client.config.client_side_validation && !opts[:'page_limit'].nil? && opts[:'page_limit'] < 1
fail ArgumentError, 'invalid value for "opts[:"page_limit"]" when calling SecurityMonitoringAPI.list_findings, must be greater than or equal to 1.'
end
if @api_client.config.client_side_validation && !opts[:'snapshot_timestamp'].nil? && opts[:'snapshot_timestamp'] < 1
fail ArgumentError, 'invalid value for "opts[:"snapshot_timestamp"]" when calling SecurityMonitoringAPI.list_findings, must be greater than or equal to 1.'
Expand All @@ -834,7 +862,7 @@ def list_findings_with_http_info(opts = {})

# query parameters
query_params = opts[:query_params] || {}
query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
query_params[:'page[limit]'] = opts[:'page_limit'] if !opts[:'page_limit'].nil?
query_params[:'snapshot_timestamp'] = opts[:'snapshot_timestamp'] if !opts[:'snapshot_timestamp'].nil?
query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil?
query_params[:'filter[tags]'] = opts[:'filter_tags'] if !opts[:'filter_tags'].nil?
Expand Down Expand Up @@ -882,6 +910,27 @@ def list_findings_with_http_info(opts = {})
return data, status_code, headers
end

# List findings.
#
# Provide a paginated version of {#list_findings}, returning all items.
#
# To use it you need to use a block: list_findings_with_pagination { |item| p item }
#
# @yield [Finding] Paginated items
def list_findings_with_pagination(opts = {})
api_version = "V2"
page_size = @api_client.get_attribute_from_path(opts, "page_limit", 100)
@api_client.set_attribute_from_path(api_version, opts, "page_limit", FindingStatus, page_size)
while true do
response = list_findings(opts)
@api_client.get_attribute_from_path(response, "data").each { |item| yield(item) }
if @api_client.get_attribute_from_path(response, "data").length < page_size
break
end
@api_client.set_attribute_from_path(api_version, opts, "page_cursor", FindingStatus, @api_client.get_attribute_from_path(response, "meta.page.cursor"))
end
end

# Get all security filters.
#
# @see #list_security_filters_with_http_info
Expand Down