Amazon-S3
view release on metacpan or search on metacpan
lib/Amazon/S3.pm view on Meta::CPAN
);
$ua->timing( join $COMMA, map { 2**$_ } 0 .. $MAX_RETRIES );
}
else {
$ua = LWP::UserAgent->new(
keep_alive => $KEEP_ALIVE_CACHESIZE,
requests_redirectable => [qw(GET HEAD DELETE)],
);
}
$ua->timeout( $self->timeout );
$ua->env_proxy;
$self->ua($ua);
$self->region( $self->_region // $DEFAULT_REGION );
if ( !$self->_signer && $self->cache_signer ) {
$self->_signer( $self->signer );
}
if ( $self->express ) {
$self->use_express_one_zone();
}
$self->turn_on_special_retry();
return $self;
}
########################################################################
sub use_express_one_zone {
########################################################################
my ($self) = @_;
my $express = $self->express;
$self->express($TRUE);
$self->host( sprintf 's3express-control.%s.amazonaws.com', $self->region );
$self->dns_bucket_names($FALSE);
return $express;
}
########################################################################
{
my $encryption_key;
########################################################################
sub _encrypt {
########################################################################
my ($text) = @_;
return $text if !$text;
if ( !defined $encryption_key ) {
$encryption_key = eval {
if ( !defined $encryption_key ) {
require Crypt::Blowfish;
require Crypt::CBC;
return md5_hex( rand $PID );
}
};
return $text if $EVAL_ERROR;
}
return $text if !$encryption_key;
my $cipher = Crypt::CBC->new(
-pass => $encryption_key,
-key => $encryption_key,
-cipher => 'Crypt::Blowfish',
-nodeprecate => $TRUE,
);
return $cipher->encrypt($text);
}
########################################################################
sub _decrypt {
########################################################################
my ($secret) = @_;
return $secret
if !$secret || !$encryption_key;
my $cipher = Crypt::CBC->new(
-pass => $encryption_key,
-key => $encryption_key,
-cipher => 'Crypt::Blowfish',
);
return $cipher->decrypt($secret);
}
}
########################################################################
sub get_bucket_location {
########################################################################
my ( $self, $bucket ) = @_;
my $region;
if ( !ref $bucket || ref $bucket !~ /Amazon::S3::Bucket/xsm ) {
$bucket = Amazon::S3::Bucket->new( bucket => $bucket, account => $self );
}
return $bucket->get_location_constraint // $DEFAULT_REGION;
}
########################################################################
sub get_default_region {
########################################################################
my ($self) = @_;
my $region = $ENV{AWS_REGION} || $ENV{AWS_DEFAULT_REGION};
return $region
if $region;
my $url = $AWS_METADATA_BASE_URL . 'placement/availability-zone';
my $request = HTTP::Request->new( 'GET', $url );
my $ua = LWP::UserAgent->new;
$ua->timeout(0);
my $response = eval { return $ua->request($request); };
if ( $response && $response->is_success ) {
if ( $response->content =~ /\A([[:lower:]]+[-][[:lower:]]+[-]\d+)/xsm ) {
$region = $1;
}
}
return $region || $DEFAULT_REGION;
}
# Amazon::Credentials compatibility methods
########################################################################
sub get_aws_access_key_id {
########################################################################
my ($self) = @_;
return _decrypt( $self->aws_access_key_id );
}
lib/Amazon/S3.pm view on Meta::CPAN
DNS bucket naming conventions or you preface the bucket name with '/'
or explicitly turn off domain buckets by setting C<dns_bucket_names>
to false.
If you set a region then the host name will be modified accordingly if
it is an Amazon endpoint.
=item region
The AWS region you where your bucket is located.
default: us-east-1
=item buffer_size
The default buffer size when reading or writing files.
default: 4096
=back
=head2 signer
Sets or retrieves the signer object. API calls must be signed using
your AWS credentials. By default, starting with version 0.54 the
module will use L<Net::Amazon::Signature::V4> as the signer and
instantiate a signer object in the constructor. Note however, that
signers need your credentials and they I<will> get stored by that
class, making them susceptible to inadvertant exfiltration. You have a
few options here:
=over 5
=item 1. Use your own signer.
You may have noticed that you can also provide your own credentials
object forcing this module to use your object for retrieving
credentials. Likewise, you can use your own signer so that this
module's signer never sees or stores those credentials.
=item 2. Pass the credentials object and set C<cache_signer> to a
false value.
If you pass a credentials object and set C<cache_signer> to a false
value, the module will use the credentials object to retrieve
credentials and create a new signer each time an API call is made that
requires signing. This prevents your credentials from being stored
inside of the signer class.
I<Note that using your own credentials object that stores your
credentials in plaintext is also going to expose your credentials when
someone dumps the class.>
=item 3. Pass credentials, set C<cache_signer> to a false value.
Unfortunately, while this will prevent L<Net::Amazon::Signature::V4>
from hanging on to your credentials, you credentials will be stored in
the C<Amazon::S3> object.
Starting with version 0.55 of this module, if you have installed
L<Crypt::CBC> and L<Crypt::Blowfish>, your credentials will be
encrypted using a random key created when the class is
instantiated. While this is more secure than leaving them in
plaintext, if the key is discovered (the key however is not stored in
the object's hash) and the object is dumped, your I<encrypted>
credentials can be exposed.
=item 4. Use very granular credentials for bucket access only.
Use credentials that only allow access to a bucket or portions of a
bucket required for your application. This will at least limit the
I<blast radius> of any potential security breach.
=item 5. Do nothing...send the credentials, use the default signer.
In this case, both the C<Amazon::S3> class and the
L<Net::Amazon::Signature::V4> have your credentials. Caveat Emptor.
See also L<Amazon::Credentials> for more information about safely
storing your credentials and preventing exfiltration.
=back
=head2 region
Sets the region for the API calls. This will also be the
default when instantiating the bucket object unless you pass the
region parameter in the C<bucket> method or use the C<verify_region>
flag that will I<always> verify the region of the bucket using the
C<get_location_constraint> method.
default: us-east-1
=head2 buckets
buckets([verify-region])
=over
=item verify-region (optional)
C<verify-region> is a boolean value that indicates if the
bucket's region should be verified when the bucket object is
instantiated.
If set to true, this method will call the C<bucket> method with
C<verify_region> set to true causing the constructor to call the
C<get_location_constraint> for each bucket to set the bucket's
region. This will cause a significant decrease in the peformance of
the C<buckets()> method. Setting the region for each bucket is
necessary since API operations on buckets require the region of the
bucket when signing API requests. If all of your buckets are in the
same region and you have passed a region parameter to your S3 object,
then that region will be used when calling the constructor of your
bucket objects.
default: false
=back
Returns a reference to a hash containing the metadata for all of the
( run in 0.903 second using v1.01-cache-2.11-cpan-e1769b4cff6 )