Amazon-Signature4-Lite
view release on metacpan or search on metacpan
lib/Amazon/Signature4/Lite.pm view on Meta::CPAN
my $signer = Amazon::Signature4::Lite->new(
access_key => $access_key_id,
secret_key => $secret_access_key,
session_token => $session_token, # optional, for STS/IAM roles
region => 'us-east-1',
service => 's3', # default
);
my $signed = $signer->sign(
method => 'PUT',
url => 'https://s3.amazonaws.com/my-bucket/my-key',
headers => { 'Content-Type' => 'application/gzip' },
payload => $content,
);
# $signed is a hashref of headers ready for HTTP::Tiny:
# Authorization, x-amz-date, x-amz-content-sha256,
# x-amz-security-token (if session_token provided), host
=head1 DESCRIPTION
share/README.md view on Meta::CPAN
my $signer = Amazon::Signature4::Lite->new(
access_key => $access_key_id,
secret_key => $secret_access_key,
session_token => $session_token, # optional, for STS/IAM roles
region => 'us-east-1',
service => 's3', # default
);
my $signed = $signer->sign(
method => 'PUT',
url => 'https://s3.amazonaws.com/my-bucket/my-key',
headers => { 'Content-Type' => 'application/gzip' },
payload => $content,
);
# $signed is a hashref of headers ready for HTTP::Tiny:
# Authorization, x-amz-date, x-amz-content-sha256,
# x-amz-security-token (if session_token provided), host
# DESCRIPTION
t/01-signature4-lite.t view on Meta::CPAN
########################################################################
# payload hashing
########################################################################
subtest 'payload hashing' => sub {
my $signer = new_signer();
# scalar payload
my $signed = $signer->sign(
method => 'PUT',
url => 'https://s3.amazonaws.com/bucket/key',
payload => 'hello world',
time => $TEST_TIME,
);
is $signed->{'x-amz-content-sha256'},
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9',
'payload hash for "hello world"';
# scalar ref payload
my $data = 'hello world';
my $signed2 = $signer->sign(
method => 'PUT',
url => 'https://s3.amazonaws.com/bucket/key',
payload => \$data,
time => $TEST_TIME,
);
is $signed2->{'x-amz-content-sha256'}, $signed->{'x-amz-content-sha256'}, 'scalar ref produces same hash as scalar';
};
########################################################################
# _encode_path
########################################################################
t/01-signature4-lite.t view on Meta::CPAN
};
########################################################################
# header passthrough
########################################################################
subtest 'extra headers included in signing' => sub {
my $signer = new_signer();
my $signed = $signer->sign(
method => 'PUT',
url => 'https://s3.amazonaws.com/bucket/key',
headers => {
'Content-Type' => 'application/gzip',
'x-amz-acl' => 'private',
},
time => $TEST_TIME,
);
is $signed->{'Content-Type'}, 'application/gzip', 'Content-Type passed through';
is $signed->{'x-amz-acl'}, 'private', 'x-amz-acl passed through';
( run in 1.327 second using v1.01-cache-2.11-cpan-13bb782fe5a )