Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Ignore provided 'region' if 'credentialScope' is defined #258

Open
wants to merge 2 commits into
base: release/0.39
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions lib/Paws/API/EndpointResolver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -23,15 +29,19 @@ 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)

# 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 } and not defined $self->region) {
$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",
Expand Down Expand Up @@ -97,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;
Expand Down