Amazon-S3

 view release on metacpan or  search on metacpan

ChangeLog  view on Meta::CPAN


Fri Feb 10 07:47:22 2023  Rob Lauer  <rlauer6@comcast.net>>

	[0.60 - logging]:
	* VERSION: bump
	* NEWS.md: updated
	* bootstrap: support M.rr style versions
	* src/main/perl/lib/Amazon/S3.pm.in
	- removed all end of block indicators inserted by perltidy
	(new)
	- only consider 'debug' flag when internal logger used
	* src/main/perl/lib/Amazon/S3.pm.in
	(new): new
	* configure.ac
	- fix email addres
	- remove -Wall to prevent warning during configure
	* s3-perl.pl: new
	* src/main/perl/test.localstack: new
	* .gitignore: added some of the files created by `make cpan`

Wed Jan 25 11:54:59 2023  Rob Lauer  <rlauer6@comcast.net>

ChangeLog  view on Meta::CPAN

Tue Nov 29 10:39:43 2022  Rob Lauer  <rlauer6@comcast.net>

	[0.56 - minor bug, 0.55 issues #8]:
	* buildspec.yml: files should be relative to project home
	* VERSION: bump
	* NEWS.md: updated
	* README-TESTING.md: more documentation
	* Makefile.am: rpm, not rpmbuild directory
	* src/main/perl/Makefile.am: comments re: testing
	* src/main/perl/t/04-list-buckets.t
	- enable debug mode if $ENV{DEBUG}
	- dump response if error
	* src/main/perl/lib/Amazon/S3.pm.in
	- pod tweaks
	(new)
	- set -key and -pass  for legacy Crypt::CBC
	(buckets): avoid return explicit undef
	(list_bucket)
	- remove undefined hash members from input
	(_make_request)
	- use URI to set path, host, port if domain bucket ame

ChangeLog  view on Meta::CPAN

	(get_bucket_location): $bucket, not $self
	(buckets)
	- verify region option
	- pass hash of options and region to _send_request
	(add_bucket)
	- do not add region constraint if us-east-1
	- refactored, send region to _send_request_expect_nothing
	(delete_bucket): likewise refactored
	(list_bucket): likewise refactored
	(_make_request): use region() method of signer
	(_do_http): debug statements, set last_reponse, reset_errors
	(_do_http_no_redirect): likewise
	(_send_request_expect_nothing): likewise
	(_send_request_expect_nothing_probed)
	- accept hash argument
	- debug statements
	- croak if redirect, but no Location
	(error): new
	(reset_errors): new
	(_remember_error): set error
	* src/main/perl/lib/Amazon/S3/Bucket.pm.in
	- pod tweaks, corrections
	(new)
	- + logger attribute
	- + verify_region attribute, verify region if true
	(_uri): remove leading '/'
	(add_key): correct region if 301 response
	(upload_multipart_object): debug messages
	(upload_part_of_multipart_upload): likewise
	(complete_multipart_upload): likewise
	(get_key): remove redundant debug message
	(delete_key): pass region to _send_request_expect_nothing
	(set_acl): likewise
	* src/main/perl/t/01-api.t: do not bailout on early tests
	(error): new
	(last_response): new
	* src/main/perl/t/03-region.t: default region is us-east-1

Fri Jul 22 14:47:30 2022  Rob Lauer  <rlauer6@comcast.net>

	[0.55 - testing, revert to XML::Simple]:

ChangeLog  view on Meta::CPAN

	(get_default_region): new
	(get_aws_access_key_id): new
	(get_aws_secret_access_key): new
	(get_token): new
	(_decrypt): new
	(_encrypt): new
	(signer)
	- accesses _signer now
	- set default region to caller's value or default
	(buckets): set region to us-east-1 temporarily
	(debug): new convenience method for level => 'debug'
	(_make_request): allow disabling of domain buckets
	* src/main/perl/lib/Amazon/S3/Bucket.pm.in: comment tweak
	* src/main/perl/lib/Amazon/S3/Constant.pm.in: $DOT
	* src/main/perl/t/01-api.t: set $dns_bucket_names to true?
	* cpan/test-requires: +Test::Output
	* cpan/requires: -Test::Output
	* configure.ac
	- ads_PERL_MODULE XML::LibXML::Simple, XML::LibXML, Test::Output

Wed Jul 13 13:09:04 2022  Rob Lauer  <rlauer6@comcast.net>

README.md  view on Meta::CPAN

    * [empty\_bucket](#empty\bucket)
    * [get\_bucket\_location](#get\bucket\location)
    * [list\_directory\_buckets](#list\directory\buckets)
  * [OBJECT LISTING AND VERSIONING](#object-listing-and-versioning)
    * [list\_bucket](#list\bucket)
    * [list\_bucket\_v2](#list\bucket\v2)
    * [list\_bucket\_all\_v2](#list\bucket\all\v2)
    * [list\_object\_versions](#list\object\versions)
    * [turn\_off\_special\_retry](#turn\off\special\retry)
    * [turn\_on\_special\_retry](#turn\on\special\retry)
* [LOGGING AND DEBUGGING](#logging-and-debugging)
* [S3-COMPATIBLE SERVICES](#s3-compatible-services)
* [COMPARISON TO OTHER PERL S3 MODULES](#comparison-to-other-perl-s3-modules)
* [COMPATIBILITY AND LIMITATIONS](#compatibility-and-limitations)
  * [Minimum Perl Version](#minimum-perl-version)
  * [Signature Version 4](#signature-version-4)
  * [Directory Buckets](#directory-buckets)
* [TESTING](#testing)
* [SUPPORT](#support)
* [REPOSITORY](#repository)
* [AUTHOR](#author)

README.md  view on Meta::CPAN

    The object must provide:

        get_aws_access_key_id()
        get_aws_secret_access_key()
        get_token()

    [Amazon::Credentials](https://metacpan.org/pod/Amazon%3A%3ACredentials) is one implementation of this interface.

    See ["AUTHENTICATION AND CREDENTIALS"](#authentication-and-credentials).

- debug

    Compatibility option that sets the default logger level to `debug`.

    Applications should normally use `level` instead.

    This option affects the internally created logger only.

- dns\_bucket\_names

    Controls whether virtual-hosted-style bucket names are used when
    possible.

README.md  view on Meta::CPAN


    This option can also be used with S3-compatible and local testing
    services.

- level

    Logging level used when `Amazon::S3` creates its default logger.

    The default is `error`.

    See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

- logger

    Logger object.

    If omitted, `Amazon::S3::Logger` is used.

    A caller-supplied logger is expected to provide the logging methods
    used by `Amazon::S3`.

    See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

- raise\_error

    When true, S3 request failures that would normally be reported through
    the return value and the `err()`, `errstr()`, and `error()` accessors
    instead throw an exception.

    The exception includes the HTTP status and, when available, the S3
    error code and message.

README.md  view on Meta::CPAN

See ["ERROR HANDLING"](#error-handling).

### logger

    my $logger = $s3->logger;

    $s3->logger($logger);

Gets or sets the logger used by `Amazon::S3`.

See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

### retry

    my $retry = $s3->retry;

    $s3->retry($boolean);

Gets or sets whether retry-aware HTTP handling is enabled.

The constructor default is false.

README.md  view on Meta::CPAN

    my $logger = $s3->get_logger;

Returns the logger associated with the client.

If no logger was supplied to `new()`, this is the
[Amazon::S3::Logger](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ALogger) instance created by the constructor.

This method is provided for compatibility with logger interfaces that
expect `get_logger()`.

See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

### level

    my $level = $s3->level;

    $s3->level('debug');

Gets or sets the logging level.

When a level is supplied, both the stored logging level and the
associated logger level are updated.

When called without an argument, returns the current logger level.

The constructor default is `error`.

See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

### region

    my $region = $s3->region;

    $s3->region('us-west-2');

Gets or sets the region used by the client.

The region is used for account-level requests and as the default

README.md  view on Meta::CPAN

Logging is controlled by the configured logger and logging level.

When no logger is supplied, `Amazon::S3::Logger` is used.

Valid levels include:

    fatal
    error
    warn
    info
    debug
    trace

The default level is `error`.

At `debug` level, `Amazon::S3` records higher-level request and
configuration information.

At `trace` level, HTTP request and response information may also be
logged.

Applications should review trace output before retaining or sharing
it. Request and response data may contain sensitive application
information even when authentication values are sanitized.

# S3-COMPATIBLE SERVICES

README.md  view on Meta::CPAN


# SUPPORT

Bug reports and feature requests should be submitted through the
project issue tracker.

When reporting a problem, include the `Amazon::S3` version, Perl
version, operating system, and enough information to reproduce the
behavior.

For request or protocol problems, debug or trace logging may also be
useful. Review logs before sharing them to ensure that they do not
contain credentials, authorization information, or sensitive object
data.

# REPOSITORY

The source repository, issue tracker, and development history are
available at:

[https://github.com/rlauer6/Amazon-S3](https://github.com/rlauer6/Amazon-S3)

lib/Amazon/S3.pm  view on Meta::CPAN


  $options{dns_bucket_names} //= $TRUE;

  croak sprintf "ERROR: invalid checksum_algorithm: '%s'\nMust be one of: %s\n", $options{checksum_algorithm}, join q{,},
    @AWS_CHECKSUM_TYPES
    if none { $options{checksum_algorithm} eq $_ } @AWS_CHECKSUM_TYPES;

  $options{_region} = delete $options{region};
  $options{_signer} = delete $options{signer};

  # convenience for level => 'debug' & for consistency with
  # Amazon::Credentials only do this if we are using internal logger,
  # call should NOT use debug flag but rather use their own logger's
  # level to turn on higher levels of logging...

  if ( !$options{logger} ) {
    if ( delete $options{debug} ) {
      $options{level} = 'debug';
    }

    $options{log_level} = delete $options{level};
    $options{log_level} //= $DEFAULT_LOG_LEVEL;

    $options{logger}
      = Amazon::S3::Logger->new( log_level => $options{log_level} );
  }

  my $self = $class->SUPER::new( \%options );

  # setup logger internal logging

  $self->get_logger->debug(
    sub {
      my %safe_options = %options;

      if ( $safe_options{aws_secret_access_key} ) {
        $safe_options{aws_secret_access_key} = '****';
        $safe_options{aws_access_key_id}     = '****';
      }

      return Dumper( [ options => \%safe_options ] );
    },

lib/Amazon/S3.pm  view on Meta::CPAN


########################################################################
sub region {
########################################################################
  my ( $self, @args ) = @_;

  if (@args) {
    $self->_region( $args[0] );
  }

  $self->get_logger->debug( sub { return 'region: ' . ( $self->_region // $EMPTY ) } );

  if ( $self->_region ) {
    my $host = $self->host;
    $self->get_logger->debug( sub { return 'host: ' . $self->host } );

    # only add region if host was not populated from endpoint_url
    if ( !$self->endpoint_url && $host =~ /\As3[.](.*)?amazonaws/xsm ) {
      $self->host( sprintf 's3.%s.amazonaws.com', $self->_region );
    }
  }

  return $self->_region;
}

lib/Amazon/S3.pm  view on Meta::CPAN


      delete $conf->{$_};
    }

    my $query_string = $QUESTION_MARK . join $AMPERSAND, map { $_ . $EQUAL_SIGN . urlencode( $conf->{$_} ) }
      keys %{$conf};

    $path .= $query_string;
  }

  $self->get_logger->debug( sprintf 'PATH: %s', $path );

  my $r = $self->send_request(
    { method  => 'GET',
      path    => $path,
      headers => $headers // {},  # { 'Content-Length' => 0 },
      region  => $self->region,
    },
  );

  $self->get_logger->trace(

lib/Amazon/S3.pm  view on Meta::CPAN

    { method  => 'GET',
      path    => $path,
      headers => $headers // {},
      region  => $self->region,
    },
  );

  return
    if !$r || $self->errstr;

  $self->get_logger->debug(
    sub {
      return Dumper(
        [ marker      => $marker,
          next_marker => $next_marker,
          response    => $r,
        ],
      );
    },
  );

lib/Amazon/S3.pm  view on Meta::CPAN

  #  if ( $path =~ m{\A([^/?]+)([^?]+)(.*)}xsm
  if ( $path =~ /\A([^\/?]+)([^?]+)(.*)/xsm
    && $self->dns_bucket_names
    && is_domain_bucket($1) ) {

    my $bucket = $1;
    $path = $2;

    my $query_string = $3;

    $self->logger->debug(
      sub {
        return Dumper(
          [ bucket       => $bucket,
            path         => $path,
            query_string => $query_string,
          ]
        );
      }
    );

lib/Amazon/S3.pm  view on Meta::CPAN

  if ( ref($request) !~ /HTTP::Request/xsm ) {
    $keep_root = delete $request->{keep_root};

    $request = $self->_make_request($request);
  }

  my $response = $self->_do_http($request);

  $self->last_response($response);

  $logger->debug(
    sub {
      return Dumper( [ response => $response ] );
    }
  );

  return $self->_decode_response( $response, $keep_root );
}

########################################################################
sub is_json_response {

lib/Amazon/S3.pm  view on Meta::CPAN


  my $response = $self->ua->request( $request, $filename );

  # For new buckets at non-standard locations, amazon will sometimes
  # respond with a temporary redirect.  In this case it is necessary
  # to try again with the new URL
  my $location = $response->header('Location');

  if ( $response->code =~ /\A3/xsm and defined $location ) {

    $self->get_logger->debug(
      sub {
        return { sprintf 'Redirecting to:  %s', $location };
      }
    );

    $request->uri($location);
    $response = $self->ua->request( $request, $filename );
  }

  $self->get_logger->debug( sub { return Dumper( [$response] ) } );

  $self->last_response($response);

  return $response;
}

# Call this if handling any temporary redirect issues
# (Like needing to probe with a HEAD request when file handle are involved)

########################################################################
sub _do_http_no_redirect {
########################################################################
  my ( $self, $request, $filename ) = @_;

  # convenient time to reset any error conditions
  $self->reset_errors;

  my $response = $self->ua->request( $request, $filename );

  $self->get_logger->debug( sub { return Dumper( [$response] ) } );

  $self->last_response($response);

  return $response;
}

########################################################################
sub send_request_expect_nothing {
########################################################################
  my ( $self, @args ) = @_;

lib/Amazon/S3.pm  view on Meta::CPAN

  my $response = $self->_do_http_no_redirect($request);

  if ( $response->code =~ /^3/xsm ) {
    if ( defined $response->header('Location') ) {
      $override_uri = $response->header('Location');
    }
    else {
      $self->_handle_response_error( $response, $TRUE );
    }

    $self->get_logger->debug(
      sub {
        return sprintf 'setting override URI: [%s]', $override_uri;
      }
    );
  }

  $request = $self->_make_request(
    { method  => $method,
      path    => $path,
      headers => $conf,

lib/Amazon/S3.pm  view on Meta::CPAN

The object must provide:

  get_aws_access_key_id()
  get_aws_secret_access_key()
  get_token()

L<Amazon::Credentials> is one implementation of this interface.

See L</AUTHENTICATION AND CREDENTIALS>.

=item debug

Compatibility option that sets the default logger level to C<debug>.

Applications should normally use C<level> instead.

This option affects the internally created logger only.

=item dns_bucket_names

Controls whether virtual-hosted-style bucket names are used when
possible.

lib/Amazon/S3.pm  view on Meta::CPAN


This method is provided for compatibility with logger interfaces that
expect C<get_logger()>.

See L</LOGGING AND DEBUGGING>.

=head3 level

  my $level = $s3->level;

  $s3->level('debug');

Gets or sets the logging level.

When a level is supplied, both the stored logging level and the
associated logger level are updated.

When called without an argument, returns the current logger level.

The constructor default is C<error>.

lib/Amazon/S3.pm  view on Meta::CPAN

Logging is controlled by the configured logger and logging level.

When no logger is supplied, C<Amazon::S3::Logger> is used.

Valid levels include:

  fatal
  error
  warn
  info
  debug
  trace

The default level is C<error>.

At C<debug> level, C<Amazon::S3> records higher-level request and
configuration information.

At C<trace> level, HTTP request and response information may also be
logged.

Applications should review trace output before retaining or sharing
it. Request and response data may contain sensitive application
information even when authentication values are sanitized.

=head1 S3-COMPATIBLE SERVICES

lib/Amazon/S3.pm  view on Meta::CPAN


=head1 SUPPORT

Bug reports and feature requests should be submitted through the
project issue tracker.

When reporting a problem, include the C<Amazon::S3> version, Perl
version, operating system, and enough information to reproduce the
behavior.

For request or protocol problems, debug or trace logging may also be
useful. Review logs before sharing them to ensure that they do not
contain credentials, authorization information, or sensitive object
data.

=head1 REPOSITORY

The source repository, issue tracker, and development history are
available at:

L<https://github.com/rlauer6/Amazon-S3>

lib/Amazon/S3/Bucket.pm  view on Meta::CPAN

  }

  # now each bucket maintains its own region
  if ( !$self->region && $self->verify_region ) {
    my $region;

    if ( !$self->account->err ) {
      $region = $self->get_location_constraint() // 'us-east-1';
    }

    $self->logger->debug( sprintf "bucket: %s region: %s\n", $self->bucket, ( $region // $EMPTY ) );

    $self->region($region);
  }
  elsif ( !$self->region ) {
    $self->region( $self->account->region );
  }

  return $self;
}

lib/Amazon/S3/Bucket.pm  view on Meta::CPAN

    partNumber => ${part_number},
    uploadId   => ${upload_id}
  );

  my $params = $QUESTION_MARK
    . create_query_string(
    partNumber => ${part_number},
    uploadId   => ${upload_id}
    );

  $self->logger->debug(
    sub {
      return Dumper(
        [ part   => $part_number,
          length => length $data,
          path   => $path,
        ]
      );
    }
  );

lib/Amazon/S3/Bucket.pm  view on Meta::CPAN

#
# Inform Amazon that the multipart upload has been completed
# You must supply a hash of part Numbers => eTags
# For amazon to use to put the file together on their servers.
#
########################################################################
sub complete_multipart_upload {
########################################################################
  my ( $self, $key, $upload_id, $parts_hr, $algorithm ) = @_;

  $self->logger->debug( Dumper( [ $key, $upload_id, $parts_hr ] ) );

  croak 'Object key is required'
    if !$key;

  croak 'Upload id is required'
    if !$upload_id;

  croak 'Part number => etag hashref is required'
    if ref $parts_hr ne 'HASH';

  $algorithm = lc( $algorithm // $EMPTY );

  # The complete command requires sending a block of xml containing all
  # the part numbers and their associated etags (returned from the upload)
  my $content = _create_multipart_upload_request( $parts_hr, $algorithm );

  $self->logger->debug("content: \n$content");

  my $md5        = md5($content);
  my $md5_base64 = encode_base64($md5);
  chomp $md5_base64;

  my $headers = {
    'Content-MD5'    => $md5_base64,
    'Content-Length' => length $content,
    'Content-Type'   => 'application/xml',
  };

lib/Amazon/S3/CLI.pm  view on Meta::CPAN

    die "ERROR: usage add-key --bucket-name bucket-name filename object-name\n";
  };

  die sprintf "ERROR: file %s does not exist\n", $filename
    if !-e $filename;

  if ( $object_name =~ m{\A[/.]}xsm ) {
    $object_name =~ s{\A[/.]+(.*)$}{$1}xsm;
  }

  $self->get_logger->debug(
    sub {
      return Dumper(
        [ bucket_name => $bucket_name,
          filename    => $filename,
          object_name => $object_name,
        ]
      );
    }
  );

  my $content_type = $self->get_content_type // guess_content_type($filename);

  my $bucket = $self->get_bucket($bucket_name);

  $self->get_logger->debug( sub { return Dumper( [ $bucket->head_key($object_name) ] ); } );

  $self->get_logger->debug( sub { return Dumper( [ $bucket, $self->get_s3->last_response ] ); } );

  $bucket->add_key_filename( $object_name, $filename, { content_type => $content_type } );

  return $SUCCESS;
}

########################################################################
sub cmd_list_directory_buckets {
########################################################################
  my ($self) = @_;

lib/Amazon/S3/CLI.pm  view on Meta::CPAN

    die "ERROR: --profile requires Amazon::Credentials\n"
      if $self->get_profile;

    $credentials{aws_access_key_id}     = $ENV{AWS_ACCESS_KEY_ID};
    $credentials{aws_secret_access_key} = $ENV{AWS_SECRET_ACCESS_KEY};
    $credentials{token}                 = $ENV{AWS_SESSION_TOKEN};
  }

  my $s3 = Amazon::S3->new(
    { %credentials,
      debug            => $ENV{DEBUG},
      raise_error      => $TRUE,
      region           => $self->get_region,
      logger           => $self->get_logger,
      dns_bucket_names => $self->get_dns_bucket_names // $FALSE,
      %endpoint,
      defined $self->get_secure ? ( secure => $self->get_secure ) : (),
    }
  );

  $self->set_s3($s3);

lib/Amazon/S3/CLI.pm  view on Meta::CPAN

  my %default_options = (
    output => $EMPTY,
    region => 'us-east-1',
    format => 'text',
  );

  my @option_specs = qw(
    availability-zone=s
    bucket-name|b=s
    content-type=s
    debug
    dns-bucket-names
    endpoint-url|u=s
    force|f
    format|F=s
    help|h
    host|H=s
    key|k=s
    modified-since|m=s
    output|o=s
    prefix=s

lib/Amazon/S3/CLI.pm  view on Meta::CPAN

directory bucket.

=item B<--bucket-name>, B<-b>

Specifies the bucket name.

=item B<--content-type>

Specifies the content type used when adding an object.

=item B<--debug>

Enables debug logging.

=item B<--dns-bucket-names>

Enables DNS-style bucket addressing.

=item B<--endpoint-url>, B<-u>

Specifies the complete S3 service endpoint URL.

For example:

lib/Amazon/S3/Constants.pm  view on Meta::CPAN

Readonly our $MAX_DELETE_KEYS                 => 1000;
Readonly our $MAX_RETRIES                     => 5;
Readonly our $DEFAULT_REGION                  => 'us-east-1';
Readonly our $AWS_METADATA_BASE_URL           => 'http://169.254.169.254/latest/meta-data/';

Readonly our $XMLDECL  => '<?xml version="1.0" encoding="UTF-8"?>';
Readonly our $S3_XMLNS => 'http://s3.amazonaws.com/doc/2006-03-01/';

Readonly::Hash our %LOG_LEVELS => (
  trace => 5,
  debug => 4,
  info  => 3,
  warn  => 2,
  error => 1,
  fatal => 0,
);

Readonly::Hash our %LIST_OBJECT_MARKERS => (
  '3' => [qw(KeyMarker NextKeyMarker key-marker)],
  '2' => [qw(ContinuationToken NextContinuationToken continuation-token)],
  '1' => [qw(Marker NextMarker marker)],

lib/Amazon/S3/Logger.pm  view on Meta::CPAN


use English qw{-no_match_vars};
use POSIX;
use Readonly;
use Scalar::Util qw{ reftype };

our $VERSION = '2.1.2'; ## no critic (RequireInterpolationOfMetachars)

Readonly::Hash our %LOG_LEVELS => (
  trace => 5,
  debug => 4,
  info  => 3,
  warn  => 2,
  error => 1,
  fatal => 0,
);

{
  no strict 'refs'; ## no critic (ProhibitNoStrict)

  foreach my $level (qw{fatal error warn info debug trace}) {

    *{ __PACKAGE__ . $DOUBLE_COLON . $level } = sub {
      my ( $self, @message ) = @_;
      $self->_log_message( $level, @message );
    };
  }
}

########################################################################
sub new {

share/README.md  view on Meta::CPAN

    * [empty\_bucket](#empty\bucket)
    * [get\_bucket\_location](#get\bucket\location)
    * [list\_directory\_buckets](#list\directory\buckets)
  * [OBJECT LISTING AND VERSIONING](#object-listing-and-versioning)
    * [list\_bucket](#list\bucket)
    * [list\_bucket\_v2](#list\bucket\v2)
    * [list\_bucket\_all\_v2](#list\bucket\all\v2)
    * [list\_object\_versions](#list\object\versions)
    * [turn\_off\_special\_retry](#turn\off\special\retry)
    * [turn\_on\_special\_retry](#turn\on\special\retry)
* [LOGGING AND DEBUGGING](#logging-and-debugging)
* [S3-COMPATIBLE SERVICES](#s3-compatible-services)
* [COMPARISON TO OTHER PERL S3 MODULES](#comparison-to-other-perl-s3-modules)
* [COMPATIBILITY AND LIMITATIONS](#compatibility-and-limitations)
  * [Minimum Perl Version](#minimum-perl-version)
  * [Signature Version 4](#signature-version-4)
  * [Directory Buckets](#directory-buckets)
* [TESTING](#testing)
* [SUPPORT](#support)
* [REPOSITORY](#repository)
* [AUTHOR](#author)

share/README.md  view on Meta::CPAN

    The object must provide:

        get_aws_access_key_id()
        get_aws_secret_access_key()
        get_token()

    [Amazon::Credentials](https://metacpan.org/pod/Amazon%3A%3ACredentials) is one implementation of this interface.

    See ["AUTHENTICATION AND CREDENTIALS"](#authentication-and-credentials).

- debug

    Compatibility option that sets the default logger level to `debug`.

    Applications should normally use `level` instead.

    This option affects the internally created logger only.

- dns\_bucket\_names

    Controls whether virtual-hosted-style bucket names are used when
    possible.

share/README.md  view on Meta::CPAN


    This option can also be used with S3-compatible and local testing
    services.

- level

    Logging level used when `Amazon::S3` creates its default logger.

    The default is `error`.

    See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

- logger

    Logger object.

    If omitted, `Amazon::S3::Logger` is used.

    A caller-supplied logger is expected to provide the logging methods
    used by `Amazon::S3`.

    See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

- raise\_error

    When true, S3 request failures that would normally be reported through
    the return value and the `err()`, `errstr()`, and `error()` accessors
    instead throw an exception.

    The exception includes the HTTP status and, when available, the S3
    error code and message.

share/README.md  view on Meta::CPAN

See ["ERROR HANDLING"](#error-handling).

### logger

    my $logger = $s3->logger;

    $s3->logger($logger);

Gets or sets the logger used by `Amazon::S3`.

See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

### retry

    my $retry = $s3->retry;

    $s3->retry($boolean);

Gets or sets whether retry-aware HTTP handling is enabled.

The constructor default is false.

share/README.md  view on Meta::CPAN

    my $logger = $s3->get_logger;

Returns the logger associated with the client.

If no logger was supplied to `new()`, this is the
[Amazon::S3::Logger](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ALogger) instance created by the constructor.

This method is provided for compatibility with logger interfaces that
expect `get_logger()`.

See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

### level

    my $level = $s3->level;

    $s3->level('debug');

Gets or sets the logging level.

When a level is supplied, both the stored logging level and the
associated logger level are updated.

When called without an argument, returns the current logger level.

The constructor default is `error`.

See ["LOGGING AND DEBUGGING"](#logging-and-debugging).

### region

    my $region = $s3->region;

    $s3->region('us-west-2');

Gets or sets the region used by the client.

The region is used for account-level requests and as the default

share/README.md  view on Meta::CPAN

Logging is controlled by the configured logger and logging level.

When no logger is supplied, `Amazon::S3::Logger` is used.

Valid levels include:

    fatal
    error
    warn
    info
    debug
    trace

The default level is `error`.

At `debug` level, `Amazon::S3` records higher-level request and
configuration information.

At `trace` level, HTTP request and response information may also be
logged.

Applications should review trace output before retaining or sharing
it. Request and response data may contain sensitive application
information even when authentication values are sanitized.

# S3-COMPATIBLE SERVICES

share/README.md  view on Meta::CPAN


# SUPPORT

Bug reports and feature requests should be submitted through the
project issue tracker.

When reporting a problem, include the `Amazon::S3` version, Perl
version, operating system, and enough information to reproduce the
behavior.

For request or protocol problems, debug or trace logging may also be
useful. Review logs before sharing them to ensure that they do not
contain credentials, authorization information, or sensitive object
data.

# REPOSITORY

The source repository, issue tracker, and development history are
available at:

[https://github.com/rlauer6/Amazon-S3](https://github.com/rlauer6/Amazon-S3)

t/02-logger.t  view on Meta::CPAN

use_ok('Amazon::S3');

########################################################################
sub test_levels {
########################################################################
  my ($s3) = @_;

  print {*STDERR} "\n---[" . $s3->level . "]---\n";

  $s3->get_logger->trace("test trace\n");
  $s3->get_logger->debug("test debug\n");
  $s3->get_logger->info("test info\n");
  $s3->get_logger->warn("test warn\n");
  $s3->get_logger->error("test error\n");
  $s3->get_logger->fatal("test fatal\n");

  return;
} ## end sub test_levels

########################################################################
sub test_all_levels {
########################################################################
  my ($s3) = @_;

  $s3->level('trace');
  stderr_like( sub { test_levels($s3); },
    qr/trace\n.*debug\n.*info\n.*warn\n.*error\n.*fatal\n/xsm, 'trace' );

  $s3->level('debug');
  stderr_like( sub { test_levels($s3); },
    qr/debug\n.*info\n.*warn\n.*error\n.*fatal\n/xsm, 'debug' );
  stderr_unlike( sub { test_levels($s3); },
    qr/trace/, 'debug - not like trace' );

  $s3->level('info');
  stderr_like( sub { test_levels($s3); },
    qr/info\n.*warn\n.*error\n.*fatal\n/xsm, 'info' );
  stderr_unlike( sub { test_levels($s3); },
    qr/trace|debug/, 'info - not like trace, debug' );

  $s3->level('warn');
  stderr_like( sub { test_levels($s3); },
    qr/warn\n.*error\n.*fatal\n/xsm, 'warn' );
  stderr_unlike( sub { test_levels($s3); },
    qr/trace|debug|info/, 'warn - not like trace, debug, info' );

  $s3->level('error');
  stderr_like( sub { test_levels($s3); }, qr/error\n.*fatal\n/xsm, 'error' );
  stderr_unlike( sub { test_levels($s3); },
    qr/trace|debug|info|warn/, 'error - not like trace, debug, info, warn' );

  $s3->level('fatal');
  stderr_like( sub { test_levels($s3); }, qr/fatal\n/xsm, 'fatal' );
  stderr_unlike(
    sub { test_levels($s3); },
    qr/trace|debug|info|warn|error/,
    'fatal - not like trace, debug, info, warn, error'
  );

} ## end sub test_all_levels

########################################################################

my $s3 = Amazon::S3->new(
  { aws_access_key_id     => 'test',
    aws_secret_access_key => 'test',
  }

t/03-region.t  view on Meta::CPAN


use Test::More;

plan tests => 7;

use_ok('Amazon::S3');

my $s3 = Amazon::S3->new(
  { aws_access_key_id     => 'test',
    aws_secret_access_key => 'test',
    log_level             => $ENV{DEBUG} ? 'debug' : undef,
  }
);

ok( $s3->region, 'us-east-1' );

is( $s3->host, 's3.us-east-1.amazonaws.com',
  'default host is s3.us-east-1.amazonaws.com' );

$s3 = Amazon::S3->new(
  { aws_access_key_id     => 'test',
    aws_secret_access_key => 'test',
    region                => 'us-west-2',
    log_level             => $ENV{DEBUG} ? 'debug' : undef,
  }
);

is( $s3->region, 'us-west-2', 'region is set' );

is( $s3->host, 's3.us-west-2.amazonaws.com',
  'host is modified during creation' );

$s3->region('us-east-1');

t/lib/S3TestUtils.pm  view on Meta::CPAN

    else {
      return Amazon::S3->new(
        { aws_access_key_id     => $ENV{AWS_ACCESS_KEY_ID},
          aws_secret_access_key => $ENV{AWS_SECRET_ACCESS_KEY},
          token                 => $ENV{AWS_SESSION_TOKEN},
          host                  => $host,
          secure                => is_aws(),
          dns_bucket_names      => $ENV{AMAZON_S3_DNS_BUCKET_NAMES},
          level                 => $ENV{DEBUG} ? 'trace' : 'error',
          raise_error           => $raise_error,
          debug                 => $ENV{DEBUG},
        }
      );
    }
  };

  die $EVAL_ERROR
    if $EVAL_ERROR;

  return $s3;
}



( run in 1.706 second using v1.01-cache-2.11-cpan-062aa07a564 )