From 421f4f0526d2714e06a0834bc8ff5ad0d72bb0f3 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 4 Mar 2020 11:22:30 -0700 Subject: [PATCH] feat(security_center): Add NotificationConfig * Add SecurityCenter#create_notification_config * Add SecurityCenter#delete_notification_config * Add SecurityCenter#get_notification_config * Add SecurityCenter#list_notification_configs * Add SecurityCenter#update_notification_config --- .../lib/google/cloud/security_center/v1.rb | 1 + .../cloud/security_center/v1/asset_pb.rb | 2 +- .../securitycenter/v1/notification_config.rb | 75 ++++ .../v1/securitycenter_service.rb | 150 +++++-- .../v1/doc/google/protobuf/empty.rb | 29 ++ .../cloud/security_center/v1/finding_pb.rb | 2 +- .../cloud/security_center/v1/helpers.rb | 16 + .../v1/notification_config_pb.rb | 28 ++ .../v1/notification_message_pb.rb | 20 + .../v1/organization_settings_pb.rb | 2 +- .../v1/run_asset_discovery_response_pb.rb | 2 +- .../v1/security_center_client.rb | 370 ++++++++++++++-- .../v1/security_center_client_config.json | 25 ++ .../security_center/v1/security_marks_pb.rb | 2 +- .../v1/securitycenter_service_pb.rb | 31 ++ .../v1/securitycenter_service_services_pb.rb | 14 +- .../cloud/security_center/v1/source_pb.rb | 2 +- google-cloud-security_center/synth.metadata | 12 +- .../cloud/security_center/v1/helpers_test.rb | 26 ++ .../v1/security_center_client_test.rb | 407 ++++++++++++++++++ 20 files changed, 1132 insertions(+), 84 deletions(-) create mode 100644 google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/cloud/securitycenter/v1/notification_config.rb create mode 100644 google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/protobuf/empty.rb create mode 100644 google-cloud-security_center/lib/google/cloud/security_center/v1/notification_config_pb.rb create mode 100644 google-cloud-security_center/lib/google/cloud/security_center/v1/notification_message_pb.rb diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1.rb index 89e32f6e4b98..c0ca3eebfab1 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1.rb @@ -15,6 +15,7 @@ require "google/cloud/security_center/v1/security_center_client" require "google/cloud/security_center/v1/helpers" +require "google/cloud/security_center/v1/notification_message_pb" require "google/cloud/security_center/v1/run_asset_discovery_response_pb" module Google diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/asset_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/asset_pb.rb index 61e01267a416..bff232c8ef54 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/asset_pb.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/asset_pb.rb @@ -4,11 +4,11 @@ require 'google/protobuf' +require 'google/api/annotations_pb' require 'google/api/resource_pb' require 'google/cloud/security_center/v1/security_marks_pb' require 'google/protobuf/struct_pb' require 'google/protobuf/timestamp_pb' -require 'google/api/annotations_pb' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "google.cloud.securitycenter.v1.Asset" do optional :name, :string, 1 diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/cloud/securitycenter/v1/notification_config.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/cloud/securitycenter/v1/notification_config.rb new file mode 100644 index 000000000000..8f0ecc76ecfc --- /dev/null +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/cloud/securitycenter/v1/notification_config.rb @@ -0,0 +1,75 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +module Google + module Cloud + module Securitycenter + module V1 + # Cloud Security Command Center (Cloud SCC) notification configs. + # + # A notification config is a Cloud SCC resource that contains the configuration + # to send notifications for create/update events of findings, assets and etc. + # @!attribute [rw] name + # @return [String] + # The relative resource name of this notification config. See: + # https://cloud.google.com/apis/design/resource_names#relative_resource_name + # Example: + # "organizations/{organization_id}/notificationConfigs/notify_public_bucket". + # @!attribute [rw] description + # @return [String] + # The description of the notification config (max of 1024 characters). + # @!attribute [rw] pubsub_topic + # @return [String] + # The PubSub topic to send notifications to. Its format is + # "projects/[project_id]/topics/[topic]". + # @!attribute [rw] service_account + # @return [String] + # Output only. The service account that needs "pubsub.topics.publish" + # permission to publish to the PubSub topic. + # @!attribute [rw] streaming_config + # @return [Google::Cloud::SecurityCenter::V1::NotificationConfig::StreamingConfig] + # The config for triggering streaming-based notifications. + class NotificationConfig + # The config for streaming-based notifications, which send each event as soon + # as it is detected. + # @!attribute [rw] filter + # @return [String] + # Expression that defines the filter to apply across create/update events + # of assets or findings as specified by the event type. The expression is a + # list of zero or more restrictions combined via logical operators `AND` + # and `OR`. Parentheses are supported, and `OR` has higher precedence than + # `AND`. + # + # Restrictions have the form ` ` and may have a + # `-` character in front of them to indicate negation. The fields map to + # those defined in the corresponding resource. + # + # The supported operators are: + # + # * `=` for all value types. + # * `>`, `<`, `>=`, `<=` for integer values. + # * `:`, meaning substring matching, for strings. + # + # The supported value types are: + # + # * string literals in quotes. + # * integer literals without quotes. + # * boolean literals `true` and `false` without quotes. + class StreamingConfig; end + end + end + end + end +end \ No newline at end of file diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/cloud/securitycenter/v1/securitycenter_service.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/cloud/securitycenter/v1/securitycenter_service.rb index dcac06753dd6..b746bd91ca2e 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/cloud/securitycenter/v1/securitycenter_service.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/cloud/securitycenter/v1/securitycenter_service.rb @@ -29,10 +29,28 @@ module V1 # greater than 0 characters in length. # @!attribute [rw] finding # @return [Google::Cloud::SecurityCenter::V1::Finding] - # Required. The Finding being created. The name and security_marks will be ignored as - # they are both output only fields on this resource. + # Required. The Finding being created. The name and security_marks will be + # ignored as they are both output only fields on this resource. class CreateFindingRequest; end + # Request message for creating a notification config. + # @!attribute [rw] parent + # @return [String] + # Required. Resource name of the new notification config's parent. Its format + # is "organizations/[organization_id]". + # @!attribute [rw] config_id + # @return [String] + # Required. + # Unique identifier provided by the client within the parent scope. + # It must be between 1 and 128 characters, and contains alphanumeric + # characters, underscores or hyphens only. + # @!attribute [rw] notification_config + # @return [Google::Cloud::SecurityCenter::V1::NotificationConfig] + # Required. The notification config being created. The name and the service + # account will be ignored as they are both output only fields on this + # resource. + class CreateNotificationConfigRequest; end + # Request message for creating a source. # @!attribute [rw] parent # @return [String] @@ -40,15 +58,29 @@ class CreateFindingRequest; end # "organizations/[organization_id]". # @!attribute [rw] source # @return [Google::Cloud::SecurityCenter::V1::Source] - # Required. The Source being created, only the display_name and description will be - # used. All other fields will be ignored. + # Required. The Source being created, only the display_name and description + # will be used. All other fields will be ignored. class CreateSourceRequest; end + # Request message for deleting a notification config. + # @!attribute [rw] name + # @return [String] + # Required. Name of the notification config to delete. Its format is + # "organizations/[organization_id]/notificationConfigs/[config_id]". + class DeleteNotificationConfigRequest; end + + # Request message for getting a notification config. + # @!attribute [rw] name + # @return [String] + # Required. Name of the notification config to get. Its format is + # "organizations/[organization_id]/notificationConfigs/[config_id]". + class GetNotificationConfigRequest; end + # Request message for getting organization settings. # @!attribute [rw] name # @return [String] - # Required. Name of the organization to get organization settings for. Its format is - # "organizations/[organization_id]/organizationSettings". + # Required. Name of the organization to get organization settings for. Its + # format is "organizations/[organization_id]/organizationSettings". class GetOrganizationSettingsRequest; end # Request message for getting a source. @@ -123,9 +155,9 @@ class GetSourceRequest; end # For example, `resource_properties.size = 100` is a valid filter string. # @!attribute [rw] group_by # @return [String] - # Required. Expression that defines what assets fields to use for grouping. The string - # value should follow SQL syntax: comma separated list of fields. For - # example: + # Required. Expression that defines what assets fields to use for grouping. + # The string value should follow SQL syntax: comma separated list of fields. + # For example: # "security_center_properties.resource_project,security_center_properties.project". # # The following fields are supported when compare_duration is not set: @@ -259,9 +291,9 @@ class GroupAssetsResponse; end # For example, `source_properties.size = 100` is a valid filter string. # @!attribute [rw] group_by # @return [String] - # Required. Expression that defines what assets fields to use for grouping (including - # `state_change`). The string value should follow SQL syntax: comma separated - # list of fields. For example: "parent,resource_name". + # Required. Expression that defines what assets fields to use for grouping + # (including `state_change`). The string value should follow SQL syntax: + # comma separated list of fields. For example: "parent,resource_name". # # The following fields are supported: # @@ -294,12 +326,18 @@ class GroupAssetsResponse; end # # Possible "state_change" values when compare_duration is specified: # - # * "CHANGED": indicates that the finding was present at the start of - # compare_duration, but changed its state at read_time. - # * "UNCHANGED": indicates that the finding was present at the start of - # compare_duration and did not change state at read_time. - # * "ADDED": indicates that the finding was not present at the start - # of compare_duration, but was present at read_time. + # * "CHANGED": indicates that the finding was present and matched the given + # filter at the start of compare_duration, but changed its + # state at read_time. + # * "UNCHANGED": indicates that the finding was present and matched the given + # filter at the start of compare_duration and did not change + # state at read_time. + # * "ADDED": indicates that the finding did not match the given filter or + # was not present at the start of compare_duration, but was + # present at read_time. + # * "REMOVED": indicates that the finding was present and matched the + # filter at the start of compare_duration, but did not match + # the filter at read_time. # # If compare_duration is not specified, then the only possible state_change # is "UNUSED", which will be the state_change set for all findings present @@ -345,11 +383,37 @@ class GroupFindingsResponse; end # Total count of resources for the given properties. class GroupResult; end + # Request message for listing notification configs. + # @!attribute [rw] parent + # @return [String] + # Required. Name of the organization to list notification configs. + # Its format is "organizations/[organization_id]". + # @!attribute [rw] page_token + # @return [String] + # The value returned by the last `ListNotificationConfigsResponse`; indicates + # that this is a continuation of a prior `ListNotificationConfigs` call, and + # that the system should return the next page of data. + # @!attribute [rw] page_size + # @return [Integer] + # The maximum number of results to return in a single response. Default is + # 10, minimum is 1, maximum is 1000. + class ListNotificationConfigsRequest; end + + # Response message for listing notification configs. + # @!attribute [rw] notification_configs + # @return [Array] + # Notification configs belonging to the requested parent. + # @!attribute [rw] next_page_token + # @return [String] + # Token to retrieve the next page of results, or empty if there are no more + # results. + class ListNotificationConfigsResponse; end + # Request message for listing sources. # @!attribute [rw] parent # @return [String] - # Required. Resource name of the parent of sources to list. Its format should be - # "organizations/[organization_id]". + # Required. Resource name of the parent of sources to list. Its format should + # be "organizations/[organization_id]". # @!attribute [rw] page_token # @return [String] # The value returned by the last `ListSourcesResponse`; indicates @@ -491,9 +555,8 @@ class ListSourcesResponse; end # read_time. # @!attribute [rw] field_mask # @return [Google::Protobuf::FieldMask] - # Optional. A field mask to specify the ListAssetsResult fields to be listed in the - # response. - # An empty field mask will list all fields. + # Optional. A field mask to specify the ListAssetsResult fields to be listed + # in the response. An empty field mask will list all fields. # @!attribute [rw] page_token # @return [String] # The value returned by the last `ListAssetsResponse`; indicates @@ -644,20 +707,26 @@ module StateChange # # Possible "state_change" values when compare_duration is specified: # - # * "CHANGED": indicates that the finding was present at the start of - # compare_duration, but changed its state at read_time. - # * "UNCHANGED": indicates that the finding was present at the start of - # compare_duration and did not change state at read_time. - # * "ADDED": indicates that the finding was not present at the start - # of compare_duration, but was present at read_time. + # * "CHANGED": indicates that the finding was present and matched the given + # filter at the start of compare_duration, but changed its + # state at read_time. + # * "UNCHANGED": indicates that the finding was present and matched the given + # filter at the start of compare_duration and did not change + # state at read_time. + # * "ADDED": indicates that the finding did not match the given filter or + # was not present at the start of compare_duration, but was + # present at read_time. + # * "REMOVED": indicates that the finding was present and matched the + # filter at the start of compare_duration, but did not match + # the filter at read_time. # # If compare_duration is not specified, then the only possible state_change # is "UNUSED", which will be the state_change set for all findings present at # read_time. # @!attribute [rw] field_mask # @return [Google::Protobuf::FieldMask] - # Optional. A field mask to specify the Finding fields to be listed in the response. - # An empty field mask will list all fields. + # Optional. A field mask to specify the Finding fields to be listed in the + # response. An empty field mask will list all fields. # @!attribute [rw] page_token # @return [String] # The value returned by the last `ListFindingsResponse`; indicates @@ -763,15 +832,15 @@ class SetFindingStateRequest; end # Request message for running asset discovery for an organization. # @!attribute [rw] parent # @return [String] - # Required. Name of the organization to run asset discovery for. Its format is - # "organizations/[organization_id]". + # Required. Name of the organization to run asset discovery for. Its format + # is "organizations/[organization_id]". class RunAssetDiscoveryRequest; end # Request message for updating or creating a finding. # @!attribute [rw] finding # @return [Google::Cloud::SecurityCenter::V1::Finding] - # Required. The finding resource to update or create if it does not already exist. - # parent, security_marks, and update_time will be ignored. + # Required. The finding resource to update or create if it does not already + # exist. parent, security_marks, and update_time will be ignored. # # In the case of creation, the finding id portion of the name must be # alphanumeric and less than or equal to 32 characters and greater than 0 @@ -787,6 +856,17 @@ class RunAssetDiscoveryRequest; end # mask. class UpdateFindingRequest; end + # Request message for updating a notification config. + # @!attribute [rw] notification_config + # @return [Google::Cloud::SecurityCenter::V1::NotificationConfig] + # Required. The notification config to update. + # @!attribute [rw] update_mask + # @return [Google::Protobuf::FieldMask] + # The FieldMask to use when updating the notification config. + # + # If empty all mutable fields will be updated. + class UpdateNotificationConfigRequest; end + # Request message for updating an organization's settings. # @!attribute [rw] organization_settings # @return [Google::Cloud::SecurityCenter::V1::OrganizationSettings] diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/protobuf/empty.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/protobuf/empty.rb new file mode 100644 index 000000000000..2e207c7c3e95 --- /dev/null +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/doc/google/protobuf/empty.rb @@ -0,0 +1,29 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +module Google + module Protobuf + # A generic empty message that you can re-use to avoid defining duplicated + # empty messages in your APIs. A typical example is to use it as the request + # or the response type of an API method. For instance: + # + # service Foo { + # rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); + # } + # + # The JSON representation for `Empty` is empty JSON object `{}`. + class Empty; end + end +end \ No newline at end of file diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/finding_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/finding_pb.rb index a540b350b919..06caa26a7c5f 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/finding_pb.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/finding_pb.rb @@ -4,12 +4,12 @@ require 'google/protobuf' +require 'google/api/annotations_pb' require 'google/api/field_behavior_pb' require 'google/api/resource_pb' require 'google/cloud/security_center/v1/security_marks_pb' require 'google/protobuf/struct_pb' require 'google/protobuf/timestamp_pb' -require 'google/api/annotations_pb' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "google.cloud.securitycenter.v1.Finding" do optional :name, :string, 1 diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/helpers.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/helpers.rb index 5403a2948c40..48b86b812775 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/helpers.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/helpers.rb @@ -44,6 +44,14 @@ def finding_security_marks_path organization, source, finding self.class.finding_security_marks_path organization, source, finding end + # Alias for Google::Cloud::SecurityCenter::V1::SecurityCenterClient.notification_config_path. + # @param organization [String] + # @param notification_config [String] + # @return [String] + def notification_config_path organization, notification_config + self.class.notification_config_path organization, notification_config + end + # Alias for Google::Cloud::SecurityCenter::V1::SecurityCenterClient.organization_path. # @param organization [String] # @return [String] @@ -65,6 +73,14 @@ def organization_settings_path organization def source_path organization, source self.class.source_path organization, source end + + # Alias for Google::Cloud::SecurityCenter::V1::SecurityCenterClient.topic_path. + # @param project [String] + # @param topic [String] + # @return [String] + def topic_path project, topic + self.class.topic_path project, topic + end end end end diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/notification_config_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/notification_config_pb.rb new file mode 100644 index 000000000000..4cf14154e225 --- /dev/null +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/notification_config_pb.rb @@ -0,0 +1,28 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/security_center/v1/notification_config.proto + + +require 'google/protobuf' + +require 'google/api/annotations_pb' +require 'google/api/field_behavior_pb' +require 'google/api/resource_pb' +Google::Protobuf::DescriptorPool.generated_pool.build do + add_message "google.cloud.securitycenter.v1.NotificationConfig" do + optional :name, :string, 1 + optional :description, :string, 2 + optional :pubsub_topic, :string, 3 + optional :service_account, :string, 4 + oneof :notify_config do + optional :streaming_config, :message, 5, "google.cloud.securitycenter.v1.NotificationConfig.StreamingConfig" + end + end + add_message "google.cloud.securitycenter.v1.NotificationConfig.StreamingConfig" do + optional :filter, :string, 1 + end +end + +module Google::Cloud::SecurityCenter::V1 + NotificationConfig = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.NotificationConfig").msgclass + NotificationConfig::StreamingConfig = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.NotificationConfig.StreamingConfig").msgclass +end diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/notification_message_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/notification_message_pb.rb new file mode 100644 index 000000000000..edf37ef29447 --- /dev/null +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/notification_message_pb.rb @@ -0,0 +1,20 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/security_center/v1/notification_message.proto + + +require 'google/protobuf' + +require 'google/api/annotations_pb' +require 'google/cloud/security_center/v1/finding_pb' +Google::Protobuf::DescriptorPool.generated_pool.build do + add_message "google.cloud.securitycenter.v1.NotificationMessage" do + optional :notification_config_name, :string, 1 + oneof :event do + optional :finding, :message, 2, "google.cloud.securitycenter.v1.Finding" + end + end +end + +module Google::Cloud::SecurityCenter::V1 + NotificationMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.NotificationMessage").msgclass +end diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/organization_settings_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/organization_settings_pb.rb index 173b0218f7f4..ec38a6d5af0d 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/organization_settings_pb.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/organization_settings_pb.rb @@ -4,8 +4,8 @@ require 'google/protobuf' -require 'google/api/resource_pb' require 'google/api/annotations_pb' +require 'google/api/resource_pb' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "google.cloud.securitycenter.v1.OrganizationSettings" do optional :name, :string, 1 diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/run_asset_discovery_response_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/run_asset_discovery_response_pb.rb index 2b2693ac66f3..0bd59976228e 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/run_asset_discovery_response_pb.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/run_asset_discovery_response_pb.rb @@ -4,8 +4,8 @@ require 'google/protobuf' -require 'google/protobuf/duration_pb' require 'google/api/annotations_pb' +require 'google/protobuf/duration_pb' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "google.cloud.securitycenter.v1.RunAssetDiscoveryResponse" do optional :state, :enum, 1, "google.cloud.securitycenter.v1.RunAssetDiscoveryResponse.State" diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/security_center_client.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/security_center_client.rb index c3052fcdc765..e0a250150fc7 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/security_center_client.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/security_center_client.rb @@ -72,6 +72,10 @@ class SecurityCenterClient "page_token", "next_page_token", "list_findings_results"), + "list_notification_configs" => Google::Gax::PageDescriptor.new( + "page_token", + "next_page_token", + "notification_configs"), "list_sources" => Google::Gax::PageDescriptor.new( "page_token", "next_page_token", @@ -109,6 +113,12 @@ class OperationsClient < Google::Longrunning::OperationsClient private_constant :FINDING_SECURITY_MARKS_PATH_TEMPLATE + NOTIFICATION_CONFIG_PATH_TEMPLATE = Google::Gax::PathTemplate.new( + "organizations/{organization}/notificationConfigs/{notification_config}" + ) + + private_constant :NOTIFICATION_CONFIG_PATH_TEMPLATE + ORGANIZATION_PATH_TEMPLATE = Google::Gax::PathTemplate.new( "organizations/{organization}" ) @@ -127,6 +137,12 @@ class OperationsClient < Google::Longrunning::OperationsClient private_constant :SOURCE_PATH_TEMPLATE + TOPIC_PATH_TEMPLATE = Google::Gax::PathTemplate.new( + "projects/{project}/topics/{topic}" + ) + + private_constant :TOPIC_PATH_TEMPLATE + # Returns a fully-qualified asset_security_marks resource name string. # @deprecated Multi-pattern resource names will have unified creation and parsing helper functions. # This helper function will be deleted in the next major version. @@ -168,6 +184,17 @@ def self.finding_security_marks_path organization, source, finding ) end + # Returns a fully-qualified notification_config resource name string. + # @param organization [String] + # @param notification_config [String] + # @return [String] + def self.notification_config_path organization, notification_config + NOTIFICATION_CONFIG_PATH_TEMPLATE.render( + :"organization" => organization, + :"notification_config" => notification_config + ) + end + # Returns a fully-qualified organization resource name string. # @param organization [String] # @return [String] @@ -197,6 +224,17 @@ def self.source_path organization, source ) end + # Returns a fully-qualified topic resource name string. + # @param project [String] + # @param topic [String] + # @return [String] + def self.topic_path project, topic + TOPIC_PATH_TEMPLATE.render( + :"project" => project, + :"topic" => topic + ) + end + # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc] # Provides the means for authenticating requests made by the client. This parameter can # be many types. @@ -366,6 +404,30 @@ def initialize \ {'parent' => request.parent} end ) + @create_notification_config = Google::Gax.create_api_call( + @security_center_stub.method(:create_notification_config), + defaults["create_notification_config"], + exception_transformer: exception_transformer, + params_extractor: proc do |request| + {'parent' => request.parent} + end + ) + @delete_notification_config = Google::Gax.create_api_call( + @security_center_stub.method(:delete_notification_config), + defaults["delete_notification_config"], + exception_transformer: exception_transformer, + params_extractor: proc do |request| + {'name' => request.name} + end + ) + @get_notification_config = Google::Gax.create_api_call( + @security_center_stub.method(:get_notification_config), + defaults["get_notification_config"], + exception_transformer: exception_transformer, + params_extractor: proc do |request| + {'name' => request.name} + end + ) @get_organization_settings = Google::Gax.create_api_call( @security_center_stub.method(:get_organization_settings), defaults["get_organization_settings"], @@ -398,6 +460,14 @@ def initialize \ {'parent' => request.parent} end ) + @list_notification_configs = Google::Gax.create_api_call( + @security_center_stub.method(:list_notification_configs), + defaults["list_notification_configs"], + exception_transformer: exception_transformer, + params_extractor: proc do |request| + {'parent' => request.parent} + end + ) @list_sources = Google::Gax.create_api_call( @security_center_stub.method(:list_sources), defaults["list_sources"], @@ -438,6 +508,14 @@ def initialize \ {'finding.name' => request.finding.name} end ) + @update_notification_config = Google::Gax.create_api_call( + @security_center_stub.method(:update_notification_config), + defaults["update_notification_config"], + exception_transformer: exception_transformer, + params_extractor: proc do |request| + {'notification_config.name' => request.notification_config.name} + end + ) @update_organization_settings = Google::Gax.create_api_call( @security_center_stub.method(:update_organization_settings), defaults["update_organization_settings"], @@ -513,9 +591,9 @@ def get_iam_policy \ # Required. Name of the organization to groupBy. Its format is # "organizations/[organization_id]". # @param group_by [String] - # Required. Expression that defines what assets fields to use for grouping. The string - # value should follow SQL syntax: comma separated list of fields. For - # example: + # Required. Expression that defines what assets fields to use for grouping. + # The string value should follow SQL syntax: comma separated list of fields. + # For example: # "security_center_properties.resource_project,security_center_properties.project". # # The following fields are supported when compare_duration is not set: @@ -698,9 +776,9 @@ def group_assets \ # all sources provide a source_id of `-`. For example: # organizations/{organization_id}/sources/- # @param group_by [String] - # Required. Expression that defines what assets fields to use for grouping (including - # `state_change`). The string value should follow SQL syntax: comma separated - # list of fields. For example: "parent,resource_name". + # Required. Expression that defines what assets fields to use for grouping + # (including `state_change`). The string value should follow SQL syntax: + # comma separated list of fields. For example: "parent,resource_name". # # The following fields are supported: # @@ -777,12 +855,18 @@ def group_assets \ # # Possible "state_change" values when compare_duration is specified: # - # * "CHANGED": indicates that the finding was present at the start of - # compare_duration, but changed its state at read_time. - # * "UNCHANGED": indicates that the finding was present at the start of - # compare_duration and did not change state at read_time. - # * "ADDED": indicates that the finding was not present at the start - # of compare_duration, but was present at read_time. + # * "CHANGED": indicates that the finding was present and matched the given + # filter at the start of compare_duration, but changed its + # state at read_time. + # * "UNCHANGED": indicates that the finding was present and matched the given + # filter at the start of compare_duration and did not change + # state at read_time. + # * "ADDED": indicates that the finding did not match the given filter or + # was not present at the start of compare_duration, but was + # present at read_time. + # * "REMOVED": indicates that the finding was present and matched the + # filter at the start of compare_duration, but did not match + # the filter at read_time. # # If compare_duration is not specified, then the only possible state_change # is "UNUSED", which will be the state_change set for all findings present @@ -902,8 +986,8 @@ def test_iam_permissions \ # Required. Resource name of the new source's parent. Its format should be # "organizations/[organization_id]". # @param source [Google::Cloud::SecurityCenter::V1::Source | Hash] - # Required. The Source being created, only the display_name and description will be - # used. All other fields will be ignored. + # Required. The Source being created, only the display_name and description + # will be used. All other fields will be ignored. # A hash of the same form as `Google::Cloud::SecurityCenter::V1::Source` # can also be provided. # @param options [Google::Gax::CallOptions] @@ -948,8 +1032,8 @@ def create_source \ # It must be alphanumeric and less than or equal to 32 characters and # greater than 0 characters in length. # @param finding [Google::Cloud::SecurityCenter::V1::Finding | Hash] - # Required. The Finding being created. The name and security_marks will be ignored as - # they are both output only fields on this resource. + # Required. The Finding being created. The name and security_marks will be + # ignored as they are both output only fields on this resource. # A hash of the same form as `Google::Cloud::SecurityCenter::V1::Finding` # can also be provided. # @param options [Google::Gax::CallOptions] @@ -988,11 +1072,125 @@ def create_finding \ @create_finding.call(req, options, &block) end + # Creates a notification config. + # + # @param parent [String] + # Required. Resource name of the new notification config's parent. Its format + # is "organizations/[organization_id]". + # @param config_id [String] + # Required. + # Unique identifier provided by the client within the parent scope. + # It must be between 1 and 128 characters, and contains alphanumeric + # characters, underscores or hyphens only. + # @param notification_config [Google::Cloud::SecurityCenter::V1::NotificationConfig | Hash] + # Required. The notification config being created. The name and the service + # account will be ignored as they are both output only fields on this + # resource. + # A hash of the same form as `Google::Cloud::SecurityCenter::V1::NotificationConfig` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Cloud::SecurityCenter::V1::NotificationConfig] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Cloud::SecurityCenter::V1::NotificationConfig] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/security_center" + # + # security_center_client = Google::Cloud::SecurityCenter.new(version: :v1) + # formatted_parent = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.organization_path("[ORGANIZATION]") + # + # # TODO: Initialize `config_id`: + # config_id = '' + # + # # TODO: Initialize `notification_config`: + # notification_config = {} + # response = security_center_client.create_notification_config(formatted_parent, config_id, notification_config) + + def create_notification_config \ + parent, + config_id, + notification_config, + options: nil, + &block + req = { + parent: parent, + config_id: config_id, + notification_config: notification_config + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Cloud::SecurityCenter::V1::CreateNotificationConfigRequest) + @create_notification_config.call(req, options, &block) + end + + # Deletes a notification config. + # + # @param name [String] + # Required. Name of the notification config to delete. Its format is + # "organizations/[organization_id]/notificationConfigs/[config_id]". + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/security_center" + # + # security_center_client = Google::Cloud::SecurityCenter.new(version: :v1) + # formatted_name = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.notification_config_path("[ORGANIZATION]", "[NOTIFICATION_CONFIG]") + # security_center_client.delete_notification_config(formatted_name) + + def delete_notification_config \ + name, + options: nil, + &block + req = { + name: name + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Cloud::SecurityCenter::V1::DeleteNotificationConfigRequest) + @delete_notification_config.call(req, options, &block) + nil + end + + # Gets a notification config. + # + # @param name [String] + # Required. Name of the notification config to get. Its format is + # "organizations/[organization_id]/notificationConfigs/[config_id]". + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Cloud::SecurityCenter::V1::NotificationConfig] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Cloud::SecurityCenter::V1::NotificationConfig] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/security_center" + # + # security_center_client = Google::Cloud::SecurityCenter.new(version: :v1) + # formatted_name = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.notification_config_path("[ORGANIZATION]", "[NOTIFICATION_CONFIG]") + # response = security_center_client.get_notification_config(formatted_name) + + def get_notification_config \ + name, + options: nil, + &block + req = { + name: name + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Cloud::SecurityCenter::V1::GetNotificationConfigRequest) + @get_notification_config.call(req, options, &block) + end + # Gets the settings for an organization. # # @param name [String] - # Required. Name of the organization to get organization settings for. Its format is - # "organizations/[organization_id]/organizationSettings". + # Required. Name of the organization to get organization settings for. Its + # format is "organizations/[organization_id]/organizationSettings". # @param options [Google::Gax::CallOptions] # Overrides the default settings for this call, e.g, timeout, # retries, etc. @@ -1169,9 +1367,8 @@ def get_source \ # A hash of the same form as `Google::Protobuf::Duration` # can also be provided. # @param field_mask [Google::Protobuf::FieldMask | Hash] - # Optional. A field mask to specify the ListAssetsResult fields to be listed in the - # response. - # An empty field mask will list all fields. + # Optional. A field mask to specify the ListAssetsResult fields to be listed + # in the response. An empty field mask will list all fields. # A hash of the same form as `Google::Protobuf::FieldMask` # can also be provided. # @param page_size [Integer] @@ -1329,12 +1526,18 @@ def list_assets \ # # Possible "state_change" values when compare_duration is specified: # - # * "CHANGED": indicates that the finding was present at the start of - # compare_duration, but changed its state at read_time. - # * "UNCHANGED": indicates that the finding was present at the start of - # compare_duration and did not change state at read_time. - # * "ADDED": indicates that the finding was not present at the start - # of compare_duration, but was present at read_time. + # * "CHANGED": indicates that the finding was present and matched the given + # filter at the start of compare_duration, but changed its + # state at read_time. + # * "UNCHANGED": indicates that the finding was present and matched the given + # filter at the start of compare_duration and did not change + # state at read_time. + # * "ADDED": indicates that the finding did not match the given filter or + # was not present at the start of compare_duration, but was + # present at read_time. + # * "REMOVED": indicates that the finding was present and matched the + # filter at the start of compare_duration, but did not match + # the filter at read_time. # # If compare_duration is not specified, then the only possible state_change # is "UNUSED", which will be the state_change set for all findings present at @@ -1342,8 +1545,8 @@ def list_assets \ # A hash of the same form as `Google::Protobuf::Duration` # can also be provided. # @param field_mask [Google::Protobuf::FieldMask | Hash] - # Optional. A field mask to specify the Finding fields to be listed in the response. - # An empty field mask will list all fields. + # Optional. A field mask to specify the Finding fields to be listed in the + # response. An empty field mask will list all fields. # A hash of the same form as `Google::Protobuf::FieldMask` # can also be provided. # @param page_size [Integer] @@ -1406,11 +1609,66 @@ def list_findings \ @list_findings.call(req, options, &block) end + # Lists notification configs. + # + # @param parent [String] + # Required. Name of the organization to list notification configs. + # Its format is "organizations/[organization_id]". + # @param page_size [Integer] + # The maximum number of resources contained in the underlying API + # response. If page streaming is performed per-resource, this + # parameter does not affect the return value. If page streaming is + # performed per-page, this determines the maximum number of + # resources in a page. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Gax::PagedEnumerable] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Gax::PagedEnumerable] + # An enumerable of Google::Cloud::SecurityCenter::V1::NotificationConfig instances. + # See Google::Gax::PagedEnumerable documentation for other + # operations such as per-page iteration or access to the response + # object. + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/security_center" + # + # security_center_client = Google::Cloud::SecurityCenter.new(version: :v1) + # formatted_parent = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.organization_path("[ORGANIZATION]") + # + # # Iterate over all results. + # security_center_client.list_notification_configs(formatted_parent).each do |element| + # # Process element. + # end + # + # # Or iterate over results one page at a time. + # security_center_client.list_notification_configs(formatted_parent).each_page do |page| + # # Process each page at a time. + # page.each do |element| + # # Process element. + # end + # end + + def list_notification_configs \ + parent, + page_size: nil, + options: nil, + &block + req = { + parent: parent, + page_size: page_size + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Cloud::SecurityCenter::V1::ListNotificationConfigsRequest) + @list_notification_configs.call(req, options, &block) + end + # Lists all sources belonging to an organization. # # @param parent [String] - # Required. Resource name of the parent of sources to list. Its format should be - # "organizations/[organization_id]". + # Required. Resource name of the parent of sources to list. Its format should + # be "organizations/[organization_id]". # @param page_size [Integer] # The maximum number of resources contained in the underlying API # response. If page streaming is performed per-resource, this @@ -1469,8 +1727,8 @@ def list_sources \ # error. # # @param parent [String] - # Required. Name of the organization to run asset discovery for. Its format is - # "organizations/[organization_id]". + # Required. Name of the organization to run asset discovery for. Its format + # is "organizations/[organization_id]". # @param options [Google::Gax::CallOptions] # Overrides the default settings for this call, e.g, timeout, # retries, etc. @@ -1625,8 +1883,8 @@ def set_iam_policy \ # finding creation to succeed. # # @param finding [Google::Cloud::SecurityCenter::V1::Finding | Hash] - # Required. The finding resource to update or create if it does not already exist. - # parent, security_marks, and update_time will be ignored. + # Required. The finding resource to update or create if it does not already + # exist. parent, security_marks, and update_time will be ignored. # # In the case of creation, the finding id portion of the name must be # alphanumeric and less than or equal to 32 characters and greater than 0 @@ -1673,6 +1931,48 @@ def update_finding \ @update_finding.call(req, options, &block) end + # Updates a notification config. + # + # @param notification_config [Google::Cloud::SecurityCenter::V1::NotificationConfig | Hash] + # Required. The notification config to update. + # A hash of the same form as `Google::Cloud::SecurityCenter::V1::NotificationConfig` + # can also be provided. + # @param update_mask [Google::Protobuf::FieldMask | Hash] + # The FieldMask to use when updating the notification config. + # + # If empty all mutable fields will be updated. + # A hash of the same form as `Google::Protobuf::FieldMask` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Cloud::SecurityCenter::V1::NotificationConfig] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Cloud::SecurityCenter::V1::NotificationConfig] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/security_center" + # + # security_center_client = Google::Cloud::SecurityCenter.new(version: :v1) + # + # # TODO: Initialize `notification_config`: + # notification_config = {} + # response = security_center_client.update_notification_config(notification_config) + + def update_notification_config \ + notification_config, + update_mask: nil, + options: nil, + &block + req = { + notification_config: notification_config, + update_mask: update_mask + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Cloud::SecurityCenter::V1::UpdateNotificationConfigRequest) + @update_notification_config.call(req, options, &block) + end + # Updates an organization's settings. # # @param organization_settings [Google::Cloud::SecurityCenter::V1::OrganizationSettings | Hash] diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/security_center_client_config.json b/google-cloud-security_center/lib/google/cloud/security_center/v1/security_center_client_config.json index 42f7b0b2114c..3143058ad883 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/security_center_client_config.json +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/security_center_client_config.json @@ -50,6 +50,21 @@ "retry_codes_name": "non_idempotent", "retry_params_name": "default" }, + "CreateNotificationConfig": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "DeleteNotificationConfig": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "GetNotificationConfig": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, "GetOrganizationSettings": { "timeout_millis": 60000, "retry_codes_name": "idempotent", @@ -70,6 +85,11 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, + "ListNotificationConfigs": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, "ListSources": { "timeout_millis": 60000, "retry_codes_name": "idempotent", @@ -95,6 +115,11 @@ "retry_codes_name": "non_idempotent", "retry_params_name": "default" }, + "UpdateNotificationConfig": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, "UpdateOrganizationSettings": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/security_marks_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/security_marks_pb.rb index a0e2ad3837b1..8c4c4c09d5c8 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/security_marks_pb.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/security_marks_pb.rb @@ -4,8 +4,8 @@ require 'google/protobuf' -require 'google/api/resource_pb' require 'google/api/annotations_pb' +require 'google/api/resource_pb' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "google.cloud.securitycenter.v1.SecurityMarks" do optional :name, :string, 1 diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/securitycenter_service_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/securitycenter_service_pb.rb index c776ff85abc2..93ea15db3c91 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/securitycenter_service_pb.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/securitycenter_service_pb.rb @@ -11,6 +11,7 @@ require 'google/api/resource_pb' require 'google/cloud/security_center/v1/asset_pb' require 'google/cloud/security_center/v1/finding_pb' +require 'google/cloud/security_center/v1/notification_config_pb' require 'google/cloud/security_center/v1/organization_settings_pb' require 'google/cloud/security_center/v1/security_marks_pb' require 'google/cloud/security_center/v1/source_pb' @@ -28,10 +29,21 @@ optional :finding_id, :string, 2 optional :finding, :message, 3, "google.cloud.securitycenter.v1.Finding" end + add_message "google.cloud.securitycenter.v1.CreateNotificationConfigRequest" do + optional :parent, :string, 1 + optional :config_id, :string, 2 + optional :notification_config, :message, 3, "google.cloud.securitycenter.v1.NotificationConfig" + end add_message "google.cloud.securitycenter.v1.CreateSourceRequest" do optional :parent, :string, 1 optional :source, :message, 2, "google.cloud.securitycenter.v1.Source" end + add_message "google.cloud.securitycenter.v1.DeleteNotificationConfigRequest" do + optional :name, :string, 1 + end + add_message "google.cloud.securitycenter.v1.GetNotificationConfigRequest" do + optional :name, :string, 1 + end add_message "google.cloud.securitycenter.v1.GetOrganizationSettingsRequest" do optional :name, :string, 1 end @@ -72,6 +84,15 @@ map :properties, :string, :message, 1, "google.protobuf.Value" optional :count, :int64, 2 end + add_message "google.cloud.securitycenter.v1.ListNotificationConfigsRequest" do + optional :parent, :string, 1 + optional :page_token, :string, 2 + optional :page_size, :int32, 3 + end + add_message "google.cloud.securitycenter.v1.ListNotificationConfigsResponse" do + repeated :notification_configs, :message, 1, "google.cloud.securitycenter.v1.NotificationConfig" + optional :next_page_token, :string, 2 + end add_message "google.cloud.securitycenter.v1.ListSourcesRequest" do optional :parent, :string, 1 optional :page_token, :string, 2 @@ -154,6 +175,10 @@ optional :finding, :message, 1, "google.cloud.securitycenter.v1.Finding" optional :update_mask, :message, 2, "google.protobuf.FieldMask" end + add_message "google.cloud.securitycenter.v1.UpdateNotificationConfigRequest" do + optional :notification_config, :message, 1, "google.cloud.securitycenter.v1.NotificationConfig" + optional :update_mask, :message, 2, "google.protobuf.FieldMask" + end add_message "google.cloud.securitycenter.v1.UpdateOrganizationSettingsRequest" do optional :organization_settings, :message, 1, "google.cloud.securitycenter.v1.OrganizationSettings" optional :update_mask, :message, 2, "google.protobuf.FieldMask" @@ -171,7 +196,10 @@ module Google::Cloud::SecurityCenter::V1 CreateFindingRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.CreateFindingRequest").msgclass + CreateNotificationConfigRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.CreateNotificationConfigRequest").msgclass CreateSourceRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.CreateSourceRequest").msgclass + DeleteNotificationConfigRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.DeleteNotificationConfigRequest").msgclass + GetNotificationConfigRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.GetNotificationConfigRequest").msgclass GetOrganizationSettingsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.GetOrganizationSettingsRequest").msgclass GetSourceRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.GetSourceRequest").msgclass GroupAssetsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.GroupAssetsRequest").msgclass @@ -179,6 +207,8 @@ module Google::Cloud::SecurityCenter::V1 GroupFindingsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.GroupFindingsRequest").msgclass GroupFindingsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.GroupFindingsResponse").msgclass GroupResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.GroupResult").msgclass + ListNotificationConfigsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.ListNotificationConfigsRequest").msgclass + ListNotificationConfigsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.ListNotificationConfigsResponse").msgclass ListSourcesRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.ListSourcesRequest").msgclass ListSourcesResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.ListSourcesResponse").msgclass ListAssetsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.ListAssetsRequest").msgclass @@ -193,6 +223,7 @@ module Google::Cloud::SecurityCenter::V1 SetFindingStateRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.SetFindingStateRequest").msgclass RunAssetDiscoveryRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.RunAssetDiscoveryRequest").msgclass UpdateFindingRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.UpdateFindingRequest").msgclass + UpdateNotificationConfigRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.UpdateNotificationConfigRequest").msgclass UpdateOrganizationSettingsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.UpdateOrganizationSettingsRequest").msgclass UpdateSourceRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.UpdateSourceRequest").msgclass UpdateSecurityMarksRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.securitycenter.v1.UpdateSecurityMarksRequest").msgclass diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/securitycenter_service_services_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/securitycenter_service_services_pb.rb index a6cbb19224e0..081505ddc3a3 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/securitycenter_service_services_pb.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/securitycenter_service_services_pb.rb @@ -1,7 +1,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # Source: google/cloud/security_center/v1/securitycenter_service.proto for package 'Google::Cloud::SecurityCenter::V1' # Original file comments: -# Copyright 2019 Google LLC. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# require 'grpc' @@ -37,8 +36,14 @@ class Service # Creates a finding. The corresponding source must exist for finding creation # to succeed. rpc :CreateFinding, CreateFindingRequest, Finding + # Creates a notification config. + rpc :CreateNotificationConfig, CreateNotificationConfigRequest, NotificationConfig + # Deletes a notification config. + rpc :DeleteNotificationConfig, DeleteNotificationConfigRequest, Google::Protobuf::Empty # Gets the access control policy on the specified Source. rpc :GetIamPolicy, Google::Iam::V1::GetIamPolicyRequest, Google::Iam::V1::Policy + # Gets a notification config. + rpc :GetNotificationConfig, GetNotificationConfigRequest, NotificationConfig # Gets the settings for an organization. rpc :GetOrganizationSettings, GetOrganizationSettingsRequest, OrganizationSettings # Gets a source. @@ -59,6 +64,8 @@ class Service # To list across all sources provide a `-` as the source id. # Example: /v1/organizations/{organization_id}/sources/-/findings rpc :ListFindings, ListFindingsRequest, ListFindingsResponse + # Lists notification configs. + rpc :ListNotificationConfigs, ListNotificationConfigsRequest, ListNotificationConfigsResponse # Lists all sources belonging to an organization. rpc :ListSources, ListSourcesRequest, ListSourcesResponse # Runs asset discovery. The discovery is tracked with a long-running @@ -77,6 +84,9 @@ class Service # Creates or updates a finding. The corresponding source must exist for a # finding creation to succeed. rpc :UpdateFinding, UpdateFindingRequest, Finding + # + # Updates a notification config. + rpc :UpdateNotificationConfig, UpdateNotificationConfigRequest, NotificationConfig # Updates an organization's settings. rpc :UpdateOrganizationSettings, UpdateOrganizationSettingsRequest, OrganizationSettings # Updates a source. diff --git a/google-cloud-security_center/lib/google/cloud/security_center/v1/source_pb.rb b/google-cloud-security_center/lib/google/cloud/security_center/v1/source_pb.rb index 0566434ff3ef..084ae16b60dc 100644 --- a/google-cloud-security_center/lib/google/cloud/security_center/v1/source_pb.rb +++ b/google-cloud-security_center/lib/google/cloud/security_center/v1/source_pb.rb @@ -4,8 +4,8 @@ require 'google/protobuf' -require 'google/api/resource_pb' require 'google/api/annotations_pb' +require 'google/api/resource_pb' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "google.cloud.securitycenter.v1.Source" do optional :name, :string, 1 diff --git a/google-cloud-security_center/synth.metadata b/google-cloud-security_center/synth.metadata index 8e4a13665eb0..da7fbdf76fc6 100644 --- a/google-cloud-security_center/synth.metadata +++ b/google-cloud-security_center/synth.metadata @@ -1,20 +1,20 @@ { - "updateTime": "2020-02-27T11:45:02.850779Z", + "updateTime": "2020-03-04T11:44:03.841096Z", "sources": [ { "generator": { "name": "artman", - "version": "0.46.0", - "dockerImage": "googleapis/artman@sha256:6248a21fba8f0d618c3b032669cec2618e684b66922bb70391fe08c41b05f6ee" + "version": "1.0.0", + "dockerImage": "googleapis/artman@sha256:f37f2464788cb551299209b4fcab4eb323533154488c2ef9ec0c75d7c2b4b482" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "dfe1cf7be44dee31d78f78e485d8c95430981d6e", - "internalRef": "297497710", - "log": "dfe1cf7be44dee31d78f78e485d8c95430981d6e\nPublish `QueryOptions` proto.\n\nIntroduced a `query_options` input in `ExecuteSqlRequest`.\n\nPiperOrigin-RevId: 297497710\n\ndafc905f71e5d46f500b41ed715aad585be062c3\npubsub: revert pull init_rpc_timeout & max_rpc_timeout back to 25 seconds and reset multiplier to 1.0\n\nPiperOrigin-RevId: 297486523\n\nf077632ba7fee588922d9e8717ee272039be126d\nfirestore: add update_transform\n\nPiperOrigin-RevId: 297405063\n\n0aba1900ffef672ec5f0da677cf590ee5686e13b\ncluster: use square brace for cross-reference\n\nPiperOrigin-RevId: 297204568\n\n5dac2da18f6325cbaed54603c43f0667ecd50247\nRestore retry params in gapic config because securitycenter has non-standard default retry params.\nRestore a few retry codes for some idempotent methods.\n\nPiperOrigin-RevId: 297196720\n\n1eb61455530252bba8b2c8d4bc9832960e5a56f6\npubsub: v1 replace IAM HTTP rules\n\nPiperOrigin-RevId: 297188590\n\n80b2d25f8d43d9d47024ff06ead7f7166548a7ba\nDialogflow weekly v2/v2beta1 library update:\n - updates to mega agent api\n - adding field mask override control for output audio config\nImportant updates are also posted at:\nhttps://cloud.google.com/dialogflow/docs/release-notes\n\nPiperOrigin-RevId: 297187629\n\n0b1876b35e98f560f9c9ca9797955f020238a092\nUse an older version of protoc-docs-plugin that is compatible with the specified gapic-generator and protobuf versions.\n\nprotoc-docs-plugin >=0.4.0 (see commit https://github.com/googleapis/protoc-docs-plugin/commit/979f03ede6678c487337f3d7e88bae58df5207af) is incompatible with protobuf 3.9.1.\n\nPiperOrigin-RevId: 296986742\n\n1e47e676cddbbd8d93f19ba0665af15b5532417e\nFix: Restore a method signature for UpdateCluster\n\nPiperOrigin-RevId: 296901854\n\n7f910bcc4fc4704947ccfd3ceed015d16b9e00c2\nUpdate Dataproc v1beta2 client.\n\nPiperOrigin-RevId: 296451205\n\nde287524405a3dce124d301634731584fc0432d7\nFix: Reinstate method signatures that had been missed off some RPCs\nFix: Correct resource types for two fields\n\nPiperOrigin-RevId: 296435091\n\n" + "sha": "541b1ded4abadcc38e8178680b0677f65594ea6f", + "internalRef": "298686266", + "log": "541b1ded4abadcc38e8178680b0677f65594ea6f\nUpdate cloud asset api v1p4beta1.\n\nPiperOrigin-RevId: 298686266\n\nc0d171acecb4f5b0bfd2c4ca34fc54716574e300\n Updated to include the Notification v1 API.\n\nPiperOrigin-RevId: 298652775\n\n2346a9186c0bff2c9cc439f2459d558068637e05\nAdd Service Directory v1beta1 protos and configs\n\nPiperOrigin-RevId: 298625638\n\na78ed801b82a5c6d9c5368e24b1412212e541bb7\nPublishing v3 protos and configs.\n\nPiperOrigin-RevId: 298607357\n\n4a180bfff8a21645b3a935c2756e8d6ab18a74e0\nautoml/v1beta1 publish proto updates\n\nPiperOrigin-RevId: 298484782\n\n6de6e938b7df1cd62396563a067334abeedb9676\nchore: use the latest gapic-generator and protoc-java-resource-name-plugin in Bazel workspace.\n\nPiperOrigin-RevId: 298474513\n\n244ab2b83a82076a1fa7be63b7e0671af73f5c02\nAdds service config definition for bigqueryreservation v1\n\nPiperOrigin-RevId: 298455048\n\n83c6f84035ee0f80eaa44d8b688a010461cc4080\nUpdate google/api/auth.proto to make AuthProvider to have JwtLocation\n\nPiperOrigin-RevId: 297918498\n\ne9e90a787703ec5d388902e2cb796aaed3a385b4\nDialogflow weekly v2/v2beta1 library update:\n - adding get validation result\n - adding field mask override control for output audio config\nImportant updates are also posted at:\nhttps://cloud.google.com/dialogflow/docs/release-notes\n\nPiperOrigin-RevId: 297671458\n\n1a2b05cc3541a5f7714529c665aecc3ea042c646\nAdding .yaml and .json config files.\n\nPiperOrigin-RevId: 297570622\n\n" } }, { diff --git a/google-cloud-security_center/test/google/cloud/security_center/v1/helpers_test.rb b/google-cloud-security_center/test/google/cloud/security_center/v1/helpers_test.rb index 507f972f735c..3da1752baacf 100644 --- a/google-cloud-security_center/test/google/cloud/security_center/v1/helpers_test.rb +++ b/google-cloud-security_center/test/google/cloud/security_center/v1/helpers_test.rb @@ -77,6 +77,19 @@ def updater_proc end end + describe "the notification_config_path instance method" do + it "correctly calls Google::Cloud::SecurityCenter::V1::SecurityCenterClient.notification_config_path" do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new version: :v1 + parameters = client.method("notification_config_path").parameters.map { |arg| arg.last.to_s } + assert_equal( + client.notification_config_path(*parameters), + Google::Cloud::SecurityCenter::V1::SecurityCenterClient.notification_config_path(*parameters) + ) + end + end + end + describe "the organization_path instance method" do it "correctly calls Google::Cloud::SecurityCenter::V1::SecurityCenterClient.organization_path" do Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do @@ -115,4 +128,17 @@ def updater_proc end end end + + describe "the topic_path instance method" do + it "correctly calls Google::Cloud::SecurityCenter::V1::SecurityCenterClient.topic_path" do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new version: :v1 + parameters = client.method("topic_path").parameters.map { |arg| arg.last.to_s } + assert_equal( + client.topic_path(*parameters), + Google::Cloud::SecurityCenter::V1::SecurityCenterClient.topic_path(*parameters) + ) + end + end + end end diff --git a/google-cloud-security_center/test/google/cloud/security_center/v1/security_center_client_test.rb b/google-cloud-security_center/test/google/cloud/security_center/v1/security_center_client_test.rb index 62bff39b24ee..34a968c8eb52 100644 --- a/google-cloud-security_center/test/google/cloud/security_center/v1/security_center_client_test.rb +++ b/google-cloud-security_center/test/google/cloud/security_center/v1/security_center_client_test.rb @@ -571,6 +571,259 @@ def updater_proc end end + describe 'create_notification_config' do + custom_error = CustomTestError_v1.new "Custom test error for Google::Cloud::SecurityCenter::V1::SecurityCenterClient#create_notification_config." + + it 'invokes create_notification_config without error' do + # Create request parameters + formatted_parent = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.organization_path("[ORGANIZATION]") + config_id = '' + notification_config = {} + + # Create expected grpc response + name = "name3373707" + description = "description-1724546052" + pubsub_topic = "pubsubTopic-338126829" + service_account = "serviceAccount-1948028253" + expected_response = { + name: name, + description: description, + pubsub_topic: pubsub_topic, + service_account: service_account + } + expected_response = Google::Gax::to_proto(expected_response, Google::Cloud::SecurityCenter::V1::NotificationConfig) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::CreateNotificationConfigRequest, request) + assert_equal(formatted_parent, request.parent) + assert_equal(config_id, request.config_id) + assert_equal(Google::Gax::to_proto(notification_config, Google::Cloud::SecurityCenter::V1::NotificationConfig), request.notification_config) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub_v1.new(:create_notification_config, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("create_notification_config") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + response = client.create_notification_config( + formatted_parent, + config_id, + notification_config + ) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.create_notification_config( + formatted_parent, + config_id, + notification_config + ) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes create_notification_config with error' do + # Create request parameters + formatted_parent = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.organization_path("[ORGANIZATION]") + config_id = '' + notification_config = {} + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::CreateNotificationConfigRequest, request) + assert_equal(formatted_parent, request.parent) + assert_equal(config_id, request.config_id) + assert_equal(Google::Gax::to_proto(notification_config, Google::Cloud::SecurityCenter::V1::NotificationConfig), request.notification_config) + raise custom_error + end + mock_stub = MockGrpcClientStub_v1.new(:create_notification_config, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("create_notification_config") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError, CustomTestError_v1 do + client.create_notification_config( + formatted_parent, + config_id, + notification_config + ) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'delete_notification_config' do + custom_error = CustomTestError_v1.new "Custom test error for Google::Cloud::SecurityCenter::V1::SecurityCenterClient#delete_notification_config." + + it 'invokes delete_notification_config without error' do + # Create request parameters + formatted_name = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.notification_config_path("[ORGANIZATION]", "[NOTIFICATION_CONFIG]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::DeleteNotificationConfigRequest, request) + assert_equal(formatted_name, request.name) + OpenStruct.new(execute: nil) + end + mock_stub = MockGrpcClientStub_v1.new(:delete_notification_config, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("delete_notification_config") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + response = client.delete_notification_config(formatted_name) + + # Verify the response + assert_nil(response) + + # Call method with block + client.delete_notification_config(formatted_name) do |response, operation| + # Verify the response + assert_nil(response) + refute_nil(operation) + end + end + end + end + + it 'invokes delete_notification_config with error' do + # Create request parameters + formatted_name = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.notification_config_path("[ORGANIZATION]", "[NOTIFICATION_CONFIG]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::DeleteNotificationConfigRequest, request) + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub_v1.new(:delete_notification_config, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("delete_notification_config") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError, CustomTestError_v1 do + client.delete_notification_config(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'get_notification_config' do + custom_error = CustomTestError_v1.new "Custom test error for Google::Cloud::SecurityCenter::V1::SecurityCenterClient#get_notification_config." + + it 'invokes get_notification_config without error' do + # Create request parameters + formatted_name = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.notification_config_path("[ORGANIZATION]", "[NOTIFICATION_CONFIG]") + + # Create expected grpc response + name_2 = "name2-1052831874" + description = "description-1724546052" + pubsub_topic = "pubsubTopic-338126829" + service_account = "serviceAccount-1948028253" + expected_response = { + name: name_2, + description: description, + pubsub_topic: pubsub_topic, + service_account: service_account + } + expected_response = Google::Gax::to_proto(expected_response, Google::Cloud::SecurityCenter::V1::NotificationConfig) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::GetNotificationConfigRequest, request) + assert_equal(formatted_name, request.name) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub_v1.new(:get_notification_config, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("get_notification_config") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + response = client.get_notification_config(formatted_name) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.get_notification_config(formatted_name) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes get_notification_config with error' do + # Create request parameters + formatted_name = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.notification_config_path("[ORGANIZATION]", "[NOTIFICATION_CONFIG]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::GetNotificationConfigRequest, request) + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub_v1.new(:get_notification_config, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("get_notification_config") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError, CustomTestError_v1 do + client.get_notification_config(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + describe 'get_organization_settings' do custom_error = CustomTestError_v1.new "Custom test error for Google::Cloud::SecurityCenter::V1::SecurityCenterClient#get_organization_settings." @@ -880,6 +1133,78 @@ def updater_proc end end + describe 'list_notification_configs' do + custom_error = CustomTestError_v1.new "Custom test error for Google::Cloud::SecurityCenter::V1::SecurityCenterClient#list_notification_configs." + + it 'invokes list_notification_configs without error' do + # Create request parameters + formatted_parent = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.organization_path("[ORGANIZATION]") + + # Create expected grpc response + next_page_token = "" + notification_configs_element = {} + notification_configs = [notification_configs_element] + expected_response = { next_page_token: next_page_token, notification_configs: notification_configs } + expected_response = Google::Gax::to_proto(expected_response, Google::Cloud::SecurityCenter::V1::ListNotificationConfigsResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::ListNotificationConfigsRequest, request) + assert_equal(formatted_parent, request.parent) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub_v1.new(:list_notification_configs, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("list_notification_configs") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + response = client.list_notification_configs(formatted_parent) + + # Verify the response + assert(response.instance_of?(Google::Gax::PagedEnumerable)) + assert_equal(expected_response, response.page.response) + assert_nil(response.next_page) + assert_equal(expected_response.notification_configs.to_a, response.to_a) + end + end + end + + it 'invokes list_notification_configs with error' do + # Create request parameters + formatted_parent = Google::Cloud::SecurityCenter::V1::SecurityCenterClient.organization_path("[ORGANIZATION]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::ListNotificationConfigsRequest, request) + assert_equal(formatted_parent, request.parent) + raise custom_error + end + mock_stub = MockGrpcClientStub_v1.new(:list_notification_configs, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("list_notification_configs") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError, CustomTestError_v1 do + client.list_notification_configs(formatted_parent) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + describe 'list_sources' do custom_error = CustomTestError_v1.new "Custom test error for Google::Cloud::SecurityCenter::V1::SecurityCenterClient#list_sources." @@ -1331,6 +1656,88 @@ def updater_proc end end + describe 'update_notification_config' do + custom_error = CustomTestError_v1.new "Custom test error for Google::Cloud::SecurityCenter::V1::SecurityCenterClient#update_notification_config." + + it 'invokes update_notification_config without error' do + # Create request parameters + notification_config = {} + + # Create expected grpc response + name = "name3373707" + description = "description-1724546052" + pubsub_topic = "pubsubTopic-338126829" + service_account = "serviceAccount-1948028253" + expected_response = { + name: name, + description: description, + pubsub_topic: pubsub_topic, + service_account: service_account + } + expected_response = Google::Gax::to_proto(expected_response, Google::Cloud::SecurityCenter::V1::NotificationConfig) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::UpdateNotificationConfigRequest, request) + assert_equal(Google::Gax::to_proto(notification_config, Google::Cloud::SecurityCenter::V1::NotificationConfig), request.notification_config) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub_v1.new(:update_notification_config, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("update_notification_config") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + response = client.update_notification_config(notification_config) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.update_notification_config(notification_config) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes update_notification_config with error' do + # Create request parameters + notification_config = {} + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Cloud::SecurityCenter::V1::UpdateNotificationConfigRequest, request) + assert_equal(Google::Gax::to_proto(notification_config, Google::Cloud::SecurityCenter::V1::NotificationConfig), request.notification_config) + raise custom_error + end + mock_stub = MockGrpcClientStub_v1.new(:update_notification_config, mock_method) + + # Mock auth layer + mock_credentials = MockSecurityCenterCredentials_v1.new("update_notification_config") + + Google::Cloud::SecurityCenter::V1::SecurityCenter::Stub.stub(:new, mock_stub) do + Google::Cloud::SecurityCenter::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::SecurityCenter.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError, CustomTestError_v1 do + client.update_notification_config(notification_config) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + describe 'update_organization_settings' do custom_error = CustomTestError_v1.new "Custom test error for Google::Cloud::SecurityCenter::V1::SecurityCenterClient#update_organization_settings."