From 568c625b815dfa9ed5ecff81fc3ca00a819e3e38 Mon Sep 17 00:00:00 2001 From: Marc Egea i Sala Date: Wed, 20 Jun 2018 16:21:32 +0200 Subject: [PATCH 1/2] Ignore provided 'region' if 'credentialScope' is defined If we end in a rule with 'credentialScope', we probably want to ignore the 'region' even if the user has defined one. Request to rules with 'credentialScope' are only going to succeed with the region in it, so if the user (mistakenly or not) has a 'region' defined the request will fail. It may be nice, though, to leave a WARNING if 'region' is defined and is different from the one in 'credentialScope'. --- lib/Paws/API/EndpointResolver.pm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Paws/API/EndpointResolver.pm b/lib/Paws/API/EndpointResolver.pm index d11f51cfca..97dcdf8bf3 100644 --- a/lib/Paws/API/EndpointResolver.pm +++ b/lib/Paws/API/EndpointResolver.pm @@ -23,12 +23,11 @@ package Paws::API::EndpointResolver; default => sub { my $self = shift; my $sig_region; - - # For global services: don't specify region: we sign with the region in the credentialScope - # specify the region: we override the credentialScope (use the region specified) + + # For global services: we sign with the region in the credentialScope # For regional services: use the region specified for signing - # If endpoint is specified: use the region specified (no _endpoint_info) - if (defined $self->_endpoint_info->{ credentialScope } and not defined $self->region) { + # If endpoint is specified: use the region specified (no _endpoint_info) + if (defined $self->_endpoint_info->{ credentialScope }) { $sig_region = $self->_endpoint_info->{ credentialScope }->{ region } } $sig_region = $self->region if (not defined $sig_region); From cefcfa56ec491d20122e11eb85470990acf9179f Mon Sep 17 00:00:00 2001 From: Marc Egea i Sala Date: Thu, 21 Jun 2018 19:27:36 +0200 Subject: [PATCH 2/2] Add support for for endpoint overriding --- lib/Paws/API/EndpointResolver.pm | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/Paws/API/EndpointResolver.pm b/lib/Paws/API/EndpointResolver.pm index 97dcdf8bf3..d898e5409f 100644 --- a/lib/Paws/API/EndpointResolver.pm +++ b/lib/Paws/API/EndpointResolver.pm @@ -15,6 +15,12 @@ package Paws::API::EndpointResolver; builder => '_construct_endpoint', ); + has _endpoint_has_been_constructed => ( + is => 'rw', + init_arg => undef, + default => 0, + ); + has _region_for_signature => ( is => 'rw', isa => 'Str', @@ -24,13 +30,18 @@ package Paws::API::EndpointResolver; my $self = shift; my $sig_region; - # For global services: we sign with the region in the credentialScope + # If endpoint is specified: use the region specified + if ($self->region and not $self->_endpoint_has_been_constructed) { + $sig_region = $self->region; + } + # For global services: we sign with the region in the credentialScope + elsif (defined $self->_endpoint_info->{ credentialScope }) { + $sig_region = $self->_endpoint_info->{ credentialScope }->{ region }; + } # For regional services: use the region specified for signing - # If endpoint is specified: use the region specified (no _endpoint_info) - if (defined $self->_endpoint_info->{ credentialScope }) { - $sig_region = $self->_endpoint_info->{ credentialScope }->{ region } + else { + $sig_region = $self->region; } - $sig_region = $self->region if (not defined $sig_region); Paws::Exception->throw( message => "Can't find a region for signing. region is required", @@ -96,6 +107,8 @@ package Paws::API::EndpointResolver; sub _construct_endpoint { my ($self) = @_; + $self->_endpoint_has_been_constructed(1); + my $args = {}; $args->{ service } = $self->service; $args->{ region } = $self->region;