diff --git a/google-cloud-chronicle/AUTHENTICATION.md b/google-cloud-chronicle/AUTHENTICATION.md index 93ed5d0e9a4b..0c4fbd7fbc5e 100644 --- a/google-cloud-chronicle/AUTHENTICATION.md +++ b/google-cloud-chronicle/AUTHENTICATION.md @@ -56,7 +56,7 @@ To configure a credentials file for an individual client initialization: ```ruby require "google/cloud/chronicle" -client = Google::Cloud::Chronicle.data_access_control_service do |config| +client = Google::Cloud::Chronicle.big_query_export_service do |config| config.credentials = "path/to/credentialfile.json" end ``` @@ -70,7 +70,7 @@ Google::Cloud::Chronicle.configure do |config| config.credentials = "path/to/credentialfile.json" end -client = Google::Cloud::Chronicle.data_access_control_service +client = Google::Cloud::Chronicle.big_query_export_service ``` ### Environment Variables @@ -100,7 +100,7 @@ require "google/cloud/chronicle" ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/credentialfile.json" -client = Google::Cloud::Chronicle.data_access_control_service +client = Google::Cloud::Chronicle.big_query_export_service ``` ### Local ADC file diff --git a/google-cloud-chronicle/README.md b/google-cloud-chronicle/README.md index 89960ff20d36..bd8d30ab7e36 100644 --- a/google-cloud-chronicle/README.md +++ b/google-cloud-chronicle/README.md @@ -37,9 +37,9 @@ In order to use this library, you first need to go through the following steps: ```ruby require "google/cloud/chronicle" -client = Google::Cloud::Chronicle.data_access_control_service -request = ::Google::Cloud::Chronicle::V1::CreateDataAccessLabelRequest.new # (request fields as keyword arguments...) -response = client.create_data_access_label request +client = Google::Cloud::Chronicle.big_query_export_service +request = ::Google::Cloud::Chronicle::V1::GetBigQueryExportRequest.new # (request fields as keyword arguments...) +response = client.get_big_query_export request ``` ## Debug Logging diff --git a/google-cloud-chronicle/Rakefile b/google-cloud-chronicle/Rakefile index 56a1f5074fa7..e2427a85f030 100644 --- a/google-cloud-chronicle/Rakefile +++ b/google-cloud-chronicle/Rakefile @@ -57,8 +57,8 @@ task :acceptance, :project, :keyfile do |t, args| if project.nil? || keyfile.nil? fail "You must provide a project and keyfile. e.g. rake acceptance[test123, /path/to/keyfile.json] or GOOGLE_CLOUD_TEST_PROJECT=test123 GOOGLE_CLOUD_TEST_KEYFILE=/path/to/keyfile.json rake acceptance" end - require "google/cloud/chronicle/v1/data_access_control_service/credentials" - ::Google::Cloud::Chronicle::V1::DataAccessControlService::Credentials.env_vars.each do |path| + require "google/cloud/chronicle/v1/big_query_export_service/credentials" + ::Google::Cloud::Chronicle::V1::BigQueryExportService::Credentials.env_vars.each do |path| ENV[path] = nil end ENV["GOOGLE_CLOUD_PROJECT"] = project diff --git a/google-cloud-chronicle/lib/google/cloud/chronicle.rb b/google-cloud-chronicle/lib/google/cloud/chronicle.rb index 0189ede0b798..043a87d93471 100644 --- a/google-cloud-chronicle/lib/google/cloud/chronicle.rb +++ b/google-cloud-chronicle/lib/google/cloud/chronicle.rb @@ -45,6 +45,216 @@ module Google module Cloud module Chronicle + ## + # Create a new client object for BigQueryExportService. + # + # By default, this returns an instance of + # [Google::Cloud::Chronicle::V1::BigQueryExportService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-chronicle-v1/latest/Google-Cloud-Chronicle-V1-BigQueryExportService-Client) + # for a gRPC client for version V1 of the API. + # However, you can specify a different API version by passing it in the + # `version` parameter. If the BigQueryExportService service is + # supported by that API version, and the corresponding gem is available, the + # appropriate versioned client will be returned. + # You can also specify a different transport by passing `:rest` or `:grpc` in + # the `transport` parameter. + # + # Raises an exception if the currently installed versioned client gem for the + # given API version does not support the given transport of the BigQueryExportService service. + # You can determine whether the method will succeed by calling + # {Google::Cloud::Chronicle.big_query_export_service_available?}. + # + # ## About BigQueryExportService + # + # Service for managing BigQuery export configurations for Chronicle instances. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [::Object] A client object for the specified version. + # + def self.big_query_export_service version: :v1, transport: :grpc, &block + require "google/cloud/chronicle/#{version.to_s.downcase}" + + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + service_module = Google::Cloud::Chronicle.const_get(package_name).const_get(:BigQueryExportService) + service_module = service_module.const_get(:Rest) if transport == :rest + service_module.const_get(:Client).new(&block) + end + + ## + # Determines whether the BigQueryExportService service is supported by the current client. + # If true, you can retrieve a client object by calling {Google::Cloud::Chronicle.big_query_export_service}. + # If false, that method will raise an exception. This could happen if the given + # API version does not exist or does not support the BigQueryExportService service, + # or if the versioned client gem needs an update to support the BigQueryExportService service. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [boolean] Whether the service is available. + # + def self.big_query_export_service_available? version: :v1, transport: :grpc + require "google/cloud/chronicle/#{version.to_s.downcase}" + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + return false unless package_name + service_module = Google::Cloud::Chronicle.const_get package_name + return false unless service_module.const_defined? :BigQueryExportService + service_module = service_module.const_get :BigQueryExportService + if transport == :rest + return false unless service_module.const_defined? :Rest + service_module = service_module.const_get :Rest + end + service_module.const_defined? :Client + rescue ::LoadError + false + end + + ## + # Create a new client object for DashboardQueryService. + # + # By default, this returns an instance of + # [Google::Cloud::Chronicle::V1::DashboardQueryService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-chronicle-v1/latest/Google-Cloud-Chronicle-V1-DashboardQueryService-Client) + # for a gRPC client for version V1 of the API. + # However, you can specify a different API version by passing it in the + # `version` parameter. If the DashboardQueryService service is + # supported by that API version, and the corresponding gem is available, the + # appropriate versioned client will be returned. + # You can also specify a different transport by passing `:rest` or `:grpc` in + # the `transport` parameter. + # + # Raises an exception if the currently installed versioned client gem for the + # given API version does not support the given transport of the DashboardQueryService service. + # You can determine whether the method will succeed by calling + # {Google::Cloud::Chronicle.dashboard_query_service_available?}. + # + # ## About DashboardQueryService + # + # A service providing functionality for managing dashboards' queries. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [::Object] A client object for the specified version. + # + def self.dashboard_query_service version: :v1, transport: :grpc, &block + require "google/cloud/chronicle/#{version.to_s.downcase}" + + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + service_module = Google::Cloud::Chronicle.const_get(package_name).const_get(:DashboardQueryService) + service_module = service_module.const_get(:Rest) if transport == :rest + service_module.const_get(:Client).new(&block) + end + + ## + # Determines whether the DashboardQueryService service is supported by the current client. + # If true, you can retrieve a client object by calling {Google::Cloud::Chronicle.dashboard_query_service}. + # If false, that method will raise an exception. This could happen if the given + # API version does not exist or does not support the DashboardQueryService service, + # or if the versioned client gem needs an update to support the DashboardQueryService service. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [boolean] Whether the service is available. + # + def self.dashboard_query_service_available? version: :v1, transport: :grpc + require "google/cloud/chronicle/#{version.to_s.downcase}" + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + return false unless package_name + service_module = Google::Cloud::Chronicle.const_get package_name + return false unless service_module.const_defined? :DashboardQueryService + service_module = service_module.const_get :DashboardQueryService + if transport == :rest + return false unless service_module.const_defined? :Rest + service_module = service_module.const_get :Rest + end + service_module.const_defined? :Client + rescue ::LoadError + false + end + + ## + # Create a new client object for DashboardChartService. + # + # By default, this returns an instance of + # [Google::Cloud::Chronicle::V1::DashboardChartService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-chronicle-v1/latest/Google-Cloud-Chronicle-V1-DashboardChartService-Client) + # for a gRPC client for version V1 of the API. + # However, you can specify a different API version by passing it in the + # `version` parameter. If the DashboardChartService service is + # supported by that API version, and the corresponding gem is available, the + # appropriate versioned client will be returned. + # You can also specify a different transport by passing `:rest` or `:grpc` in + # the `transport` parameter. + # + # Raises an exception if the currently installed versioned client gem for the + # given API version does not support the given transport of the DashboardChartService service. + # You can determine whether the method will succeed by calling + # {Google::Cloud::Chronicle.dashboard_chart_service_available?}. + # + # ## About DashboardChartService + # + # A service providing functionality for managing dashboards' charts. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [::Object] A client object for the specified version. + # + def self.dashboard_chart_service version: :v1, transport: :grpc, &block + require "google/cloud/chronicle/#{version.to_s.downcase}" + + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + service_module = Google::Cloud::Chronicle.const_get(package_name).const_get(:DashboardChartService) + service_module = service_module.const_get(:Rest) if transport == :rest + service_module.const_get(:Client).new(&block) + end + + ## + # Determines whether the DashboardChartService service is supported by the current client. + # If true, you can retrieve a client object by calling {Google::Cloud::Chronicle.dashboard_chart_service}. + # If false, that method will raise an exception. This could happen if the given + # API version does not exist or does not support the DashboardChartService service, + # or if the versioned client gem needs an update to support the DashboardChartService service. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [boolean] Whether the service is available. + # + def self.dashboard_chart_service_available? version: :v1, transport: :grpc + require "google/cloud/chronicle/#{version.to_s.downcase}" + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + return false unless package_name + service_module = Google::Cloud::Chronicle.const_get package_name + return false unless service_module.const_defined? :DashboardChartService + service_module = service_module.const_get :DashboardChartService + if transport == :rest + return false unless service_module.const_defined? :Rest + service_module = service_module.const_get :Rest + end + service_module.const_defined? :Client + rescue ::LoadError + false + end + ## # Create a new client object for DataAccessControlService. # @@ -256,6 +466,147 @@ def self.entity_service_available? version: :v1, transport: :grpc false end + ## + # Create a new client object for NativeDashboardService. + # + # By default, this returns an instance of + # [Google::Cloud::Chronicle::V1::NativeDashboardService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-chronicle-v1/latest/Google-Cloud-Chronicle-V1-NativeDashboardService-Client) + # for a gRPC client for version V1 of the API. + # However, you can specify a different API version by passing it in the + # `version` parameter. If the NativeDashboardService service is + # supported by that API version, and the corresponding gem is available, the + # appropriate versioned client will be returned. + # You can also specify a different transport by passing `:rest` or `:grpc` in + # the `transport` parameter. + # + # Raises an exception if the currently installed versioned client gem for the + # given API version does not support the given transport of the NativeDashboardService service. + # You can determine whether the method will succeed by calling + # {Google::Cloud::Chronicle.native_dashboard_service_available?}. + # + # ## About NativeDashboardService + # + # A service providing functionality for managing native dashboards. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [::Object] A client object for the specified version. + # + def self.native_dashboard_service version: :v1, transport: :grpc, &block + require "google/cloud/chronicle/#{version.to_s.downcase}" + + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + service_module = Google::Cloud::Chronicle.const_get(package_name).const_get(:NativeDashboardService) + service_module = service_module.const_get(:Rest) if transport == :rest + service_module.const_get(:Client).new(&block) + end + + ## + # Determines whether the NativeDashboardService service is supported by the current client. + # If true, you can retrieve a client object by calling {Google::Cloud::Chronicle.native_dashboard_service}. + # If false, that method will raise an exception. This could happen if the given + # API version does not exist or does not support the NativeDashboardService service, + # or if the versioned client gem needs an update to support the NativeDashboardService service. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [boolean] Whether the service is available. + # + def self.native_dashboard_service_available? version: :v1, transport: :grpc + require "google/cloud/chronicle/#{version.to_s.downcase}" + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + return false unless package_name + service_module = Google::Cloud::Chronicle.const_get package_name + return false unless service_module.const_defined? :NativeDashboardService + service_module = service_module.const_get :NativeDashboardService + if transport == :rest + return false unless service_module.const_defined? :Rest + service_module = service_module.const_get :Rest + end + service_module.const_defined? :Client + rescue ::LoadError + false + end + + ## + # Create a new client object for FeaturedContentNativeDashboardService. + # + # By default, this returns an instance of + # [Google::Cloud::Chronicle::V1::FeaturedContentNativeDashboardService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-chronicle-v1/latest/Google-Cloud-Chronicle-V1-FeaturedContentNativeDashboardService-Client) + # for a gRPC client for version V1 of the API. + # However, you can specify a different API version by passing it in the + # `version` parameter. If the FeaturedContentNativeDashboardService service is + # supported by that API version, and the corresponding gem is available, the + # appropriate versioned client will be returned. + # You can also specify a different transport by passing `:rest` or `:grpc` in + # the `transport` parameter. + # + # Raises an exception if the currently installed versioned client gem for the + # given API version does not support the given transport of the FeaturedContentNativeDashboardService service. + # You can determine whether the method will succeed by calling + # {Google::Cloud::Chronicle.featured_content_native_dashboard_service_available?}. + # + # ## About FeaturedContentNativeDashboardService + # + # This service provides functionality for managing + # FeaturedContentNativeDashboard. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [::Object] A client object for the specified version. + # + def self.featured_content_native_dashboard_service version: :v1, transport: :grpc, &block + require "google/cloud/chronicle/#{version.to_s.downcase}" + + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + service_module = Google::Cloud::Chronicle.const_get(package_name).const_get(:FeaturedContentNativeDashboardService) + service_module = service_module.const_get(:Rest) if transport == :rest + service_module.const_get(:Client).new(&block) + end + + ## + # Determines whether the FeaturedContentNativeDashboardService service is supported by the current client. + # If true, you can retrieve a client object by calling {Google::Cloud::Chronicle.featured_content_native_dashboard_service}. + # If false, that method will raise an exception. This could happen if the given + # API version does not exist or does not support the FeaturedContentNativeDashboardService service, + # or if the versioned client gem needs an update to support the FeaturedContentNativeDashboardService service. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v1`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [boolean] Whether the service is available. + # + def self.featured_content_native_dashboard_service_available? version: :v1, transport: :grpc + require "google/cloud/chronicle/#{version.to_s.downcase}" + package_name = Google::Cloud::Chronicle + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + return false unless package_name + service_module = Google::Cloud::Chronicle.const_get package_name + return false unless service_module.const_defined? :FeaturedContentNativeDashboardService + service_module = service_module.const_get :FeaturedContentNativeDashboardService + if transport == :rest + return false unless service_module.const_defined? :Rest + service_module = service_module.const_get :Rest + end + service_module.const_defined? :Client + rescue ::LoadError + false + end + ## # Create a new client object for InstanceService. # diff --git a/google-cloud-chronicle/test/google/cloud/chronicle/client_test.rb b/google-cloud-chronicle/test/google/cloud/chronicle/client_test.rb index e0c86f852881..4fb10d7e02d3 100644 --- a/google-cloud-chronicle/test/google/cloud/chronicle/client_test.rb +++ b/google-cloud-chronicle/test/google/cloud/chronicle/client_test.rb @@ -41,6 +41,69 @@ def logger end end + def test_big_query_export_service_grpc + skip unless Google::Cloud::Chronicle.big_query_export_service_available? transport: :grpc + Gapic::ServiceStub.stub :new, DummyStub.new do + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + client = Google::Cloud::Chronicle.big_query_export_service transport: :grpc do |config| + config.credentials = grpc_channel + end + assert_kind_of Google::Cloud::Chronicle::V1::BigQueryExportService::Client, client + end + end + + def test_big_query_export_service_rest + skip unless Google::Cloud::Chronicle.big_query_export_service_available? transport: :rest + Gapic::Rest::ClientStub.stub :new, DummyStub.new do + client = Google::Cloud::Chronicle.big_query_export_service transport: :rest do |config| + config.credentials = :dummy_credentials + end + assert_kind_of Google::Cloud::Chronicle::V1::BigQueryExportService::Rest::Client, client + end + end + + def test_dashboard_query_service_grpc + skip unless Google::Cloud::Chronicle.dashboard_query_service_available? transport: :grpc + Gapic::ServiceStub.stub :new, DummyStub.new do + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + client = Google::Cloud::Chronicle.dashboard_query_service transport: :grpc do |config| + config.credentials = grpc_channel + end + assert_kind_of Google::Cloud::Chronicle::V1::DashboardQueryService::Client, client + end + end + + def test_dashboard_query_service_rest + skip unless Google::Cloud::Chronicle.dashboard_query_service_available? transport: :rest + Gapic::Rest::ClientStub.stub :new, DummyStub.new do + client = Google::Cloud::Chronicle.dashboard_query_service transport: :rest do |config| + config.credentials = :dummy_credentials + end + assert_kind_of Google::Cloud::Chronicle::V1::DashboardQueryService::Rest::Client, client + end + end + + def test_dashboard_chart_service_grpc + skip unless Google::Cloud::Chronicle.dashboard_chart_service_available? transport: :grpc + Gapic::ServiceStub.stub :new, DummyStub.new do + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + client = Google::Cloud::Chronicle.dashboard_chart_service transport: :grpc do |config| + config.credentials = grpc_channel + end + assert_kind_of Google::Cloud::Chronicle::V1::DashboardChartService::Client, client + end + end + + def test_dashboard_chart_service_rest + skip unless Google::Cloud::Chronicle.dashboard_chart_service_available? transport: :rest + Gapic::Rest::ClientStub.stub :new, DummyStub.new do + client = Google::Cloud::Chronicle.dashboard_chart_service transport: :rest do |config| + config.credentials = :dummy_credentials + end + assert_kind_of Google::Cloud::Chronicle::V1::DashboardChartService::Rest::Client, client + end + end + def test_data_access_control_service_grpc skip unless Google::Cloud::Chronicle.data_access_control_service_available? transport: :grpc Gapic::ServiceStub.stub :new, DummyStub.new do @@ -104,6 +167,48 @@ def test_entity_service_rest end end + def test_native_dashboard_service_grpc + skip unless Google::Cloud::Chronicle.native_dashboard_service_available? transport: :grpc + Gapic::ServiceStub.stub :new, DummyStub.new do + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + client = Google::Cloud::Chronicle.native_dashboard_service transport: :grpc do |config| + config.credentials = grpc_channel + end + assert_kind_of Google::Cloud::Chronicle::V1::NativeDashboardService::Client, client + end + end + + def test_native_dashboard_service_rest + skip unless Google::Cloud::Chronicle.native_dashboard_service_available? transport: :rest + Gapic::Rest::ClientStub.stub :new, DummyStub.new do + client = Google::Cloud::Chronicle.native_dashboard_service transport: :rest do |config| + config.credentials = :dummy_credentials + end + assert_kind_of Google::Cloud::Chronicle::V1::NativeDashboardService::Rest::Client, client + end + end + + def test_featured_content_native_dashboard_service_grpc + skip unless Google::Cloud::Chronicle.featured_content_native_dashboard_service_available? transport: :grpc + Gapic::ServiceStub.stub :new, DummyStub.new do + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + client = Google::Cloud::Chronicle.featured_content_native_dashboard_service transport: :grpc do |config| + config.credentials = grpc_channel + end + assert_kind_of Google::Cloud::Chronicle::V1::FeaturedContentNativeDashboardService::Client, client + end + end + + def test_featured_content_native_dashboard_service_rest + skip unless Google::Cloud::Chronicle.featured_content_native_dashboard_service_available? transport: :rest + Gapic::Rest::ClientStub.stub :new, DummyStub.new do + client = Google::Cloud::Chronicle.featured_content_native_dashboard_service transport: :rest do |config| + config.credentials = :dummy_credentials + end + assert_kind_of Google::Cloud::Chronicle::V1::FeaturedContentNativeDashboardService::Rest::Client, client + end + end + def test_instance_service_grpc skip unless Google::Cloud::Chronicle.instance_service_available? transport: :grpc Gapic::ServiceStub.stub :new, DummyStub.new do