view release on metacpan or search on metacpan
README.markdown view on Meta::CPAN
Required. String.
Provided by Amazon, this is your secret access key.
## secure
Optional. Boolean.
Default is `0`
## endpoint
Optional. String.
Default is `s3.amazonaws.com`
## ua
Optional. Should be an instance of [LWP::UserAgent](https://metacpan.org/pod/LWP%3A%3AUserAgent) or a subclass of it.
Defaults to creating a new instance of [LWP::UserAgent::Determined](https://metacpan.org/pod/LWP%3A%3AUserAgent%3A%3ADetermined)
README.markdown view on Meta::CPAN
String. Read-only
## secret\_access\_key
String. Read-only.
## secure
Boolean. Read-only.
## endpoint
String. Read-only.
## ua
[LWP::UserAgent](https://metacpan.org/pod/LWP%3A%3AUserAgent) object. Read-only.
## owner
[AWS::S3::Owner](https://metacpan.org/pod/AWS%3A%3AS3%3A%3AOwner) object. Read-only.
lib/AWS/S3.pm view on Meta::CPAN
default => sub { $ENV{AWS_REGION} },
);
has 'secure' => (
is => 'ro',
isa => 'Bool',
lazy => 1,
default => 0
);
has 'endpoint' => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub {
my ( $s ) = @_;
if ( my $region = $s->region ) {
return "s3.$region.amazonaws.com"
} else {
return "s3.amazonaws.com"
lib/AWS/S3.pm view on Meta::CPAN
Required. String.
Provided by Amazon, this is your secret access key.
=head2 secure
Optional. Boolean.
Default is C<0>
=head2 endpoint
Optional. String.
Default is C<s3.amazonaws.com>
=head2 ua
Optional. Should be an instance of L<LWP::UserAgent> or a subclass of it.
Defaults to creating a new instance of L<LWP::UserAgent::Determined>
lib/AWS/S3.pm view on Meta::CPAN
String. Read-only
=head2 secret_access_key
String. Read-only.
=head2 secure
Boolean. Read-only.
=head2 endpoint
String. Read-only.
=head2 ua
L<LWP::UserAgent> object. Read-only.
=head2 owner
L<AWS::S3::Owner> object. Read-only.
lib/AWS/S3/Request/CreateBucket.pm view on Meta::CPAN
$xml = <<"XML";
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<LocationConstraint>@{[ $s->location ]}</LocationConstraint>
</CreateBucketConfiguration>
XML
}
my $signer = AWS::S3::Signer->new(
s3 => $s->s3,
method => 'PUT',
uri => $s->protocol . '://' . $s->bucket . '.' . $s->endpoint . '/',
content_type => 'text/plain',
content_md5 => '',
content => \$xml,
);
return $s->_send_request(
$signer->method => $signer->uri => {
Authorization => $signer->auth_header,
Date => $signer->date,
'content-type' => 'text/plain',
lib/AWS/S3/Request/SetBucketAccessControl.pm view on Meta::CPAN
has '+_expect_nothing' => ( default => 1 );
sub request {
my $s = shift;
if ( $s->acl_short ) {
my $signer = AWS::S3::Signer->new(
s3 => $s->s3,
method => 'PUT',
uri => $s->protocol . '://' . $s->bucket . '.' . $s->endpoint . '/?acl',
headers => [ 'x-amz-acl' => $s->acl_short ]
);
return $s->_send_request(
$signer->method => $signer->uri => {
Authorization => $signer->auth_header,
Date => $signer->date,
'x-amz-acl' => $s->acl_short
},
$s->acl_xml
);
} elsif ( $s->acl_xml ) {
my $signer = AWS::S3::Signer->new(
s3 => $s->s3,
method => 'PUT',
uri => $s->protocol . '://' . $s->bucket . '.' . $s->endpoint . '/?acl',
content => \$s->acl_xml,
'content-type' => 'text/xml',
);
return $s->_send_request(
$signer->method => $signer->uri => {
Authorization => $signer->auth_header,
Date => $signer->date,
},
$s->acl_xml
);
lib/AWS/S3/Request/SetFileContents.pm view on Meta::CPAN
} elsif ( ref( $s->file->contents ) eq 'SCALAR' ) {
$contents = $s->file->contents;
} # end if()
my %other_args = ();
$other_args{'x-amz-server-side-encryption'} = 'AES256' if $s->file->is_encrypted;
my $signer = AWS::S3::Signer->new(
s3 => $s->s3,
method => 'PUT',
uri => $s->protocol . '://' . $s->bucket . '.' . $s->endpoint . '/' . $s->file->key,
content_type => $s->content_type,
content => $contents,
headers => [ 'x-amz-storage-class', $s->file->storage_class ],
);
$s->_send_request(
$signer->method => $signer->uri => {
Authorization => $signer->auth_header,
Date => $signer->date,
'content-type' => $s->content_type,
'content-md5' => $signer->content_md5,
lib/AWS/S3/Roles/Bucket.pm view on Meta::CPAN
package AWS::S3::Roles::Bucket;
use Moose::Role;
sub bucket_uri {
my ( $s,$path ) = @_;
$path //= $s->bucket;
my $protocol = $s->s3->secure ? 'https' : 'http';
my $endpoint = $s->s3->endpoint;
my $uri = "$protocol://$endpoint/$path";
if ( $path =~ m{^([^/?]+)(.*)} && $s->is_dns_bucket( $1 ) ) {
$uri = "$protocol://$1.$endpoint$2";
} # end if()
return $uri;
}
sub is_dns_bucket {
my ( $s,$bucket ) = @_;
# https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
return 0 if ( length( $bucket ) < 3 or length( $bucket ) > 63 );
lib/AWS/S3/Roles/Request.pm view on Meta::CPAN
has 'protocol' => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub {
shift->s3->secure ? 'https' : 'http';
}
);
has 'endpoint' => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub {
shift->s3->endpoint;
}
);
# XXX should be required=>1; https://rt.cpan.org/Ticket/Display.html?id=77863
has "_action" => (
isa => 'Str',
is => 'ro',
init_arg => undef,
#required => 1
);
lib/AWS/S3/Roles/Request.pm view on Meta::CPAN
isa => Uri,
is => 'ro',
lazy => 1,
default => sub {
my $self = shift;
my $m = $self->meta;
my $uri = URI->new(
$self->protocol . '://'
. ( $m->has_attribute('bucket') ? $self->bucket . '.' : '' )
. $self->endpoint
. '/'
);
# note we add some extra exceptions to uri_escape to prevent
# encoding of things like "/", ":", "="
if ( $m->has_attribute('key') ) {
my $escaped_path = uri_escape( $self->key,"^A-Za-z0-9\-\._~\/:=" );
# if we have a leading slash in the key name we need to add *another*
# slash in the call to ->path to ensure it is retained
lib/AWS/S3/Signer.pm view on Meta::CPAN
required => 1,
);
has 'bucket_name' => (
is => 'ro',
isa => 'Str',
required => 1,
lazy => 1,
default => sub {
my $s = shift;
my $endpoint = $s->s3->endpoint;
if ( my ( $name ) = $s->uri->host =~ m{^(.+?)\.\Q$endpoint\E} ) {
return $name;
} else {
return '';
} # end if()
}
);
has 'uri' => (
is => 'ro',
isa => Uri,
lib/AWS/S3/Signer/V4.pm view on Meta::CPAN
If a security token is provided, it overrides any values given for
-access_key or -secret_key.
If the environment variables EC2_ACCESS_KEY and/or EC2_SECRET_KEY are
set, their contents are used as defaults for -access_key and
-secret_key.
If -service and/or -region is not provided, they are automtically determined
according to endpoint.
=cut
sub new {
my $self = shift;
my %args = @_;
my ( $id, $secret, $token, $region, $service );
if ( ref $args{-security_token}
&& $args{-security_token}->can('access_key_id') )
lib/AWS/S3/Signer/V4.pm view on Meta::CPAN
sub access_key { shift->{access_key} }
sub secret_key { shift->{secret_key} }
=item $signer->sign($request [,$region] [,$payload_sha256_hex])
Given an HTTP::Request object, add the headers required by AWS and
then sign it with a version 4 signature by adding an "Authorization"
header.
The request must include a URL from which the AWS endpoint and service
can be derived, such as "ec2.us-east-1.amazonaws.com." In some cases
(e.g. S3 bucket operations) the endpoint does not indicate the
region. In this case, the region can be forced by passing a defined
value for $region. The current date and time will be added to the
request using an "X-Amz-Date header." To force the date and time to a
fixed value, include the "Date" header in the request.
The request content, or "payload" is retrieved from the HTTP::Request
object by calling its content() method.. Under some circumstances the
payload is not included directly in the request, but is in an external
file that will be uploaded as the request is executed. In this case,
you must pass a second argument containing the results of running
lib/AWS/S3/Signer/V4.pm view on Meta::CPAN
sub sign {
my $self = shift;
my ( $request, $region, $payload_sha256_hex ) = @_;
$self->_add_date_header($request);
$self->_sign( $request, $region, $payload_sha256_hex );
}
=item my $url $signer->signed_url($request_or_uri [,$expires] [,$verb])
Pass an HTTP::Request, a URI object, or just a plain URL string
containing the proper endpoint and parameters needed for an AWS REST
API Call. This method will return an appropriately signed request as a
URI object, which can be shared with non-AWS users for the purpose of,
e.g., accessing an object in a private S3 bucket.
Pass an optional $expires argument to indicate that the URL will only
be valid for a finite period of time. The value of the argument is in
seconds.
Pass an optional verb which is useful for HEAD requests, this defaults to GET.
use Data::Section::Simple 'get_data_section';
use Carp 'confess';
$SIG{__DIE__} = \&confess;
use_ok('AWS::S3');
my $s3 = AWS::S3->new(
access_key_id => $ENV{AWS_ACCESS_KEY_ID} // 'foo',
secret_access_key => $ENV{AWS_SECRET_ACCESS_KEY} // 'bar',
endpoint => 'bad.hostname.',
);
my $bucket_name = "aws-s3-test-" . int(rand() * 1_000_000) . '-' . time() . "-foo";
eval {
my $bucket = $s3->add_bucket( name => $bucket_name, location => 'us-west-1' );
};
like(
$@,
qr/Can't connect to aws-s3-test-.*?bad\.hostname/,
'endpoint was used'
);
isa_ok(
$s3->request( 'CreateBucket',bucket => 'foo' ),
'AWS::S3::Request::CreateBucket'
);
subtest 'create bucket strange temporary redirect' => sub {
plan tests => 8; # make sure all tests in here get run
t/aws/s3/bucket.t view on Meta::CPAN
use Carp 'confess';
$SIG{__DIE__} = \&confess;
use_ok('AWS::S3');
note( "construction" );
my $s3 = AWS::S3->new(
access_key_id => $ENV{AWS_ACCESS_KEY_ID} // 'foo',
secret_access_key => $ENV{AWS_SECRET_ACCESS_KEY} // 'bar',
endpoint => $ENV{AWS_ENDPOINT} // 's3.baz.com',
);
use_ok('AWS::S3::Bucket');
isa_ok(
my $bucket = AWS::S3::Bucket->new(
s3 => $s3,
name => $ENV{AWS_TEST_BUCKET} // 'maibucket',
),
'AWS::S3::Bucket'
t/aws/s3/file.t view on Meta::CPAN
$SIG{__DIE__} = \&confess;
use_ok('AWS::S3');
note( "construction" );
foreach my $leading_slashes ( 0,1 ) {
my $s3 = AWS::S3->new(
access_key_id => $ENV{AWS_ACCESS_KEY_ID} // 'foo',
secret_access_key => $ENV{AWS_SECRET_ACCESS_KEY} // 'bar',
endpoint => $ENV{AWS_ENDPOINT} // 's3.baz.com',
honor_leading_slashes => $leading_slashes,
);
use_ok('AWS::S3::File');
use_ok('AWS::S3::Bucket');
use_ok('AWS::S3::Request::SetFileContents');
monkey_patch_module();
my $path = '/path/to/';
t/aws/s3/file_iterator.t view on Meta::CPAN
use Carp 'confess';
$SIG{__DIE__} = \&confess;
use_ok('AWS::S3');
use_ok('AWS::S3::FileIterator');
use_ok('AWS::S3::Bucket');
my $s3 = AWS::S3->new(
access_key_id => $ENV{AWS_ACCESS_KEY_ID} // 'foo',
secret_access_key => $ENV{AWS_SECRET_ACCESS_KEY} // 'bar',
endpoint => $ENV{AWS_ENDPOINT} // 's3.baz.com',
);
isa_ok(
my $bucket = AWS::S3::Bucket->new(
s3 => $s3,
name => $ENV{AWS_TEST_BUCKET} // 'maibucket',
),
'AWS::S3::Bucket'
);
t/aws/s3/http_request.t view on Meta::CPAN
use Carp 'confess';
$SIG{__DIE__} = \&confess;
use_ok('AWS::S3');
note( "construction" );
my $s3 = AWS::S3->new(
access_key_id => $ENV{AWS_ACCESS_KEY_ID} // 'foo',
secret_access_key => $ENV{AWS_SECRET_ACCESS_KEY} // 'bar',
endpoint => $ENV{AWS_ENDPOINT} // 's3.baz.com',
);
use_ok('AWS::S3::HTTPRequest');
isa_ok(
my $request = AWS::S3::HTTPRequest->new(
s3 => $s3,
method => 'POST',
path => '/foo/bar',
),
t/aws/s3/signer.t view on Meta::CPAN
use Carp 'confess';
$SIG{__DIE__} = \&confess;
use_ok('AWS::S3');
note( "construction" );
my $s3 = AWS::S3->new(
access_key_id => $ENV{AWS_ACCESS_KEY_ID} // 'foo',
secret_access_key => $ENV{AWS_SECRET_ACCESS_KEY} // 'bar',
endpoint => $ENV{AWS_ENDPOINT} // 's3.baz.com',
);
use_ok('AWS::S3::Signer');
isa_ok(
my $signer = AWS::S3::Signer->new(
method => 'HEAD',
s3 => $s3,
uri => "http://maibucket.s3.baz.com/boz",
content => \'hello world',