Amazon-S3

 view release on metacpan or  search on metacpan

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

########################################################################
  my ( $class, @args ) = @_;

  my %options = ref $args[0] ? %{ $args[0] } : @args;

  $options{timeout}            //= $DEFAULT_TIMEOUT;
  $options{cache_signer}       //= $FALSE;
  $options{retry}              //= $FALSE;
  $options{express}            //= $FALSE;
  $options{verify_checksums}   //= $TRUE;
  $options{checksum_algorithm} //= 'crc64nvme';
  $options{raise_error}        //= $FALSE;

  croak "ERROR: pass endpoint_url or host but not both\n"
    if $options{endpoint_url} && $options{host};

  if ( my $endpoint_url = $options{endpoint_url} ) {
    @options{qw(secure host)} = _parse_endpoint($endpoint_url);
  }
  elsif ( $options{host} ) {
    if ( $options{host} =~ m{\Ahttps?://}xsm ) {
      warn "host containing a URL is deprecated; use endpoint_url instead\n";

      @options{qw(secure host)} = _parse_endpoint( $options{host} );
    }
    else {
      $options{secure} //= $TRUE;
    }
  }
  else {
    $options{secure} = $TRUE;
    $options{host}   = $DEFAULT_HOST;
  }

  $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 ] );
    },
  );

  if ( !$self->credentials ) {

    croak 'No aws_access_key_id'
      if !$self->aws_access_key_id;

    croak 'No aws_secret_access_key'
      if !$self->aws_secret_access_key;

    # encrypt credentials
    $self->aws_access_key_id( _encrypt( $self->aws_access_key_id ) );
    $self->aws_secret_access_key( _encrypt( $self->aws_secret_access_key ) );
    $self->token( _encrypt( $self->token ) );
  }

  my $ua;

  if ( $self->retry ) {
    $ua = LWP::UserAgent::Determined->new(
      keep_alive            => $KEEP_ALIVE_CACHESIZE,
      requests_redirectable => [qw(GET HEAD DELETE)],
    );

    $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();
  }



( run in 1.788 second using v1.01-cache-2.11-cpan-4e491c91c6e )