diff --git a/lib/Signer/AWSv4/S3.pm b/lib/Signer/AWSv4/S3.pm index 374d4ab..2c399ed 100644 --- a/lib/Signer/AWSv4/S3.pm +++ b/lib/Signer/AWSv4/S3.pm @@ -18,7 +18,7 @@ package Signer::AWSv4::S3; sprintf "/%s/%s", $self->bucket, $self->key; }); - has bucket_host => (is => 'ro', isa => Str, init_arg => undef, lazy => 1, default => sub { + has bucket_host => (is => 'ro', isa => Str, lazy => 1, default => sub { my $self = shift; if ($self->region =~m/us-east-1/i) { return 's3.amazonaws.com'; @@ -77,6 +77,7 @@ Signer::AWSv4::S3 - Implements the AWS v4 signature algorithm key => 'test.txt', bucket => 'examplebucket', region => 'us-east-1', + bucket_host => 'custom-s3-compatible-endpoint.lan', expires => 86400, version_id => '1234561zOnAAAJKHxVKBxxEyuy_78901j', content_type => 'text/plain', @@ -105,6 +106,12 @@ The name of the S3 bucket VersionId used to reference a specific version of the object. +=head1 Optional Attributes + +=head2 bucket_host + +Custom S3 endpoint hostname. By default, an AWS hostname will be used. + =head1 Overriding Response Header Values There are times when you want to override certain response header values in a GET response. diff --git a/t/02_s3.t b/t/02_s3.t index 253cc6c..8ac1fbc 100644 --- a/t/02_s3.t +++ b/t/02_s3.t @@ -73,4 +73,32 @@ $signer = Signer::AWSv4::S3->new( $expected_signed_qstring = 'X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIOSFODNN7EXAMPLE%2F20130524%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20130524T000000Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&response-content-disposition=inline%3B%20filename%3DNew%20Name.txt&response-content-type=text%2Fplain&versionId=1234561zOnAAAJKHxVKBxxEyuy_78901j&X-Amz-Signature=d2f2d969d49edb97b90bf67c652b87eee2449750dd2f14c2e1cbe994f1f5e813'; cmp_ok($signer->signed_qstring, 'eq', $expected_signed_qstring); +$signer = Signer::AWSv4::S3->new( + time => Time::Piece->strptime('20130524T000000Z', '%Y%m%dT%H%M%SZ'), + access_key => 'AKIAIOSFODNN7EXAMPLE', + secret_key => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', + method => 'GET', + key => 'test.txt', + bucket => 'examplebucket', + region => 'us-east-1', + bucket_host => 'minio.dev.lan', + expires => 86400, + version_id => '1234561zOnAAAJKHxVKBxxEyuy_78901j', + content_type => 'text/plain', + content_disposition => 'inline; filename=New Name.txt', +); + +my $expected_url = 'https://minio.dev.lan/examplebucket/test.txt' + . '?X-Amz-Algorithm=AWS4-HMAC-SHA256' + . '&X-Amz-Credential=AKIAIOSFODNN7EXAMPLE%2F20130524%2Fus-east-1%2Fs3%2Faws4_request' + . '&X-Amz-Date=20130524T000000Z' + . '&X-Amz-Expires=86400' + . '&X-Amz-SignedHeaders=host' + . '&response-content-disposition=inline%3B%20filename%3DNew%20Name.txt' + . '&response-content-type=text%2Fplain' + . '&versionId=1234561zOnAAAJKHxVKBxxEyuy_78901j' + . '&X-Amz-Signature=c1936b2b58e1a0dc14eaae9901617c54bc2e5645b729ab9b34bd5b5d8f4d2d91'; + +cmp_ok($signer->signed_url, 'eq', $expected_url, 'expected url is generated for non-AWS S3 bucket host'); + done_testing;