diff --git a/google-cloud-run-client/AUTHENTICATION.md b/google-cloud-run-client/AUTHENTICATION.md index fce7edd96e28..a4733d9907cb 100644 --- a/google-cloud-run-client/AUTHENTICATION.md +++ b/google-cloud-run-client/AUTHENTICATION.md @@ -56,7 +56,7 @@ To configure a credentials file for an individual client initialization: ```ruby require "google/cloud/run" -client = Google::Cloud::Run.executions do |config| +client = Google::Cloud::Run.builds do |config| config.credentials = "path/to/credentialfile.json" end ``` @@ -70,7 +70,7 @@ Google::Cloud::Run.configure do |config| config.credentials = "path/to/credentialfile.json" end -client = Google::Cloud::Run.executions +client = Google::Cloud::Run.builds ``` ### Environment Variables @@ -100,7 +100,7 @@ require "google/cloud/run" ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/credentialfile.json" -client = Google::Cloud::Run.executions +client = Google::Cloud::Run.builds ``` ### Local ADC file diff --git a/google-cloud-run-client/Rakefile b/google-cloud-run-client/Rakefile index 2142bac18328..ed3b11d33d08 100644 --- a/google-cloud-run-client/Rakefile +++ b/google-cloud-run-client/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/run/v2/executions/credentials" - ::Google::Cloud::Run::V2::Executions::Credentials.env_vars.each do |path| + require "google/cloud/run/v2/builds/credentials" + ::Google::Cloud::Run::V2::Builds::Credentials.env_vars.each do |path| ENV[path] = nil end ENV["GOOGLE_CLOUD_PROJECT"] = project diff --git a/google-cloud-run-client/lib/google/cloud/run.rb b/google-cloud-run-client/lib/google/cloud/run.rb index f1e25b6e45d2..bbb0869d8667 100644 --- a/google-cloud-run-client/lib/google/cloud/run.rb +++ b/google-cloud-run-client/lib/google/cloud/run.rb @@ -45,6 +45,40 @@ module Google module Cloud module Run + ## + # Create a new client object for Builds. + # + # By default, this returns an instance of + # [Google::Cloud::Run::V2::Builds::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-run-v2/latest/Google-Cloud-Run-V2-Builds-Client) + # for a gRPC client for version V2 of the API. + # However, you can specify a different API version by passing it in the + # `version` parameter. If the Builds 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. + # + # ## About Builds + # + # Cloud Run Build Control Plane API + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v2`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [::Object] A client object for the specified version. + # + def self.builds version: :v2, transport: :grpc, &block + require "google/cloud/run/#{version.to_s.downcase}" + + package_name = Google::Cloud::Run + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + service_module = Google::Cloud::Run.const_get(package_name).const_get(:Builds) + service_module = service_module.const_get(:Rest) if transport == :rest + service_module.const_get(:Client).new(&block) + end + ## # Create a new client object for Executions. # diff --git a/google-cloud-run-client/test/google/cloud/run/client_test.rb b/google-cloud-run-client/test/google/cloud/run/client_test.rb index 2dcb14748cbe..bf717632ef81 100644 --- a/google-cloud-run-client/test/google/cloud/run/client_test.rb +++ b/google-cloud-run-client/test/google/cloud/run/client_test.rb @@ -33,6 +33,25 @@ def universe_domain end end + def test_builds_grpc + Gapic::ServiceStub.stub :new, DummyStub.new do + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + client = Google::Cloud::Run.builds transport: :grpc do |config| + config.credentials = grpc_channel + end + assert_kind_of Google::Cloud::Run::V2::Builds::Client, client + end + end + + def test_builds_rest + Gapic::Rest::ClientStub.stub :new, DummyStub.new do + client = Google::Cloud::Run.builds transport: :rest do |config| + config.credentials = :dummy_credentials + end + assert_kind_of Google::Cloud::Run::V2::Builds::Rest::Client, client + end + end + def test_executions_grpc Gapic::ServiceStub.stub :new, DummyStub.new do grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure