Amazon-Signature4-Lite

 view release on metacpan or  search on metacpan

lib/Amazon/Signature4/Lite.pm  view on Meta::CPAN

}

########################################################################
sub _encode_path {
########################################################################
  my ($path) = @_;

  # encode each segment individually, preserving slashes
  return join '/', map { uri_escape_utf8($_) } split m{/}xsm, $path, -1;
}

1;

__END__

=head1 NAME

Amazon::Signature4::Lite - Lightweight AWS Signature Version 4 signing

=head1 SYNOPSIS

  use Amazon::Signature4::Lite;

  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

A minimal, dependency-free AWS Signature Version 4 implementation for
signing S3 and other AWS API requests. Unlike L<AWS::Signature4>, this
module does not depend on L<LWP> or L<HTTP::Request> - it works
directly with the plain scalars and hashrefs that L<HTTP::Tiny> uses.

=head1 METHODS

=head2 new(%args)

  my $signer = Amazon::Signature4::Lite->new(
    access_key => $key,
    secret_key => $secret,
    region     => 'us-east-1',
  );

Required: C<access_key>, C<secret_key>, C<region>.
Optional: C<session_token> (for temporary credentials), C<service>
(defaults to C<s3>).

=head2 sign(%args)

  my $headers = $signer->sign(
    method  => 'GET',
    url     => $url,
    headers => \%extra_headers,
    payload => $body,
  );

Returns a hashref of HTTP headers including C<Authorization>,
C<x-amz-date>, C<x-amz-content-sha256>, and C<host>. Merge these
into your L<HTTP::Tiny> request headers.

=head2 parse_service_url(%args)

  my ($host, $service, $region) = Amazon::Signature4::Lite->parse_service_url(
    host           => 's3.us-east-2.amazonaws.com',
    default_region => 'us-east-1',
  );

Extracts service name and region from an AWS endpoint URL. Can be
called as a class or instance method.

I<Note: The patterns used for parsing are S3/AWS endpoint focused, not
a general URL parser.>

=head1 DEPENDENCIES

All dependencies are Perl core modules (since 5.10) or already
required by distributions in the Amazon::* toolchain:

=over 4

=item * L<Digest::SHA> (core since 5.10)

=item * L<MIME::Base64> (core)

=item * L<POSIX> (core)

=item * L<URI::Escape>

=back

=head1 SEE ALSO

L<AWS::Signature4>, L<Signer::AWSv4>, L<Amazon::S3::Lite>

=cut



( run in 2.140 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )