From 0cdb3ddd2c6dc60b1410593e3cf3ba87704fb0b1 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 6 Sep 2024 12:04:07 -0400 Subject: [PATCH] Move sigv4a metric to endpoints plugin --- .../templates/endpoints_plugin.mustache | 16 +++++++++++++--- .../lib/aws-sdk-core/plugins/sign.rb | 8 +------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache index 4ef6e5bf274..6cd71aa0281 100644 --- a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache +++ b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache @@ -44,17 +44,27 @@ module {{module_name}} context[:auth_scheme] = Aws::Endpoints.resolve_auth_scheme(context, endpoint) - with_metric(context[:endpoint_params]) { @handler.call(context) } + with_endpoint_metric(context[:endpoint_params]) do + with_sigv4a_metric(context[:auth_scheme]) do + @handler.call(context) + end + end end private - def with_metric(params, &block) - return block.call unless params && params[:endpoint] + def with_endpoint_metric(endpoint_params, &block) + return block.call unless endpoint_params && endpoint_params[:endpoint] Aws::Plugins::UserAgent.metric('ENDPOINT_OVERRIDE', &block) end + def with_sigv4a_metric(auth_scheme, &block) + return block.call unless auth_scheme && auth_scheme['name'] == 'sigv4a' + + Aws::Plugins::UserAgent.metric('SIGV4A_SIGNING', &block) + end + def apply_endpoint_headers(context, headers) headers.each do |key, values| value = values diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb index 3c5755a5d60..5a447707222 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb @@ -50,17 +50,11 @@ def call(context) ) signer.sign(context) end - with_metric(context[:auth_scheme]) { @handler.call(context) } + @handler.call(context) end private - def with_metric(auth_scheme, &block) - return block.call unless auth_scheme && auth_scheme['name'] == 'sigv4a' - - Aws::Plugins::UserAgent.metric('SIGV4A_SIGNING', &block) - end - def v2_signing?(config) # 's3' is legacy signing, 'v4' is default config.respond_to?(:signature_version) &&