diff --git a/gapic-common/gapic-common.gemspec b/gapic-common/gapic-common.gemspec index 4ddd6ef86..0bfe23011 100644 --- a/gapic-common/gapic-common.gemspec +++ b/gapic-common/gapic-common.gemspec @@ -53,4 +53,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake", ">= 12.0" spec.add_development_dependency "redcarpet", "~> 3.0" spec.add_development_dependency "yard", "~> 0.9" + spec.add_development_dependency "debug" end diff --git a/gapic-common/lib/gapic/grpc.rb b/gapic-common/lib/gapic/grpc.rb index 28840aaa6..0f9c6b083 100644 --- a/gapic-common/lib/gapic/grpc.rb +++ b/gapic-common/lib/gapic/grpc.rb @@ -16,3 +16,4 @@ require "gapic/grpc/errors" require "gapic/grpc/service_stub" require "gapic/grpc/status_details" +require "gapic/routing_headers" diff --git a/gapic-common/lib/gapic/rest.rb b/gapic-common/lib/gapic/rest.rb index 474ce2634..21015245c 100644 --- a/gapic-common/lib/gapic/rest.rb +++ b/gapic-common/lib/gapic/rest.rb @@ -29,4 +29,6 @@ require "gapic/rest/paged_enumerable" require "gapic/rest/server_stream" require "gapic/rest/threaded_enumerator" +require "gapic/routing_headers" require "json" + diff --git a/gapic-common/lib/gapic/routing_headers.rb b/gapic-common/lib/gapic/routing_headers.rb new file mode 100644 index 000000000..de99b6ad6 --- /dev/null +++ b/gapic-common/lib/gapic/routing_headers.rb @@ -0,0 +1,15 @@ +# Copyright 2023 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. + +require "gapic/routing_headers/headers_extractor" diff --git a/gapic-common/lib/gapic/routing_headers/header_binding.rb b/gapic-common/lib/gapic/routing_headers/header_binding.rb new file mode 100644 index 000000000..5b0ff8fa3 --- /dev/null +++ b/gapic-common/lib/gapic/routing_headers/header_binding.rb @@ -0,0 +1,41 @@ +# Copyright 2023 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 Gapic + module RoutingHeaders + class HeadersExtractor + ## + # @private + class HeaderBinding + attr_reader :field + attr_reader :header_name + attr_reader :regex + + def initialize field, header_name=nil, regex=nil + @field = field + @header_name = header_name + @regex = regex + end + + ## + # @private + # Creates a new HeaderBinding. + # + def self.create field:, header_name: nil, regex: nil + HeaderBinding.new field, header_name, regex + end + end + end + end +end diff --git a/gapic-common/lib/gapic/routing_headers/headers_extractor.rb b/gapic-common/lib/gapic/routing_headers/headers_extractor.rb new file mode 100644 index 000000000..04efda4f4 --- /dev/null +++ b/gapic-common/lib/gapic/routing_headers/headers_extractor.rb @@ -0,0 +1,80 @@ +# Copyright 2023 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. + +require "gapic/routing_headers/header_binding" + +module Gapic + module RoutingHeaders + class HeadersExtractor + attr_accessor :bindings + + def initialize bindings = nil + @bindings = bindings || [] + end + + def with_bindings(field:, header_name: nil, regex: nil) + binding = HeaderBinding.create(field: field, header_name: header_name, regex: regex) + HeadersExtractor.new @bindings + [binding] + end + + def extract_headers request + header_params = {} + + unless request + err_msg = "Incorrect header extraction request: request is nil." + raise ::Gapic::Common::Error, err_msg + end + + @bindings.each do |header_binding| + field_value = get_field_val request, header_binding.field + next unless field_value + + if header_binding.regex && !field_value.is_a?(::String) + err_msg = "Header binding configuration is incorrect: regex" \ + "is given with a non-string field #{field}.\n" \ + "When the regex is present the field in the regex must be a ::String." + raise ::Gapic::Common::Error, err_msg + end + + header_name = header_binding.header_name || header_binding.field + + header_value = if header_binding.regex + match = header_binding.regex.match field_value + match[1] if match + else + field_value.to_s + end + + header_params[header_name] = header_value if header_value && !header_value.empty? + end + + header_params + end + + private + + def get_field_val request, field + field_path = field.split "." + + curr_submessage = request + field_path.each do |curr_field| + return nil unless curr_submessage.respond_to? curr_field + curr_submessage = curr_submessage.send curr_field + end + + return curr_submessage.to_s if curr_submessage + end + end + end +end diff --git a/gapic-common/test/gapic/routing_headers_test.rb b/gapic-common/test/gapic/routing_headers_test.rb new file mode 100644 index 000000000..685ff3401 --- /dev/null +++ b/gapic-common/test/gapic/routing_headers_test.rb @@ -0,0 +1,312 @@ +# Copyright 2023 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. + +require "test_helper" +require "gapic/routing_headers" + +class RoutingHeaderTest < Minitest::Test + # Extracting a field from the request to put into the routing header + # unchanged, with the key equal to the field name. + def test_simple_extraction + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "app_profile_id") + + test_cases = [ + { + request: OpenStruct.new(app_profile_id: "foo.123"), + expected: "app_profile_id=foo.123" + }, + { + request: OpenStruct.new(app_profile_id: "projects/100"), + expected: "app_profile_id=projects/100" + }, + { + request: OpenStruct.new(app_profile_id: ""), + expected: "" + } + ] + + assert_regex_matches extractor, test_cases + end + + # Extracting a field from the request to put into the routing header + # unchanged, with the key different from the field name. + def test_rename_extraction + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "app_profile_id", header_name: "routing_id") + + test_cases = [ + { + request: OpenStruct.new(app_profile_id: "foo123"), + expected: "routing_id=foo123" + }, + { + request: OpenStruct.new(app_profile_id: "projects/100"), + expected: "routing_id=projects/100" + }, + { + request: OpenStruct.new(app_profile_id: ""), + expected: "" + } + ] + + assert_regex_matches extractor, test_cases + end + + def test_nested_field + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "sub.name", header_name: "sub_name", regex: %r{^subs/([^/]+)/?$}) + .with_bindings(field: "app_profile_id", header_name: "legacy.routing_id", regex: %r{^(.+)$}) + + sub_message = OpenStruct.new name: "subs/100" + test_cases = [ + { + request: OpenStruct.new(app_profile_id: "routes/200"), + expected: "legacy.routing_id=routes/200" + }, + { + request: OpenStruct.new(sub: sub_message, app_profile_id: "routes/200"), + expected: "sub_name=100&legacy.routing_id=routes/200" + } + ] + + assert_regex_matches extractor, test_cases + end + + # Extracting a field from the request to put into the routing + # header, while matching a path template syntax on the field's value. + def test_field_match + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", regex: %r{^(projects/[^/]+/instances/[^/]+(?:/.*)?)$}) + .with_bindings(field: "table_name", regex: %r{^(regions/[^/]+/zones/[^/]+(?:/.*)?)$}) + + test_cases = [ + { + request: OpenStruct.new(table_name: "projects/100/instances/200"), + expected: "table_name=projects/100/instances/200" + }, + { + request: OpenStruct.new(table_name: "projects/100/instances/200/whatever"), + expected: "table_name=projects/100/instances/200/whatever" + }, + { + request: OpenStruct.new(table_name: "foo"), + expected: "" + } + ] + + assert_regex_matches extractor, test_cases + end + + # Extracting a single routing header key-value pair by matching a + # template syntax on (a part of) a single request field. + def test_simple_extract + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "routing_id", regex: %r{^(projects/[^/]+)(?:/.*)?$}) + + test_cases = [ + { + request: OpenStruct.new(table_name: "projects/100"), + expected: "routing_id=projects/100" + }, + { + request: OpenStruct.new(table_name: "projects/100/instances/200"), + expected: "routing_id=projects/100" + }, + { + request: OpenStruct.new(table_name: "regions/10/projects/100"), + expected: "" + }, + { + request: OpenStruct.new(table_name: "foo"), + expected: "" + } + ] + + assert_regex_matches extractor, test_cases + end + + # Extracting a single routing header key-value pair by matching + # several conflictingly named path templates on (parts of) a single request + # field. The last template to match "wins" the conflict. + def test_overlapping_patterns + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "routing_id", regex: %r{^(projects/[^/]+)(?:/.*)?$}) + .with_bindings(field: "table_name", header_name: "routing_id", regex: %r{^(projects/[^/]+/instances/[^/]+)(?:/.*)?$}) + + test_cases = [ + { + request: OpenStruct.new(table_name: "projects/100"), + expected: "routing_id=projects/100" + }, + { + request: OpenStruct.new(table_name: "projects/100/shards/300"), + expected: "routing_id=projects/100" + }, + { + request: OpenStruct.new(table_name: "projects/100/instances/200"), + expected: "routing_id=projects/100/instances/200" + }, + { + request: OpenStruct.new(table_name: "projects/100/instances/200/shards/300"), + expected: "routing_id=projects/100/instances/200" + }, + { + request: OpenStruct.new(table_name: "foo"), + expected: "" + }, + { + request: OpenStruct.new(table_name: "orgs/1/projects/100/instances/200"), + expected: "" + } + ] + + assert_regex_matches extractor, test_cases + end + + # Extracting multiple routing header key-value pairs by matching + # several non-conflicting path templates on (parts of) a single request field. + # Make the templates strict, so that if the `table_name` does not + # have an instance information, nothing is sent. + def test_multiple_keyvaluepairs_strict + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "project_id", regex: %r{^(projects/[^/]+)/instances/[^/]+(?:/.*)?$}) + .with_bindings(field: "table_name", header_name: "instance_id", regex: %r{^projects/[^/]+/(instances/[^/]+)(?:/.*)?$}) + + test_cases = [ + { + request: OpenStruct.new(table_name: "projects/100/instances/200/tables/300"), + expected: "project_id=projects/100&instance_id=instances/200" + }, + { + request: OpenStruct.new(table_name: "projects/100"), + expected: "" + } + ] + + assert_regex_matches extractor, test_cases + end + + # Extracting multiple routing header key-value pairs by matching + # several non-conflicting path templates on (parts of) a single request field. + # Make the templates loose, so that if the `table_name` does not + # have an instance information, just the project id part is sent. + def test_multiple_keyvaluepairs_loose + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "project_id", regex: %r{^(projects/[^/]+)(?:/.*)?$}) + .with_bindings(field: "table_name", header_name: "instance_id", regex: %r{^projects/[^/]+/(instances/[^/]+)(?:/.*)?$}) + + test_cases = [ + { + request: OpenStruct.new(table_name: "projects/100/instances/200/tables/300"), + expected: "project_id=projects/100&instance_id=instances/200" + }, + { + request: OpenStruct.new(table_name: "projects/100"), + expected: "project_id=projects/100" + } + ] + + assert_regex_matches extractor, test_cases + end + + # Extracting multiple routing header key-value pairs by matching + # several path templates on multiple request fields. + def test_multple_request_fields + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "project_id", regex: %r{^(projects/[^/]+)(?:/.*)?$}) + .with_bindings(field: "app_profile_id", header_name: "routing_id", regex: %r{^(.+)$}) + + test_cases = [ + { + request: OpenStruct.new(table_name: "projects/100/instances/200/tables/300", + app_profile_id: "profiles/profile_17"), + expected: "project_id=projects/100&routing_id=profiles/profile_17" + }, + { + request: OpenStruct.new(table_name: "projects/100"), + expected: "project_id=projects/100" + } + ] + + assert_regex_matches extractor, test_cases + end + + # Extracting a single routing header key-value pair by matching + # several conflictingly named path templates on several request fields. The + # last template to match "wins" the conflict. + def test_multple_conflicts_and_request_fields + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "routing_id", regex: %r{^(projects/[^/]+)(?:/.*)?$}) + .with_bindings(field: "table_name", header_name: "routing_id", regex: %r{^(regions/[^/]+)(?:/.*)?$}) + .with_bindings(field: "app_profile_id", header_name: "routing_id", regex: %r{^(.+)$}) + + test_cases = [ + { + request: OpenStruct.new(table_name: "projects/100/instances/200/tables/300", + app_profile_id: "profiles/profile_17"), + expected: "routing_id=profiles/profile_17" + }, + { + request: OpenStruct.new(table_name: "regions/100", app_profile_id: ""), + expected: "routing_id=regions/100" + } + ] + + assert_regex_matches extractor, test_cases + end + + # Test a complex scenario with a kitchen sink of concerns + def test_complex_scenario + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "table_location", regex: %r{^projects/[^/]+/(instances/[^/]+)/tables/[^/]+/?$}) + .with_bindings(field: "table_name", header_name: "table_location", regex: %r{^(regions/[^/]+/zones/[^/]+)/tables/[^/]+/?$}) + .with_bindings(field: "table_name", header_name: "routing_id", regex: %r{^(projects/[^/]+)(?:/.*)?$}) + .with_bindings(field: "app_profile_id", header_name: "routing_id", regex: %r{^(.+)$}) + .with_bindings(field: "app_profile_id", header_name: "routing_id", regex: %r{^profiles/([^/]+)/?$}) + + test_cases = [ + { + request: OpenStruct.new(table_name: "projects/100/instances/200/tables/300", + app_profile_id: "profiles/profile_17"), + expected: "table_location=instances/200&routing_id=profile_17" + }, + { + request: OpenStruct.new(table_name: "projects/100/instances/200/tables/300", + app_profile_id: "profile_17"), + expected: "table_location=instances/200&routing_id=profile_17" + }, + { + request: OpenStruct.new(table_name: "projects/100/instances/200/tables/300", + app_profile_id: ""), + expected: "table_location=instances/200&routing_id=projects/100" + } + ] + + assert_regex_matches extractor, test_cases + end + + def assert_regex_matches extractor, test_cases + test_cases.each do |test_case| + request = test_case[:request] + expected = test_case[:expected] + err_str = "Test case:\nRequest: \n#{request.pretty_inspect}\nExpected: \n#{expected.pretty_inspect}" + + headers = extractor.extract_headers request + err_str = "#{err_str}\nHeaders formed: \n #{headers.pretty_inspect}" + + assert_equal expected, headers.map { |key, value| "#{key}=#{value}" }.join("&"), err_str + end + end +end diff --git a/gapic-generator/templates/default/service/client/method/def/_routing_params.erb b/gapic-generator/templates/default/service/client/method/def/_routing_params.erb index 4904082ae..517d129c3 100644 --- a/gapic-generator/templates/default/service/client/method/def/_routing_params.erb +++ b/gapic-generator/templates/default/service/client/method/def/_routing_params.erb @@ -1,36 +1,21 @@ <%- assert_locals method -%> -header_params = {} +extractor = Gapic::RoutingHeaders::HeadersExtractor.new <%- if method.routing.explicit_params? -%> <%- method.routing.explicit_params.each do |key_name, routing_infos| -%> <%- routing_infos.each do |routing_info| -%> <%- if routing_info.pattern_matching_not_needed? -%> -if request.<%= routing_info.field.gsub(".", "&.") %> && !request.<%= routing_info.field %>.empty? - header_params["<%= key_name %>"] = request.<%= routing_info.field %> -end -<%- elsif routing_info.value_is_full_field? -%> -if request.<%= routing_info.field.gsub(".", "&.") %> && - %r{<%= routing_info.field_regex_str %>}.match?(request.<%= routing_info.field %>) - header_params["<%= key_name %>"] = request.<%= routing_info.field %> -end + .with_bindings(field: "<%= routing_info.field %>", header_name: "<%= key_name %>") <%- else -%> -if request.<%= routing_info.field.gsub(".", "&.") %> - regex_match = %r{<%= routing_info.field_full_regex_str %>}.match request.<%= routing_info.field %> - if regex_match - header_params["<%= key_name %>"] = regex_match["<%= key_name %>".to_s] - end -end + .with_bindings(field: "<%= routing_info.field %>", header_name: "<%= key_name %>", regex: %r{<%= routing_info.field_full_regex_str %>}) <%- end -%> <%- end -%> <%- end -%> - -request_params_header = URI.encode_www_form header_params <%- else -%> <%- method.routing_params.each_with_index do |routing_param, index| -%> -if request.<%= routing_param.gsub(".", "&.") %> - header_params["<%= routing_param %>"] = request.<%= routing_param %> -end + .with_bindings(field: "<%= routing_param %>") <%- end -%> - -request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") <%- end -%> + +header_params = extractor.extract_headers request +request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header diff --git a/gapic-generator/templates/default/service/rest/client/method/def/_options_defaults.erb b/gapic-generator/templates/default/service/rest/client/method/def/_options_defaults.erb index 93e107f75..876ad7b86 100644 --- a/gapic-generator/templates/default/service/rest/client/method/def/_options_defaults.erb +++ b/gapic-generator/templates/default/service/rest/client/method/def/_options_defaults.erb @@ -3,18 +3,22 @@ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults -call_metadata = @config.rpcs.<%= method.name %>.metadata.to_h +metadata = @config.rpcs.<%= method.name %>.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers -call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ +metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::<%= method.service.gem.version_name_full %>, transports_version_send: [:rest] -call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id +metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id +<%- if method.routing_params? && !method.client_streaming? -%> + +<%= render partial: "service/client/method/def/routing_params", locals: { method: method } -%> +<%- end -%> options.apply_defaults timeout: @config.rpcs.<%= method.name %>.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.<%= method.name %>.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/ads/googleads/lib/google/ads/google_ads/v7/services/campaign_service/client.rb b/shared/output/ads/googleads/lib/google/ads/google_ads/v7/services/campaign_service/client.rb index 6c5c7cb24..01f2d67e9 100644 --- a/shared/output/ads/googleads/lib/google/ads/google_ads/v7/services/campaign_service/client.rb +++ b/shared/output/ads/googleads/lib/google/ads/google_ads/v7/services/campaign_service/client.rb @@ -208,12 +208,11 @@ def get_campaign request, options = nil gapic_version: ::Google::Ads::GoogleAds::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource_name - header_params["resource_name"] = request.resource_name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource_name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_campaign.timeout, @@ -344,12 +343,11 @@ def mutate_campaigns request, options = nil gapic_version: ::Google::Ads::GoogleAds::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.customer_id - header_params["customer_id"] = request.customer_id - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "customer_id") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.mutate_campaigns.timeout, diff --git a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/addresses/rest/client.rb b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/addresses/rest/client.rb index 82001be5e..75f25030a 100644 --- a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/addresses/rest/client.rb +++ b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/addresses/rest/client.rb @@ -205,18 +205,25 @@ def aggregated_list request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.aggregated_list.metadata.to_h + metadata = @config.rpcs.aggregated_list.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.aggregated_list.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.aggregated_list.retry_policy options.apply_defaults timeout: @config.timeout, @@ -278,18 +285,27 @@ def delete request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete.metadata.to_h + metadata = @config.rpcs.delete.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "region") + .with_bindings(field: "address") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete.retry_policy options.apply_defaults timeout: @config.timeout, @@ -353,18 +369,27 @@ def get request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get.metadata.to_h + metadata = @config.rpcs.get.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "region") + .with_bindings(field: "address") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get.retry_policy options.apply_defaults timeout: @config.timeout, @@ -425,18 +450,26 @@ def insert request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.insert.metadata.to_h + metadata = @config.rpcs.insert.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "region") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.insert.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.insert.retry_policy options.apply_defaults timeout: @config.timeout, @@ -518,18 +551,26 @@ def list request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list.metadata.to_h + metadata = @config.rpcs.list.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "region") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/global_operations/rest/client.rb b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/global_operations/rest/client.rb index 376a4a414..7664535b9 100644 --- a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/global_operations/rest/client.rb +++ b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/global_operations/rest/client.rb @@ -171,18 +171,26 @@ def delete request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete.metadata.to_h + metadata = @config.rpcs.delete.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "operation") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete.retry_policy options.apply_defaults timeout: @config.timeout, @@ -235,18 +243,26 @@ def get request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get.metadata.to_h + metadata = @config.rpcs.get.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "operation") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/networks/rest/client.rb b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/networks/rest/client.rb index ffde38355..468eae1f1 100644 --- a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/networks/rest/client.rb +++ b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/networks/rest/client.rb @@ -211,18 +211,26 @@ def list_peering_routes request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_peering_routes.metadata.to_h + metadata = @config.rpcs.list_peering_routes.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "network") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_peering_routes.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_peering_routes.retry_policy options.apply_defaults timeout: @config.timeout, @@ -284,18 +292,26 @@ def remove_peering request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.remove_peering.metadata.to_h + metadata = @config.rpcs.remove_peering.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "network") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.remove_peering.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.remove_peering.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/region_instance_group_managers/rest/client.rb b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/region_instance_group_managers/rest/client.rb index 46186a5c9..543d676cc 100644 --- a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/region_instance_group_managers/rest/client.rb +++ b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/region_instance_group_managers/rest/client.rb @@ -199,18 +199,27 @@ def resize request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.resize.metadata.to_h + metadata = @config.rpcs.resize.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "region") + .with_bindings(field: "instance_group_manager") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.resize.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.resize.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/region_operations/rest/client.rb b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/region_operations/rest/client.rb index a3a4f3c77..24d465abd 100644 --- a/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/region_operations/rest/client.rb +++ b/shared/output/cloud/compute_small/lib/google/cloud/compute/v1/region_operations/rest/client.rb @@ -173,18 +173,27 @@ def delete request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete.metadata.to_h + metadata = @config.rpcs.delete.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "region") + .with_bindings(field: "operation") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete.retry_policy options.apply_defaults timeout: @config.timeout, @@ -239,18 +248,27 @@ def get request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get.metadata.to_h + metadata = @config.rpcs.get.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "region") + .with_bindings(field: "operation") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get.retry_policy options.apply_defaults timeout: @config.timeout, @@ -323,18 +341,26 @@ def list request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list.metadata.to_h + metadata = @config.rpcs.list.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "region") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list.retry_policy options.apply_defaults timeout: @config.timeout, @@ -394,18 +420,27 @@ def wait request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.wait.metadata.to_h + metadata = @config.rpcs.wait.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Compute::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "project") + .with_bindings(field: "region") + .with_bindings(field: "operation") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.wait.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.wait.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/grafeas_v1/lib/grafeas/v1/grafeas/client.rb b/shared/output/cloud/grafeas_v1/lib/grafeas/v1/grafeas/client.rb index 120948450..6a9a787c8 100644 --- a/shared/output/cloud/grafeas_v1/lib/grafeas/v1/grafeas/client.rb +++ b/shared/output/cloud/grafeas_v1/lib/grafeas/v1/grafeas/client.rb @@ -208,12 +208,11 @@ def get_occurrence request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_occurrence.timeout, @@ -307,12 +306,11 @@ def list_occurrences request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_occurrences.timeout, @@ -396,12 +394,11 @@ def delete_occurrence request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_occurrence.timeout, @@ -484,12 +481,11 @@ def create_occurrence request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_occurrence.timeout, @@ -572,12 +568,11 @@ def batch_create_occurrences request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.batch_create_occurrences.timeout, @@ -662,12 +657,11 @@ def update_occurrence request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_occurrence.timeout, @@ -749,12 +743,11 @@ def get_occurrence_note request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_occurrence_note.timeout, @@ -835,12 +828,11 @@ def get_note request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_note.timeout, @@ -934,12 +926,11 @@ def list_notes request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_notes.timeout, @@ -1021,12 +1012,11 @@ def delete_note request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_note.timeout, @@ -1111,12 +1101,11 @@ def create_note request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_note.timeout, @@ -1199,12 +1188,11 @@ def batch_create_notes request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.batch_create_notes.timeout, @@ -1289,12 +1277,11 @@ def update_note request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_note.timeout, @@ -1389,12 +1376,11 @@ def list_note_occurrences request, options = nil gapic_version: ::Grafeas::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_note_occurrences.timeout, diff --git a/shared/output/cloud/language_v1/lib/google/cloud/language/v1/language_service/rest/client.rb b/shared/output/cloud/language_v1/lib/google/cloud/language/v1/language_service/rest/client.rb index 19f008518..8280d296b 100644 --- a/shared/output/cloud/language_v1/lib/google/cloud/language/v1/language_service/rest/client.rb +++ b/shared/output/cloud/language_v1/lib/google/cloud/language/v1/language_service/rest/client.rb @@ -202,18 +202,18 @@ def analyze_sentiment request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.analyze_sentiment.metadata.to_h + metadata = @config.rpcs.analyze_sentiment.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.analyze_sentiment.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.analyze_sentiment.retry_policy options.apply_defaults timeout: @config.timeout, @@ -268,18 +268,18 @@ def analyze_entities request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.analyze_entities.metadata.to_h + metadata = @config.rpcs.analyze_entities.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.analyze_entities.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.analyze_entities.retry_policy options.apply_defaults timeout: @config.timeout, @@ -333,18 +333,18 @@ def analyze_entity_sentiment request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.analyze_entity_sentiment.metadata.to_h + metadata = @config.rpcs.analyze_entity_sentiment.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.analyze_entity_sentiment.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.analyze_entity_sentiment.retry_policy options.apply_defaults timeout: @config.timeout, @@ -399,18 +399,18 @@ def analyze_syntax request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.analyze_syntax.metadata.to_h + metadata = @config.rpcs.analyze_syntax.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.analyze_syntax.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.analyze_syntax.retry_policy options.apply_defaults timeout: @config.timeout, @@ -461,18 +461,18 @@ def classify_text request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.classify_text.metadata.to_h + metadata = @config.rpcs.classify_text.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.classify_text.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.classify_text.retry_policy options.apply_defaults timeout: @config.timeout, @@ -528,18 +528,18 @@ def annotate_text request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.annotate_text.metadata.to_h + metadata = @config.rpcs.annotate_text.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.annotate_text.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.annotate_text.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/location/lib/google/cloud/location/locations/client.rb b/shared/output/cloud/location/lib/google/cloud/location/locations/client.rb index c91344123..f264602d1 100644 --- a/shared/output/cloud/location/lib/google/cloud/location/locations/client.rb +++ b/shared/output/cloud/location/lib/google/cloud/location/locations/client.rb @@ -216,12 +216,11 @@ def list_locations request, options = nil gapic_version: ::Google::Cloud::Location::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_locations.timeout, @@ -302,12 +301,11 @@ def get_location request, options = nil gapic_version: ::Google::Cloud::Location::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_location.timeout, diff --git a/shared/output/cloud/location/lib/google/cloud/location/locations/rest/client.rb b/shared/output/cloud/location/lib/google/cloud/location/locations/rest/client.rb index b810f84e8..47f02fa7a 100644 --- a/shared/output/cloud/location/lib/google/cloud/location/locations/rest/client.rb +++ b/shared/output/cloud/location/lib/google/cloud/location/locations/rest/client.rb @@ -176,18 +176,25 @@ def list_locations request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_locations.metadata.to_h + metadata = @config.rpcs.list_locations.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Location::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_locations.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_locations.retry_policy options.apply_defaults timeout: @config.timeout, @@ -241,18 +248,25 @@ def get_location request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_location.metadata.to_h + metadata = @config.rpcs.get_location.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Location::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_location.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_location.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/secretmanager_v1beta1/lib/google/cloud/secret_manager/v1beta1/secret_manager_service/client.rb b/shared/output/cloud/secretmanager_v1beta1/lib/google/cloud/secret_manager/v1beta1/secret_manager_service/client.rb index de4dfab7f..f8056ecff 100644 --- a/shared/output/cloud/secretmanager_v1beta1/lib/google/cloud/secret_manager/v1beta1/secret_manager_service/client.rb +++ b/shared/output/cloud/secretmanager_v1beta1/lib/google/cloud/secret_manager/v1beta1/secret_manager_service/client.rb @@ -225,12 +225,11 @@ def list_secrets request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_secrets.timeout, @@ -320,12 +319,11 @@ def create_secret request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_secret.timeout, @@ -409,12 +407,11 @@ def add_secret_version request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.add_secret_version.timeout, @@ -494,12 +491,11 @@ def get_secret request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_secret.timeout, @@ -581,12 +577,11 @@ def update_secret request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.secret&.name - header_params["secret.name"] = request.secret.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "secret.name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_secret.timeout, @@ -667,12 +662,11 @@ def delete_secret request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_secret.timeout, @@ -768,12 +762,11 @@ def list_secret_versions request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_secret_versions.timeout, @@ -860,12 +853,11 @@ def get_secret_version request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_secret_version.timeout, @@ -949,12 +941,11 @@ def access_secret_version request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.access_secret_version.timeout, @@ -1038,12 +1029,11 @@ def disable_secret_version request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.disable_secret_version.timeout, @@ -1127,12 +1117,11 @@ def enable_secret_version request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.enable_secret_version.timeout, @@ -1217,12 +1206,11 @@ def destroy_secret_version request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.destroy_secret_version.timeout, @@ -1312,12 +1300,11 @@ def set_iam_policy request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource - header_params["resource"] = request.resource - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.set_iam_policy.timeout, @@ -1402,12 +1389,11 @@ def get_iam_policy request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource - header_params["resource"] = request.resource - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_iam_policy.timeout, @@ -1499,12 +1485,11 @@ def test_iam_permissions request, options = nil gapic_version: ::Google::Cloud::SecretManager::V1beta1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource - header_params["resource"] = request.resource - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.test_iam_permissions.timeout, diff --git a/shared/output/cloud/speech_v1/lib/google/cloud/speech/v1/speech/operations.rb b/shared/output/cloud/speech_v1/lib/google/cloud/speech/v1/speech/operations.rb index 3d1947cfc..dfef14fd4 100644 --- a/shared/output/cloud/speech_v1/lib/google/cloud/speech/v1/speech/operations.rb +++ b/shared/output/cloud/speech_v1/lib/google/cloud/speech/v1/speech/operations.rb @@ -184,12 +184,11 @@ def list_operations request, options = nil gapic_version: ::Google::Cloud::Speech::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_operations.timeout, @@ -280,12 +279,11 @@ def get_operation request, options = nil gapic_version: ::Google::Cloud::Speech::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, @@ -369,12 +367,11 @@ def delete_operation request, options = nil gapic_version: ::Google::Cloud::Speech::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, @@ -463,12 +460,11 @@ def cancel_operation request, options = nil gapic_version: ::Google::Cloud::Speech::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, diff --git a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/operations.rb b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/operations.rb index 4eae3a729..10f29dcdb 100644 --- a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/operations.rb +++ b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/operations.rb @@ -184,12 +184,11 @@ def list_operations request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_operations.timeout, @@ -280,12 +279,11 @@ def get_operation request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, @@ -369,12 +367,11 @@ def delete_operation request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, @@ -463,12 +460,11 @@ def cancel_operation request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, diff --git a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/rest/client.rb b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/rest/client.rb index 7caa8b442..e433e6374 100644 --- a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/rest/client.rb +++ b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/rest/client.rb @@ -214,18 +214,18 @@ def batch_annotate_images request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.batch_annotate_images.metadata.to_h + metadata = @config.rpcs.batch_annotate_images.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.batch_annotate_images.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.batch_annotate_images.retry_policy options.apply_defaults timeout: @config.timeout, @@ -296,18 +296,18 @@ def batch_annotate_files request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.batch_annotate_files.metadata.to_h + metadata = @config.rpcs.batch_annotate_files.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.batch_annotate_files.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.batch_annotate_files.retry_policy options.apply_defaults timeout: @config.timeout, @@ -381,18 +381,18 @@ def async_batch_annotate_images request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.async_batch_annotate_images.metadata.to_h + metadata = @config.rpcs.async_batch_annotate_images.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.async_batch_annotate_images.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.async_batch_annotate_images.retry_policy options.apply_defaults timeout: @config.timeout, @@ -462,18 +462,18 @@ def async_batch_annotate_files request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.async_batch_annotate_files.metadata.to_h + metadata = @config.rpcs.async_batch_annotate_files.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.async_batch_annotate_files.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.async_batch_annotate_files.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/rest/operations.rb b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/rest/operations.rb index d60b712c6..fbca916d7 100644 --- a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/rest/operations.rb +++ b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/image_annotator/rest/operations.rb @@ -145,18 +145,25 @@ def list_operations request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_operations.metadata.to_h + metadata = @config.rpcs.list_operations.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_operations.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_operations.retry_policy options.apply_defaults timeout: @config.timeout, @@ -210,18 +217,25 @@ def get_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_operation.metadata.to_h + metadata = @config.rpcs.get_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -276,18 +290,25 @@ def delete_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_operation.metadata.to_h + metadata = @config.rpcs.delete_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -347,18 +368,25 @@ def cancel_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.cancel_operation.metadata.to_h + metadata = @config.rpcs.cancel_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.cancel_operation.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/client.rb b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/client.rb index 62eb31991..ed43eef59 100644 --- a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/client.rb +++ b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/client.rb @@ -259,12 +259,11 @@ def create_product_set request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_product_set.timeout, @@ -361,12 +360,11 @@ def list_product_sets request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_product_sets.timeout, @@ -454,12 +452,11 @@ def get_product_set request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_product_set.timeout, @@ -551,12 +548,11 @@ def update_product_set request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.product_set&.name - header_params["product_set.name"] = request.product_set.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "product_set.name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_product_set.timeout, @@ -642,12 +638,11 @@ def delete_product_set request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_product_set.timeout, @@ -744,12 +739,11 @@ def create_product request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_product.timeout, @@ -846,12 +840,11 @@ def list_products request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_products.timeout, @@ -939,12 +932,11 @@ def get_product request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_product.timeout, @@ -1045,12 +1037,11 @@ def update_product request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.product&.name - header_params["product.name"] = request.product.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "product.name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_product.timeout, @@ -1137,12 +1128,11 @@ def delete_product request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_product.timeout, @@ -1251,12 +1241,11 @@ def create_reference_image request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_reference_image.timeout, @@ -1345,12 +1334,11 @@ def delete_reference_image request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_reference_image.timeout, @@ -1452,12 +1440,11 @@ def list_reference_images request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_reference_images.timeout, @@ -1545,12 +1532,11 @@ def get_reference_image request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_reference_image.timeout, @@ -1645,12 +1631,11 @@ def add_product_to_product_set request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.add_product_to_product_set.timeout, @@ -1738,12 +1723,11 @@ def remove_product_from_product_set request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.remove_product_from_product_set.timeout, @@ -1842,12 +1826,11 @@ def list_products_in_product_set request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_products_in_product_set.timeout, @@ -1949,12 +1932,11 @@ def import_product_sets request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.import_product_sets.timeout, @@ -2075,12 +2057,11 @@ def purge_products request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.purge_products.timeout, diff --git a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/operations.rb b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/operations.rb index 15eabae03..327d3c72d 100644 --- a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/operations.rb +++ b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/operations.rb @@ -184,12 +184,11 @@ def list_operations request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_operations.timeout, @@ -280,12 +279,11 @@ def get_operation request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, @@ -369,12 +367,11 @@ def delete_operation request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, @@ -463,12 +460,11 @@ def cancel_operation request, options = nil gapic_version: ::Google::Cloud::Vision::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, diff --git a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/rest/client.rb b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/rest/client.rb index 453ba5e3b..125f13588 100644 --- a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/rest/client.rb +++ b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/rest/client.rb @@ -226,18 +226,25 @@ def create_product_set request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.create_product_set.metadata.to_h + metadata = @config.rpcs.create_product_set.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_product_set.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.create_product_set.retry_policy options.apply_defaults timeout: @config.timeout, @@ -299,18 +306,25 @@ def list_product_sets request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_product_sets.metadata.to_h + metadata = @config.rpcs.list_product_sets.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_product_sets.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_product_sets.retry_policy options.apply_defaults timeout: @config.timeout, @@ -369,18 +383,25 @@ def get_product_set request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_product_set.metadata.to_h + metadata = @config.rpcs.get_product_set.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_product_set.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_product_set.retry_policy options.apply_defaults timeout: @config.timeout, @@ -443,18 +464,25 @@ def update_product_set request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.update_product_set.metadata.to_h + metadata = @config.rpcs.update_product_set.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "product_set.name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_product_set.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.update_product_set.retry_policy options.apply_defaults timeout: @config.timeout, @@ -511,18 +539,25 @@ def delete_product_set request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_product_set.metadata.to_h + metadata = @config.rpcs.delete_product_set.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_product_set.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_product_set.retry_policy options.apply_defaults timeout: @config.timeout, @@ -590,18 +625,25 @@ def create_product request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.create_product.metadata.to_h + metadata = @config.rpcs.create_product.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_product.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.create_product.retry_policy options.apply_defaults timeout: @config.timeout, @@ -663,18 +705,25 @@ def list_products request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_products.metadata.to_h + metadata = @config.rpcs.list_products.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_products.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_products.retry_policy options.apply_defaults timeout: @config.timeout, @@ -733,18 +782,25 @@ def get_product request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_product.metadata.to_h + metadata = @config.rpcs.get_product.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_product.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_product.retry_policy options.apply_defaults timeout: @config.timeout, @@ -816,18 +872,25 @@ def update_product request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.update_product.metadata.to_h + metadata = @config.rpcs.update_product.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "product.name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_product.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.update_product.retry_policy options.apply_defaults timeout: @config.timeout, @@ -885,18 +948,25 @@ def delete_product request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_product.metadata.to_h + metadata = @config.rpcs.delete_product.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_product.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_product.retry_policy options.apply_defaults timeout: @config.timeout, @@ -976,18 +1046,25 @@ def create_reference_image request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.create_reference_image.metadata.to_h + metadata = @config.rpcs.create_reference_image.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_reference_image.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.create_reference_image.retry_policy options.apply_defaults timeout: @config.timeout, @@ -1047,18 +1124,25 @@ def delete_reference_image request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_reference_image.metadata.to_h + metadata = @config.rpcs.delete_reference_image.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_reference_image.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_reference_image.retry_policy options.apply_defaults timeout: @config.timeout, @@ -1125,18 +1209,25 @@ def list_reference_images request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_reference_images.metadata.to_h + metadata = @config.rpcs.list_reference_images.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_reference_images.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_reference_images.retry_policy options.apply_defaults timeout: @config.timeout, @@ -1195,18 +1286,25 @@ def get_reference_image request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_reference_image.metadata.to_h + metadata = @config.rpcs.get_reference_image.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_reference_image.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_reference_image.retry_policy options.apply_defaults timeout: @config.timeout, @@ -1272,18 +1370,25 @@ def add_product_to_product_set request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.add_product_to_product_set.metadata.to_h + metadata = @config.rpcs.add_product_to_product_set.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.add_product_to_product_set.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.add_product_to_product_set.retry_policy options.apply_defaults timeout: @config.timeout, @@ -1342,18 +1447,25 @@ def remove_product_from_product_set request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.remove_product_from_product_set.metadata.to_h + metadata = @config.rpcs.remove_product_from_product_set.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.remove_product_from_product_set.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.remove_product_from_product_set.retry_policy options.apply_defaults timeout: @config.timeout, @@ -1417,18 +1529,25 @@ def list_products_in_product_set request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_products_in_product_set.metadata.to_h + metadata = @config.rpcs.list_products_in_product_set.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_products_in_product_set.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_products_in_product_set.retry_policy options.apply_defaults timeout: @config.timeout, @@ -1494,18 +1613,25 @@ def import_product_sets request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.import_product_sets.metadata.to_h + metadata = @config.rpcs.import_product_sets.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.import_product_sets.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.import_product_sets.retry_policy options.apply_defaults timeout: @config.timeout, @@ -1590,18 +1716,25 @@ def purge_products request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.purge_products.metadata.to_h + metadata = @config.rpcs.purge_products.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.purge_products.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.purge_products.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/rest/operations.rb b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/rest/operations.rb index 1333d7028..614f07cfe 100644 --- a/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/rest/operations.rb +++ b/shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/rest/operations.rb @@ -145,18 +145,25 @@ def list_operations request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_operations.metadata.to_h + metadata = @config.rpcs.list_operations.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_operations.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_operations.retry_policy options.apply_defaults timeout: @config.timeout, @@ -210,18 +217,25 @@ def get_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_operation.metadata.to_h + metadata = @config.rpcs.get_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -276,18 +290,25 @@ def delete_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_operation.metadata.to_h + metadata = @config.rpcs.delete_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -347,18 +368,25 @@ def cancel_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.cancel_operation.metadata.to_h + metadata = @config.rpcs.cancel_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Vision::V1::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.cancel_operation.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/garbage/lib/so/much/trash/garbage_service/operations.rb b/shared/output/gapic/templates/garbage/lib/so/much/trash/garbage_service/operations.rb index 428c841df..53a57921b 100644 --- a/shared/output/gapic/templates/garbage/lib/so/much/trash/garbage_service/operations.rb +++ b/shared/output/gapic/templates/garbage/lib/so/much/trash/garbage_service/operations.rb @@ -191,12 +191,11 @@ def list_operations request, options = nil gapic_version: ::Google::Garbage::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_operations.timeout, @@ -286,12 +285,11 @@ def get_operation request, options = nil gapic_version: ::Google::Garbage::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, @@ -373,12 +371,11 @@ def delete_operation request, options = nil gapic_version: ::Google::Garbage::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, @@ -465,12 +462,11 @@ def cancel_operation request, options = nil gapic_version: ::Google::Garbage::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, diff --git a/shared/output/gapic/templates/garbage/lib/so/much/trash/iam_policy/client.rb b/shared/output/gapic/templates/garbage/lib/so/much/trash/iam_policy/client.rb index c8ff34485..ad73bc64a 100644 --- a/shared/output/gapic/templates/garbage/lib/so/much/trash/iam_policy/client.rb +++ b/shared/output/gapic/templates/garbage/lib/so/much/trash/iam_policy/client.rb @@ -233,12 +233,11 @@ def set_iam_policy request, options = nil gapic_version: ::Google::Garbage::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource - header_params["resource"] = request.resource - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.set_iam_policy.timeout, @@ -322,12 +321,11 @@ def get_iam_policy request, options = nil gapic_version: ::Google::Garbage::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource - header_params["resource"] = request.resource - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_iam_policy.timeout, @@ -417,12 +415,11 @@ def test_iam_permissions request, options = nil gapic_version: ::Google::Garbage::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource - header_params["resource"] = request.resource - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.test_iam_permissions.timeout, diff --git a/shared/output/gapic/templates/showcase/Gemfile b/shared/output/gapic/templates/showcase/Gemfile index b4e2a20bb..28f4d681c 100644 --- a/shared/output/gapic/templates/showcase/Gemfile +++ b/shared/output/gapic/templates/showcase/Gemfile @@ -1,3 +1,5 @@ source "https://rubygems.org" +gem "gapic-common", path: "/home/virost/src/gapic-generator-ruby/gapic-common" + gemspec diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/compliance/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/compliance/client.rb index 795661f0f..de47788b3 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/compliance/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/compliance/client.rb @@ -486,24 +486,15 @@ def repeat_data_simple_path request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.info&.f_string - header_params["info.f_string"] = request.info.f_string - end - if request.info&.f_int32 - header_params["info.f_int32"] = request.info.f_int32 - end - if request.info&.f_double - header_params["info.f_double"] = request.info.f_double - end - if request.info&.f_bool - header_params["info.f_bool"] = request.info.f_bool - end - if request.info&.f_kingdom - header_params["info.f_kingdom"] = request.info.f_kingdom - end - - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "info.f_string") + .with_bindings(field: "info.f_int32") + .with_bindings(field: "info.f_double") + .with_bindings(field: "info.f_bool") + .with_bindings(field: "info.f_kingdom") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.repeat_data_simple_path.timeout, @@ -594,18 +585,13 @@ def repeat_data_path_resource request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.info&.f_string - header_params["info.f_string"] = request.info.f_string - end - if request.info&.f_child&.f_string - header_params["info.f_child.f_string"] = request.info.f_child.f_string - end - if request.info&.f_bool - header_params["info.f_bool"] = request.info.f_bool - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "info.f_string") + .with_bindings(field: "info.f_child.f_string") + .with_bindings(field: "info.f_bool") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.repeat_data_path_resource.timeout, @@ -696,15 +682,12 @@ def repeat_data_path_trailing_resource request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.info&.f_string - header_params["info.f_string"] = request.info.f_string - end - if request.info&.f_child&.f_string - header_params["info.f_child.f_string"] = request.info.f_child.f_string - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "info.f_string") + .with_bindings(field: "info.f_child.f_string") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.repeat_data_path_trailing_resource.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/compliance/rest/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/compliance/rest/client.rb index 2a46a2d78..5fbbf28c4 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/compliance/rest/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/compliance/rest/client.rb @@ -184,18 +184,18 @@ def repeat_data_body request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.repeat_data_body.metadata.to_h + metadata = @config.rpcs.repeat_data_body.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.repeat_data_body.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.repeat_data_body.retry_policy options.apply_defaults timeout: @config.timeout, @@ -261,18 +261,18 @@ def repeat_data_body_info request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.repeat_data_body_info.metadata.to_h + metadata = @config.rpcs.repeat_data_body_info.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.repeat_data_body_info.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.repeat_data_body_info.retry_policy options.apply_defaults timeout: @config.timeout, @@ -337,18 +337,18 @@ def repeat_data_query request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.repeat_data_query.metadata.to_h + metadata = @config.rpcs.repeat_data_query.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.repeat_data_query.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.repeat_data_query.retry_policy options.apply_defaults timeout: @config.timeout, @@ -414,18 +414,29 @@ def repeat_data_simple_path request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.repeat_data_simple_path.metadata.to_h + metadata = @config.rpcs.repeat_data_simple_path.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "info.f_string") + .with_bindings(field: "info.f_int32") + .with_bindings(field: "info.f_double") + .with_bindings(field: "info.f_bool") + .with_bindings(field: "info.f_kingdom") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.repeat_data_simple_path.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.repeat_data_simple_path.retry_policy options.apply_defaults timeout: @config.timeout, @@ -489,18 +500,27 @@ def repeat_data_path_resource request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.repeat_data_path_resource.metadata.to_h + metadata = @config.rpcs.repeat_data_path_resource.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "info.f_string") + .with_bindings(field: "info.f_child.f_string") + .with_bindings(field: "info.f_bool") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.repeat_data_path_resource.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.repeat_data_path_resource.retry_policy options.apply_defaults timeout: @config.timeout, @@ -564,18 +584,26 @@ def repeat_data_path_trailing_resource request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.repeat_data_path_trailing_resource.metadata.to_h + metadata = @config.rpcs.repeat_data_path_trailing_resource.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "info.f_string") + .with_bindings(field: "info.f_child.f_string") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.repeat_data_path_trailing_resource.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.repeat_data_path_trailing_resource.retry_policy options.apply_defaults timeout: @config.timeout, @@ -639,18 +667,18 @@ def repeat_data_body_put request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.repeat_data_body_put.metadata.to_h + metadata = @config.rpcs.repeat_data_body_put.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.repeat_data_body_put.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.repeat_data_body_put.retry_policy options.apply_defaults timeout: @config.timeout, @@ -714,18 +742,18 @@ def repeat_data_body_patch request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.repeat_data_body_patch.metadata.to_h + metadata = @config.rpcs.repeat_data_body_patch.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.repeat_data_body_patch.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.repeat_data_body_patch.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/client.rb index 11fe658f2..0c653cfff 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/client.rb @@ -229,43 +229,17 @@ def echo request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.header && !request.header.empty? - header_params["header"] = request.header - end - if request.header && !request.header.empty? - header_params["routing_id"] = request.header - end - if request.header && - %r{^regions/[^/]+/zones/[^/]+(?:/.*)?$}.match?(request.header) - header_params["table_name"] = request.header - end - if request.header && - %r{^projects/[^/]+/instances/[^/]+(?:/.*)?$}.match?(request.header) - header_params["table_name"] = request.header - end - if request.header - regex_match = %r{^(?projects/[^/]+)(?:/.*)?$}.match request.header - if regex_match - header_params["super_id"] = regex_match["super_id".to_s] - end - end - if request.header - regex_match = %r{^projects/[^/]+/(?instances/[^/]+)(?:/.*)?$}.match request.header - if regex_match - header_params["instance_id"] = regex_match["instance_id".to_s] - end - end - if request.other_header && !request.other_header.empty? - header_params["baz"] = request.other_header - end - if request.other_header - regex_match = %r{^(?projects/[^/]+)(?:/.*)?$}.match request.other_header - if regex_match - header_params["qux"] = regex_match["qux".to_s] - end - end - + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "header", header_name: "header") + .with_bindings(field: "header", header_name: "routing_id") + .with_bindings(field: "header", header_name: "table_name", regex: %r{^(?regions/[^/]+/zones/[^/]+(?:/.*)?)/?$}) + .with_bindings(field: "header", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+(?:/.*)?)/?$}) + .with_bindings(field: "header", header_name: "super_id", regex: %r{^(?projects/[^/]+)(?:/.*)?$}) + .with_bindings(field: "header", header_name: "instance_id", regex: %r{^projects/[^/]+/(?instances/[^/]+)(?:/.*)?$}) + .with_bindings(field: "other_header", header_name: "baz") + .with_bindings(field: "other_header", header_name: "qux", regex: %r{^(?projects/[^/]+)(?:/.*)?$}) + + header_params = extractor.extract_headers request request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/operations.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/operations.rb index c2abb2bc5..f6f90baa0 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/operations.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/operations.rb @@ -278,12 +278,11 @@ def get_operation request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, @@ -365,12 +364,11 @@ def delete_operation request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, @@ -457,12 +455,11 @@ def cancel_operation request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/rest/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/rest/client.rb index 75f7d78b8..538055e63 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/rest/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/rest/client.rb @@ -196,18 +196,32 @@ def echo request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.echo.metadata.to_h + metadata = @config.rpcs.echo.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "header", header_name: "header") + .with_bindings(field: "header", header_name: "routing_id") + .with_bindings(field: "header", header_name: "table_name", regex: %r{^(?regions/[^/]+/zones/[^/]+(?:/.*)?)/?$}) + .with_bindings(field: "header", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+(?:/.*)?)/?$}) + .with_bindings(field: "header", header_name: "super_id", regex: %r{^(?projects/[^/]+)(?:/.*)?$}) + .with_bindings(field: "header", header_name: "instance_id", regex: %r{^projects/[^/]+/(?instances/[^/]+)(?:/.*)?$}) + .with_bindings(field: "other_header", header_name: "baz") + .with_bindings(field: "other_header", header_name: "qux", regex: %r{^(?projects/[^/]+)(?:/.*)?$}) + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.echo.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.echo.retry_policy options.apply_defaults timeout: @config.timeout, @@ -257,18 +271,18 @@ def expand request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.expand.metadata.to_h + metadata = @config.rpcs.expand.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.expand.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.expand.retry_policy options.apply_defaults timeout: @config.timeout, @@ -329,18 +343,18 @@ def paged_expand request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.paged_expand.metadata.to_h + metadata = @config.rpcs.paged_expand.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.paged_expand.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.paged_expand.retry_policy options.apply_defaults timeout: @config.timeout, @@ -401,18 +415,18 @@ def paged_expand_legacy request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.paged_expand_legacy.metadata.to_h + metadata = @config.rpcs.paged_expand_legacy.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.paged_expand_legacy.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.paged_expand_legacy.retry_policy options.apply_defaults timeout: @config.timeout, @@ -473,18 +487,18 @@ def paged_expand_legacy_mapped request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.paged_expand_legacy_mapped.metadata.to_h + metadata = @config.rpcs.paged_expand_legacy_mapped.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.paged_expand_legacy_mapped.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.paged_expand_legacy_mapped.retry_policy options.apply_defaults timeout: @config.timeout, @@ -545,18 +559,18 @@ def wait request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.wait.metadata.to_h + metadata = @config.rpcs.wait.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.wait.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.wait.retry_policy options.apply_defaults timeout: @config.timeout, @@ -615,18 +629,18 @@ def block request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.block.metadata.to_h + metadata = @config.rpcs.block.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.block.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.block.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/rest/operations.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/rest/operations.rb index 885f787e2..a4b173af4 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/rest/operations.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/rest/operations.rb @@ -152,18 +152,18 @@ def list_operations request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_operations.metadata.to_h + metadata = @config.rpcs.list_operations.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.list_operations.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_operations.retry_policy options.apply_defaults timeout: @config.timeout, @@ -218,18 +218,25 @@ def get_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_operation.metadata.to_h + metadata = @config.rpcs.get_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -284,18 +291,25 @@ def delete_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_operation.metadata.to_h + metadata = @config.rpcs.delete_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -355,18 +369,25 @@ def cancel_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.cancel_operation.metadata.to_h + metadata = @config.rpcs.cancel_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.cancel_operation.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/identity/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/identity/client.rb index 54f09a785..30f22f183 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/identity/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/identity/client.rb @@ -279,12 +279,11 @@ def get_user request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_user.timeout, @@ -365,12 +364,11 @@ def update_user request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.user&.name - header_params["user.name"] = request.user.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "user.name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_user.timeout, @@ -448,12 +446,11 @@ def delete_user request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_user.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/identity/rest/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/identity/rest/client.rb index 4be1b7958..86a767455 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/identity/rest/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/identity/rest/client.rb @@ -171,18 +171,18 @@ def create_user request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.create_user.metadata.to_h + metadata = @config.rpcs.create_user.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.create_user.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.create_user.retry_policy options.apply_defaults timeout: @config.timeout, @@ -233,18 +233,25 @@ def get_user request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_user.metadata.to_h + metadata = @config.rpcs.get_user.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_user.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_user.retry_policy options.apply_defaults timeout: @config.timeout, @@ -298,18 +305,25 @@ def update_user request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.update_user.metadata.to_h + metadata = @config.rpcs.update_user.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "user.name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_user.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.update_user.retry_policy options.apply_defaults timeout: @config.timeout, @@ -360,18 +374,25 @@ def delete_user request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_user.metadata.to_h + metadata = @config.rpcs.delete_user.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_user.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_user.retry_policy options.apply_defaults timeout: @config.timeout, @@ -427,18 +448,18 @@ def list_users request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_users.metadata.to_h + metadata = @config.rpcs.list_users.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.list_users.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_users.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/client.rb index 43f80e29c..bee76049f 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/client.rb @@ -295,12 +295,11 @@ def get_room request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_room.timeout, @@ -381,12 +380,11 @@ def update_room request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.room&.name - header_params["room.name"] = request.room.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "room.name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_room.timeout, @@ -464,12 +462,11 @@ def delete_room request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_room.timeout, @@ -640,12 +637,11 @@ def create_blurb request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_blurb.timeout, @@ -723,12 +719,11 @@ def get_blurb request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_blurb.timeout, @@ -809,12 +804,11 @@ def update_blurb request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.blurb&.name - header_params["blurb.name"] = request.blurb.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "blurb.name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_blurb.timeout, @@ -892,12 +886,11 @@ def delete_blurb request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_blurb.timeout, @@ -990,12 +983,11 @@ def list_blurbs request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_blurbs.timeout, @@ -1097,12 +1089,11 @@ def search_blurbs request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.search_blurbs.timeout, @@ -1187,12 +1178,11 @@ def stream_blurbs request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.stream_blurbs.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/operations.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/operations.rb index 7f62217a9..cefeef77f 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/operations.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/operations.rb @@ -278,12 +278,11 @@ def get_operation request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, @@ -365,12 +364,11 @@ def delete_operation request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, @@ -457,12 +455,11 @@ def cancel_operation request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/rest/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/rest/client.rb index 01f21f9c4..2aaec1a1c 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/rest/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/rest/client.rb @@ -187,18 +187,18 @@ def create_room request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.create_room.metadata.to_h + metadata = @config.rpcs.create_room.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.create_room.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.create_room.retry_policy options.apply_defaults timeout: @config.timeout, @@ -249,18 +249,25 @@ def get_room request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_room.metadata.to_h + metadata = @config.rpcs.get_room.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_room.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_room.retry_policy options.apply_defaults timeout: @config.timeout, @@ -314,18 +321,25 @@ def update_room request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.update_room.metadata.to_h + metadata = @config.rpcs.update_room.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "room.name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_room.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.update_room.retry_policy options.apply_defaults timeout: @config.timeout, @@ -376,18 +390,25 @@ def delete_room request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_room.metadata.to_h + metadata = @config.rpcs.delete_room.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_room.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_room.retry_policy options.apply_defaults timeout: @config.timeout, @@ -443,18 +464,18 @@ def list_rooms request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_rooms.metadata.to_h + metadata = @config.rpcs.list_rooms.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.list_rooms.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_rooms.retry_policy options.apply_defaults timeout: @config.timeout, @@ -512,18 +533,25 @@ def create_blurb request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.create_blurb.metadata.to_h + metadata = @config.rpcs.create_blurb.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_blurb.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.create_blurb.retry_policy options.apply_defaults timeout: @config.timeout, @@ -574,18 +602,25 @@ def get_blurb request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_blurb.metadata.to_h + metadata = @config.rpcs.get_blurb.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_blurb.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_blurb.retry_policy options.apply_defaults timeout: @config.timeout, @@ -639,18 +674,25 @@ def update_blurb request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.update_blurb.metadata.to_h + metadata = @config.rpcs.update_blurb.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "blurb.name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.update_blurb.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.update_blurb.retry_policy options.apply_defaults timeout: @config.timeout, @@ -701,18 +743,25 @@ def delete_blurb request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_blurb.metadata.to_h + metadata = @config.rpcs.delete_blurb.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_blurb.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_blurb.retry_policy options.apply_defaults timeout: @config.timeout, @@ -772,18 +821,25 @@ def list_blurbs request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_blurbs.metadata.to_h + metadata = @config.rpcs.list_blurbs.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_blurbs.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_blurbs.retry_policy options.apply_defaults timeout: @config.timeout, @@ -851,18 +907,25 @@ def search_blurbs request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.search_blurbs.metadata.to_h + metadata = @config.rpcs.search_blurbs.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.search_blurbs.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.search_blurbs.retry_policy options.apply_defaults timeout: @config.timeout, @@ -913,18 +976,25 @@ def stream_blurbs request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.stream_blurbs.metadata.to_h + metadata = @config.rpcs.stream_blurbs.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.stream_blurbs.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.stream_blurbs.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/rest/operations.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/rest/operations.rb index 55b1e9c07..ecd2c060c 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/rest/operations.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/messaging/rest/operations.rb @@ -152,18 +152,18 @@ def list_operations request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_operations.metadata.to_h + metadata = @config.rpcs.list_operations.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.list_operations.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_operations.retry_policy options.apply_defaults timeout: @config.timeout, @@ -218,18 +218,25 @@ def get_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_operation.metadata.to_h + metadata = @config.rpcs.get_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -284,18 +291,25 @@ def delete_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_operation.metadata.to_h + metadata = @config.rpcs.delete_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -355,18 +369,25 @@ def cancel_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.cancel_operation.metadata.to_h + metadata = @config.rpcs.cancel_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.cancel_operation.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/testing/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/testing/client.rb index b9c7949e0..b340c9425 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/testing/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/testing/client.rb @@ -282,12 +282,11 @@ def get_session request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_session.timeout, @@ -450,12 +449,11 @@ def delete_session request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_session.timeout, @@ -535,12 +533,11 @@ def report_session request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.report_session.timeout, @@ -628,12 +625,11 @@ def list_tests request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.parent - header_params["parent"] = request.parent - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_tests.timeout, @@ -717,12 +713,11 @@ def delete_test request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_test.timeout, @@ -807,12 +802,11 @@ def verify_test request, options = nil gapic_version: ::Google::Showcase::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.verify_test.timeout, diff --git a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/testing/rest/client.rb b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/testing/rest/client.rb index c25496882..e81220a91 100644 --- a/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/testing/rest/client.rb +++ b/shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/testing/rest/client.rb @@ -174,18 +174,18 @@ def create_session request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.create_session.metadata.to_h + metadata = @config.rpcs.create_session.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.create_session.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.create_session.retry_policy options.apply_defaults timeout: @config.timeout, @@ -236,18 +236,25 @@ def get_session request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_session.metadata.to_h + metadata = @config.rpcs.get_session.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_session.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_session.retry_policy options.apply_defaults timeout: @config.timeout, @@ -300,18 +307,18 @@ def list_sessions request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_sessions.metadata.to_h + metadata = @config.rpcs.list_sessions.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.list_sessions.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_sessions.retry_policy options.apply_defaults timeout: @config.timeout, @@ -364,18 +371,25 @@ def delete_session request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_session.metadata.to_h + metadata = @config.rpcs.delete_session.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_session.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_session.retry_policy options.apply_defaults timeout: @config.timeout, @@ -428,18 +442,25 @@ def report_session request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.report_session.metadata.to_h + metadata = @config.rpcs.report_session.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.report_session.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.report_session.retry_policy options.apply_defaults timeout: @config.timeout, @@ -494,18 +515,25 @@ def list_tests request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_tests.metadata.to_h + metadata = @config.rpcs.list_tests.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "parent") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_tests.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_tests.retry_policy options.apply_defaults timeout: @config.timeout, @@ -563,18 +591,25 @@ def delete_test request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_test.metadata.to_h + metadata = @config.rpcs.delete_test.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_test.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_test.retry_policy options.apply_defaults timeout: @config.timeout, @@ -632,18 +667,25 @@ def verify_test request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.verify_test.metadata.to_h + metadata = @config.rpcs.verify_test.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Showcase::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.verify_test.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.verify_test.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/showcase/test/echo_headers.rb b/shared/output/gapic/templates/showcase/test/echo_headers.rb new file mode 100644 index 000000000..4809f8395 --- /dev/null +++ b/shared/output/gapic/templates/showcase/test/echo_headers.rb @@ -0,0 +1,191 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "helper" +require "gapic/rest" +require "google/showcase/v1beta1/echo" +require "google/showcase/v1beta1/echo/rest" + + +class ::Google::Showcase::V1beta1::Echo::HeadersTest < Minitest::Test + def setup client=nil + @client = client + end + + # Currently cannot be done from the standard test battery in routing.proto: + # - test_nested_field (no nested field in EchoRequest) + # - test_overlapping_patterns -- no conflicting overlapping patterns + # - test_multiple_keyvaluepairs_strict -- requires a very specific pattern setup + # - test_multiple_conflicts_and_request_fields -- no conflicts + # - test_complex_scenario -- no conflicts + + # Extracting a field from the request to put into the routing header + # unchanged, with the key equal to the field name. + # Extracting a field from the request to put into the routing header + # unchanged, with the key different from the field name. + # + # This tests: + # - test_simple_extraction + # - test_rename_extraction + def test_simple_and_rename_extraction + test_cases = [ + { + header_field: "foo.123", + expected: ["header=foo.123", "routing_id=foo.123"] + }, + { + header_field: "projects/100", + expected: "super_id=projects/100" + }, + ] + + assert_matches @client, test_cases + end + + # Extracting a field from the request to put into the routing + # header, while matching a path template syntax on the field's value. + # Extracting a single routing header key-value pair by matching a + # template syntax on (a part of) a single request field. + # + # This tests: + # - test_field_match + # - test_simple_extract + # - test_multiple_keyvaluepairs_loose + def test_field_match_simple_extract_multiple_kvp + test_cases = [ + { + header_field: "projects/100/instances/200", + expected: ["super_id=projects/100", "table_name=projects/100/instances/200", "instance_id=instances/200"] + }, + { + header_field: "regions/100/zones/200", + expected: ["table_name=regions/100/zones/200",] + }, + { + header_field: "projects/100/instances/200/whatever", + expected: ["super_id=projects/100", "table_name=projects/100/instances/200/whatever", "instance_id=instances/200"] + }, + ] + + assert_matches @client, test_cases + end + + # Extracting multiple routing header key-value pairs by matching + # several path templates on multiple request fields. + # + # This tests: + # - test_multiple_request_fields + # - test_complex_scenario (only partially since no conflicts) + def test_multiple_request_fields_conflicts + test_cases = [ + { + header_field: "projects/100", + other_header_field: "projects/100/misc", + expected: ["super_id=projects/100", "qux=projects/100", "baz=projects/100/misc"] + }, + { + header_field: "projects/100", + other_header_field: "foo.123", + expected: ["super_id=projects/100", "baz=foo.123"] + }, + ] + + assert_matches @client, test_cases + end + + def assert_matches client, test_cases + return unless client + test_cases.each do |test_case| + request = { content: "foo", header: test_case[:header_field] } + request[:other_header] = test_case[:other_header_field] if test_case.key? :other_header_field + @client.echo request do |response, operation| + routing_keyvals = extract_routing_keyvals operation + + expected = test_case[:expected] + expected = [expected] unless expected.is_a? ::Array + + refute_nil routing_keyvals + routing_keys = routing_keyvals.split("&").map { |kvp| kvp.split("=")[0]} + expected_keys = expected.map {|kvp| kvp.split("=")[0]} + + expected_keys.append("header") unless expected_keys.include? "header" + expected_keys.append("routing_id") unless expected_keys.include? "routing_id" + + err_str = "Test case keys mismatch:\nRequest: \n#{request.pretty_inspect}\nExpected: \n#{expected.pretty_inspect}" \ + "\nHeaders formed: \n #{routing_keys}" + + assert_equal expected_keys.sort, routing_keys.sort, err_str + + expected.each do |expected_elem| + expected_elem_encoded = URI.encode_www_form([expected_elem.split("=")]) + + err_str = "Test case:\nRequest: \n#{request.pretty_inspect}\nExpected: \n#{expected_elem.pretty_inspect}" \ + "\nEncoded: #{expected_elem_encoded}" + + err_str = "#{err_str}\nRouting header formed: \n #{routing_keys}" + + assert_match expected_elem_encoded, routing_keyvals, err_str + end + end + end + end + + def extract_routing_keyvals operation + end +end + +class ::Google::Showcase::V1beta1::Echo::GrpcHeadersTest < ::Google::Showcase::V1beta1::Echo::HeadersTest + def setup + client = Google::Showcase::V1beta1::Echo::Client.new do |config| + config.credentials = GRPC::Core::Channel.new "localhost:7469", nil, :this_channel_is_insecure + end + + super client + end + + def extract_routing_keyvals operation + assert_kind_of ::Hash, operation.metadata + assert operation.metadata.key? "x-goog-request-params" + operation.metadata["x-goog-request-params"] + end +end + +class ::Google::Showcase::V1beta1::Echo::RestHeadersTest < ::Google::Showcase::V1beta1::Echo::HeadersTest + def setup + client = Google::Showcase::V1beta1::Echo::Rest::Client.new do |config| + config.endpoint = "http://localhost:7469" + config.credentials = :this_channel_is_insecure + end + + super client + end + + def extract_routing_keyvals response + assert_kind_of ::Hash, response.env.request_headers + assert response.env.request_headers.key? "X-goog-request-params" + response.env.request_headers["x-goog-request-params"] + end +end diff --git a/shared/output/gapic/templates/testing/lib/testing/grpc_service_config/service_no_retry/rest/client.rb b/shared/output/gapic/templates/testing/lib/testing/grpc_service_config/service_no_retry/rest/client.rb index 0ba3cf97d..aceff39da 100644 --- a/shared/output/gapic/templates/testing/lib/testing/grpc_service_config/service_no_retry/rest/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/grpc_service_config/service_no_retry/rest/client.rb @@ -171,18 +171,18 @@ def no_retry_method request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.no_retry_method.metadata.to_h + metadata = @config.rpcs.no_retry_method.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.no_retry_method.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.no_retry_method.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/grpc_service_config/service_with_retries/rest/client.rb b/shared/output/gapic/templates/testing/lib/testing/grpc_service_config/service_with_retries/rest/client.rb index fc5b9f478..30b84e572 100644 --- a/shared/output/gapic/templates/testing/lib/testing/grpc_service_config/service_with_retries/rest/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/grpc_service_config/service_with_retries/rest/client.rb @@ -181,18 +181,18 @@ def service_level_retry_method request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.service_level_retry_method.metadata.to_h + metadata = @config.rpcs.service_level_retry_method.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.service_level_retry_method.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.service_level_retry_method.retry_policy options.apply_defaults timeout: @config.timeout, @@ -233,18 +233,18 @@ def method_level_retry_method request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.method_level_retry_method.metadata.to_h + metadata = @config.rpcs.method_level_retry_method.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.method_level_retry_method.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.method_level_retry_method.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/mixins/service_with_loc/rest/client.rb b/shared/output/gapic/templates/testing/lib/testing/mixins/service_with_loc/rest/client.rb index 29e88eeda..d02174ef4 100644 --- a/shared/output/gapic/templates/testing/lib/testing/mixins/service_with_loc/rest/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/mixins/service_with_loc/rest/client.rb @@ -171,18 +171,18 @@ def call_method request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.call_method.metadata.to_h + metadata = @config.rpcs.call_method.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.call_method.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.call_method.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/operations.rb b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/operations.rb index a4ec6b3c6..008819166 100644 --- a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/operations.rb +++ b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/operations.rb @@ -277,12 +277,11 @@ def get_operation request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, @@ -364,12 +363,11 @@ def delete_operation request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, @@ -456,12 +454,11 @@ def cancel_operation request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.name - header_params["name"] = request.name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/rest/client.rb b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/rest/client.rb index fe0b6c5f2..d285d2718 100644 --- a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/rest/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/rest/client.rb @@ -221,18 +221,18 @@ def plain_lro_rpc request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.plain_lro_rpc.metadata.to_h + metadata = @config.rpcs.plain_lro_rpc.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.plain_lro_rpc.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.plain_lro_rpc.retry_policy options.apply_defaults timeout: @config.timeout, @@ -290,18 +290,18 @@ def another_lro_rpc request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.another_lro_rpc.metadata.to_h + metadata = @config.rpcs.another_lro_rpc.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.another_lro_rpc.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.another_lro_rpc.retry_policy options.apply_defaults timeout: @config.timeout, @@ -354,18 +354,18 @@ def non_copy_another_lro_rpc request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.non_copy_another_lro_rpc.metadata.to_h + metadata = @config.rpcs.non_copy_another_lro_rpc.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.non_copy_another_lro_rpc.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.non_copy_another_lro_rpc.retry_policy options.apply_defaults timeout: @config.timeout, @@ -421,18 +421,18 @@ def aip_lro request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.aip_lro.metadata.to_h + metadata = @config.rpcs.aip_lro.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.aip_lro.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.aip_lro.retry_policy options.apply_defaults timeout: @config.timeout, @@ -483,18 +483,18 @@ def no_lro request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.no_lro.metadata.to_h + metadata = @config.rpcs.no_lro.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.no_lro.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.no_lro.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/rest/operations.rb b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/rest/operations.rb index 11ba5ccbd..c963b74cd 100644 --- a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/rest/operations.rb +++ b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/all_subclients_consumer/rest/operations.rb @@ -151,18 +151,18 @@ def list_operations request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.list_operations.metadata.to_h + metadata = @config.rpcs.list_operations.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.list_operations.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.list_operations.retry_policy options.apply_defaults timeout: @config.timeout, @@ -217,18 +217,25 @@ def get_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_operation.metadata.to_h + metadata = @config.rpcs.get_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -283,18 +290,25 @@ def delete_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.delete_operation.metadata.to_h + metadata = @config.rpcs.delete_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.delete_operation.retry_policy options.apply_defaults timeout: @config.timeout, @@ -354,18 +368,25 @@ def cancel_operation request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.cancel_operation.metadata.to_h + metadata = @config.rpcs.cancel_operation.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.cancel_operation.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/another_lro_provider/rest/client.rb b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/another_lro_provider/rest/client.rb index 796dff5d2..b5650203d 100644 --- a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/another_lro_provider/rest/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/another_lro_provider/rest/client.rb @@ -179,18 +179,18 @@ def get_another request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get_another.metadata.to_h + metadata = @config.rpcs.get_another.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.get_another.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get_another.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/plain_lro_consumer/rest/client.rb b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/plain_lro_consumer/rest/client.rb index 511ba00c9..e3aa65532 100644 --- a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/plain_lro_consumer/rest/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/plain_lro_consumer/rest/client.rb @@ -192,18 +192,18 @@ def plain_lro_rpc request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.plain_lro_rpc.metadata.to_h + metadata = @config.rpcs.plain_lro_rpc.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.plain_lro_rpc.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.plain_lro_rpc.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/plain_lro_provider/rest/client.rb b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/plain_lro_provider/rest/client.rb index cd887d156..cda555648 100644 --- a/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/plain_lro_provider/rest/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/nonstandard_lro_grpc/plain_lro_provider/rest/client.rb @@ -179,18 +179,18 @@ def get request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.get.metadata.to_h + metadata = @config.rpcs.get.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.get.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.get.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_explicit_headers/client.rb b/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_explicit_headers/client.rb index ba1a4e334..f395f1dfe 100644 --- a/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_explicit_headers/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_explicit_headers/client.rb @@ -221,11 +221,10 @@ def plain_no_template request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.table_name && !request.table_name.empty? - header_params["table_name"] = request.table_name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "table_name") + header_params = extractor.extract_headers request request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header @@ -312,12 +311,10 @@ def plain_full_field request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.table_name && - %r{^projects/[^/]+/instances/[^/]+/tables/[^/]+/?$}.match?(request.table_name) - header_params["table_name"] = request.table_name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+/tables/[^/]+)/?$}) + header_params = extractor.extract_headers request request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header @@ -404,14 +401,10 @@ def plain_extract request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.table_name - regex_match = %r{^projects/[^/]+/instances/[^/]+/(?tables/[^/]+)/?$}.match request.table_name - if regex_match - header_params["table_name"] = regex_match["table_name".to_s] - end - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "table_name", regex: %r{^projects/[^/]+/instances/[^/]+/(?tables/[^/]+)/?$}) + header_params = extractor.extract_headers request request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header @@ -498,40 +491,16 @@ def complex request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.table_name - regex_match = %r{^(?projects/[^/]+)/instances/[^/]+/tables/[^/]+/?$}.match request.table_name - if regex_match - header_params["project_id"] = regex_match["project_id".to_s] - end - end - if request.table_name - regex_match = %r{^projects/[^/]+/(?instances/[^/]+)/tables/[^/]+/?$}.match request.table_name - if regex_match - header_params["instance_id"] = regex_match["instance_id".to_s] - end - end - if request.table_name - regex_match = %r{^projects/[^/]+/instances/[^/]+/(?tables/[^/]+)/?$}.match request.table_name - if regex_match - header_params["table_id"] = regex_match["table_id".to_s] - end - end - if request.table_name && - %r{^projects/[^/]+/instances/[^/]+/tables/[^/]+/?$}.match?(request.table_name) - header_params["table_name"] = request.table_name - end - if request.table_name && - %r{^projects/[^/]+/instances/[^/]+/tables/[^/]+/aliases(?:/.*)?$}.match?(request.table_name) - header_params["table_name"] = request.table_name - end - if request.app_profile_id && !request.app_profile_id.empty? - header_params["app_profile_id"] = request.app_profile_id - end - if request.app_profile_id && !request.app_profile_id.empty? - header_params["app_profile_id_renamed"] = request.app_profile_id - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "project_id", regex: %r{^(?projects/[^/]+)/instances/[^/]+/tables/[^/]+/?$}) + .with_bindings(field: "table_name", header_name: "instance_id", regex: %r{^projects/[^/]+/(?instances/[^/]+)/tables/[^/]+/?$}) + .with_bindings(field: "table_name", header_name: "table_id", regex: %r{^projects/[^/]+/instances/[^/]+/(?tables/[^/]+)/?$}) + .with_bindings(field: "table_name", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+/tables/[^/]+)/?$}) + .with_bindings(field: "table_name", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+/tables/[^/]+/aliases(?:/.*)?)/?$}) + .with_bindings(field: "app_profile_id", header_name: "app_profile_id") + .with_bindings(field: "app_profile_id", header_name: "app_profile_id_renamed") + header_params = extractor.extract_headers request request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header @@ -618,15 +587,11 @@ def with_sub_message request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource&.resource_name && - %r{^projects/[^/]+/instances/[^/]+/tables/[^/]+/?$}.match?(request.resource.resource_name) - header_params["table_name"] = request.resource.resource_name - end - if request.app_profile_id && !request.app_profile_id.empty? - header_params["app_profile_id"] = request.app_profile_id - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource.resource_name", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+/tables/[^/]+)/?$}) + .with_bindings(field: "app_profile_id", header_name: "app_profile_id") + header_params = extractor.extract_headers request request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header diff --git a/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_explicit_headers/rest/client.rb b/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_explicit_headers/rest/client.rb index fb5d0c4ee..866768065 100644 --- a/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_explicit_headers/rest/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_explicit_headers/rest/client.rb @@ -189,18 +189,25 @@ def plain_no_template request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.plain_no_template.metadata.to_h + metadata = @config.rpcs.plain_no_template.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "table_name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.plain_no_template.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.plain_no_template.retry_policy options.apply_defaults timeout: @config.timeout, @@ -259,18 +266,25 @@ def plain_full_field request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.plain_full_field.metadata.to_h + metadata = @config.rpcs.plain_full_field.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+/tables/[^/]+)/?$}) + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.plain_full_field.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.plain_full_field.retry_policy options.apply_defaults timeout: @config.timeout, @@ -329,18 +343,25 @@ def plain_extract request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.plain_extract.metadata.to_h + metadata = @config.rpcs.plain_extract.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "table_name", regex: %r{^projects/[^/]+/instances/[^/]+/(?tables/[^/]+)/?$}) + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.plain_extract.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.plain_extract.retry_policy options.apply_defaults timeout: @config.timeout, @@ -399,18 +420,31 @@ def complex request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.complex.metadata.to_h + metadata = @config.rpcs.complex.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name", header_name: "project_id", regex: %r{^(?projects/[^/]+)/instances/[^/]+/tables/[^/]+/?$}) + .with_bindings(field: "table_name", header_name: "instance_id", regex: %r{^projects/[^/]+/(?instances/[^/]+)/tables/[^/]+/?$}) + .with_bindings(field: "table_name", header_name: "table_id", regex: %r{^projects/[^/]+/instances/[^/]+/(?tables/[^/]+)/?$}) + .with_bindings(field: "table_name", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+/tables/[^/]+)/?$}) + .with_bindings(field: "table_name", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+/tables/[^/]+/aliases(?:/.*)?)/?$}) + .with_bindings(field: "app_profile_id", header_name: "app_profile_id") + .with_bindings(field: "app_profile_id", header_name: "app_profile_id_renamed") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.complex.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.complex.retry_policy options.apply_defaults timeout: @config.timeout, @@ -469,18 +503,26 @@ def with_sub_message request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.with_sub_message.metadata.to_h + metadata = @config.rpcs.with_sub_message.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource.resource_name", header_name: "table_name", regex: %r{^(?projects/[^/]+/instances/[^/]+/tables/[^/]+)/?$}) + .with_bindings(field: "app_profile_id", header_name: "app_profile_id") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.with_sub_message.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.with_sub_message.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_implicit_headers/client.rb b/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_implicit_headers/client.rb index fea51cd26..b308e2c53 100644 --- a/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_implicit_headers/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_implicit_headers/client.rb @@ -221,12 +221,11 @@ def plain request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.table_name - header_params["table_name"] = request.table_name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.plain.timeout, @@ -312,12 +311,11 @@ def with_sub_message request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource&.resource_name - header_params["resource.resource_name"] = request.resource.resource_name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource.resource_name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.with_sub_message.timeout, @@ -403,12 +401,11 @@ def with_multiple_levels request, options = nil gapic_version: ::Testing::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id - header_params = {} - if request.resource&.inner&.inner_name - header_params["resource.inner.inner_name"] = request.resource.inner.inner_name - end + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource.inner.inner_name") - request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.with_multiple_levels.timeout, diff --git a/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_implicit_headers/rest/client.rb b/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_implicit_headers/rest/client.rb index dc55ce47e..a018b2103 100644 --- a/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_implicit_headers/rest/client.rb +++ b/shared/output/gapic/templates/testing/lib/testing/routing_headers/service_implicit_headers/rest/client.rb @@ -189,18 +189,25 @@ def plain request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.plain.metadata.to_h + metadata = @config.rpcs.plain.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "table_name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.plain.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.plain.retry_policy options.apply_defaults timeout: @config.timeout, @@ -259,18 +266,25 @@ def with_sub_message request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.with_sub_message.metadata.to_h + metadata = @config.rpcs.with_sub_message.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource.resource_name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.with_sub_message.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.with_sub_message.retry_policy options.apply_defaults timeout: @config.timeout, @@ -329,18 +343,25 @@ def with_multiple_levels request, options = nil options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults - call_metadata = @config.rpcs.with_multiple_levels.metadata.to_h + metadata = @config.rpcs.with_multiple_levels.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers - call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Testing::VERSION, transports_version_send: [:rest] - call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + extractor = Gapic::RoutingHeaders::HeadersExtractor.new + .with_bindings(field: "resource.inner.inner_name") + + header_params = extractor.extract_headers request + request_params_header = URI.encode_www_form header_params + metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.with_multiple_levels.timeout, - metadata: call_metadata, + metadata: metadata, retry_policy: @config.rpcs.with_multiple_levels.retry_policy options.apply_defaults timeout: @config.timeout, diff --git a/shared/test_resources/showcase/Gemfile b/shared/test_resources/showcase/Gemfile new file mode 100644 index 000000000..28f4d681c --- /dev/null +++ b/shared/test_resources/showcase/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "gapic-common", path: "/home/virost/src/gapic-generator-ruby/gapic-common" + +gemspec diff --git a/shared/test_resources/showcase/test/echo_headers.rb b/shared/test_resources/showcase/test/echo_headers.rb new file mode 100644 index 000000000..4809f8395 --- /dev/null +++ b/shared/test_resources/showcase/test/echo_headers.rb @@ -0,0 +1,191 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "helper" +require "gapic/rest" +require "google/showcase/v1beta1/echo" +require "google/showcase/v1beta1/echo/rest" + + +class ::Google::Showcase::V1beta1::Echo::HeadersTest < Minitest::Test + def setup client=nil + @client = client + end + + # Currently cannot be done from the standard test battery in routing.proto: + # - test_nested_field (no nested field in EchoRequest) + # - test_overlapping_patterns -- no conflicting overlapping patterns + # - test_multiple_keyvaluepairs_strict -- requires a very specific pattern setup + # - test_multiple_conflicts_and_request_fields -- no conflicts + # - test_complex_scenario -- no conflicts + + # Extracting a field from the request to put into the routing header + # unchanged, with the key equal to the field name. + # Extracting a field from the request to put into the routing header + # unchanged, with the key different from the field name. + # + # This tests: + # - test_simple_extraction + # - test_rename_extraction + def test_simple_and_rename_extraction + test_cases = [ + { + header_field: "foo.123", + expected: ["header=foo.123", "routing_id=foo.123"] + }, + { + header_field: "projects/100", + expected: "super_id=projects/100" + }, + ] + + assert_matches @client, test_cases + end + + # Extracting a field from the request to put into the routing + # header, while matching a path template syntax on the field's value. + # Extracting a single routing header key-value pair by matching a + # template syntax on (a part of) a single request field. + # + # This tests: + # - test_field_match + # - test_simple_extract + # - test_multiple_keyvaluepairs_loose + def test_field_match_simple_extract_multiple_kvp + test_cases = [ + { + header_field: "projects/100/instances/200", + expected: ["super_id=projects/100", "table_name=projects/100/instances/200", "instance_id=instances/200"] + }, + { + header_field: "regions/100/zones/200", + expected: ["table_name=regions/100/zones/200",] + }, + { + header_field: "projects/100/instances/200/whatever", + expected: ["super_id=projects/100", "table_name=projects/100/instances/200/whatever", "instance_id=instances/200"] + }, + ] + + assert_matches @client, test_cases + end + + # Extracting multiple routing header key-value pairs by matching + # several path templates on multiple request fields. + # + # This tests: + # - test_multiple_request_fields + # - test_complex_scenario (only partially since no conflicts) + def test_multiple_request_fields_conflicts + test_cases = [ + { + header_field: "projects/100", + other_header_field: "projects/100/misc", + expected: ["super_id=projects/100", "qux=projects/100", "baz=projects/100/misc"] + }, + { + header_field: "projects/100", + other_header_field: "foo.123", + expected: ["super_id=projects/100", "baz=foo.123"] + }, + ] + + assert_matches @client, test_cases + end + + def assert_matches client, test_cases + return unless client + test_cases.each do |test_case| + request = { content: "foo", header: test_case[:header_field] } + request[:other_header] = test_case[:other_header_field] if test_case.key? :other_header_field + @client.echo request do |response, operation| + routing_keyvals = extract_routing_keyvals operation + + expected = test_case[:expected] + expected = [expected] unless expected.is_a? ::Array + + refute_nil routing_keyvals + routing_keys = routing_keyvals.split("&").map { |kvp| kvp.split("=")[0]} + expected_keys = expected.map {|kvp| kvp.split("=")[0]} + + expected_keys.append("header") unless expected_keys.include? "header" + expected_keys.append("routing_id") unless expected_keys.include? "routing_id" + + err_str = "Test case keys mismatch:\nRequest: \n#{request.pretty_inspect}\nExpected: \n#{expected.pretty_inspect}" \ + "\nHeaders formed: \n #{routing_keys}" + + assert_equal expected_keys.sort, routing_keys.sort, err_str + + expected.each do |expected_elem| + expected_elem_encoded = URI.encode_www_form([expected_elem.split("=")]) + + err_str = "Test case:\nRequest: \n#{request.pretty_inspect}\nExpected: \n#{expected_elem.pretty_inspect}" \ + "\nEncoded: #{expected_elem_encoded}" + + err_str = "#{err_str}\nRouting header formed: \n #{routing_keys}" + + assert_match expected_elem_encoded, routing_keyvals, err_str + end + end + end + end + + def extract_routing_keyvals operation + end +end + +class ::Google::Showcase::V1beta1::Echo::GrpcHeadersTest < ::Google::Showcase::V1beta1::Echo::HeadersTest + def setup + client = Google::Showcase::V1beta1::Echo::Client.new do |config| + config.credentials = GRPC::Core::Channel.new "localhost:7469", nil, :this_channel_is_insecure + end + + super client + end + + def extract_routing_keyvals operation + assert_kind_of ::Hash, operation.metadata + assert operation.metadata.key? "x-goog-request-params" + operation.metadata["x-goog-request-params"] + end +end + +class ::Google::Showcase::V1beta1::Echo::RestHeadersTest < ::Google::Showcase::V1beta1::Echo::HeadersTest + def setup + client = Google::Showcase::V1beta1::Echo::Rest::Client.new do |config| + config.endpoint = "http://localhost:7469" + config.credentials = :this_channel_is_insecure + end + + super client + end + + def extract_routing_keyvals response + assert_kind_of ::Hash, response.env.request_headers + assert response.env.request_headers.key? "X-goog-request-params" + response.env.request_headers["x-goog-request-params"] + end +end