| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Signer::AWSv4::S3; | 
| 2 | 1 |  |  | 1 |  | 78064 | use Moo; | 
|  | 1 |  |  |  |  | 12924 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 3 | 1 |  |  | 1 |  | 2409 | use Types::Standard qw/Str/; | 
|  | 1 |  |  |  |  | 83922 |  | 
|  | 1 |  |  |  |  | 15 |  | 
| 4 |  |  |  |  |  |  | extends 'Signer::AWSv4'; | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | has bucket => (is => 'ro', isa => Str, required => 1); | 
| 7 |  |  |  |  |  |  | has key => (is => 'ro', isa => Str, required => 1); | 
| 8 |  |  |  |  |  |  | has version_id => (is => 'ro', isa => Str); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | has '+service' => (default => 's3'); | 
| 11 |  |  |  |  |  |  | has '+uri' => (init_arg => undef, lazy => 1, default => sub { | 
| 12 |  |  |  |  |  |  | my $self = shift; | 
| 13 |  |  |  |  |  |  | sprintf "/%s/%s", $self->bucket, $self->key; | 
| 14 |  |  |  |  |  |  | }); | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | has bucket_host => (is => 'ro', isa => Str, init_arg => undef, lazy => 1, default => sub { | 
| 17 |  |  |  |  |  |  | my $self = shift; | 
| 18 |  |  |  |  |  |  | if ($self->region =~m/us-east-1/i) { | 
| 19 |  |  |  |  |  |  | return 's3.amazonaws.com'; | 
| 20 |  |  |  |  |  |  | } else { | 
| 21 |  |  |  |  |  |  | return 's3-' . $self->region . '.amazonaws.com'; | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  | }); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | has '+unsigned_payload' => (default => 1); | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub build_params { | 
| 28 | 2 |  |  | 2 | 0 | 28 | my $self = shift; | 
| 29 |  |  |  |  |  |  | { | 
| 30 | 2 |  |  |  |  | 63 | 'X-Amz-Algorithm' => $self->aws_algorithm, | 
| 31 |  |  |  |  |  |  | 'X-Amz-Credential' => $self->access_key . "/" . $self->credential_scope, | 
| 32 |  |  |  |  |  |  | 'X-Amz-Date' => $self->date_timestamp, | 
| 33 |  |  |  |  |  |  | 'X-Amz-Expires' => $self->expires, | 
| 34 |  |  |  |  |  |  | 'X-Amz-SignedHeaders' => $self->signed_header_list, | 
| 35 |  |  |  |  |  |  | (versionId => $self->version_id) x!! $self->version_id, | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub build_headers { | 
| 40 | 2 |  |  | 2 | 0 | 26 | my $self = shift; | 
| 41 |  |  |  |  |  |  | { | 
| 42 | 2 |  |  |  |  | 38 | Host => $self->bucket_host, | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | has signed_url => (is => 'ro', isa => Str, init_arg => undef, lazy => 1, default => sub { | 
| 47 |  |  |  |  |  |  | my $self = shift; | 
| 48 |  |  |  |  |  |  | return join '', 'https://', $self->bucket_host, $self->uri, '?', $self->signed_qstring; | 
| 49 |  |  |  |  |  |  | }); | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | 1; | 
| 52 |  |  |  |  |  |  | ### main pod documentation begin ### | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | =encoding UTF-8 | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head1 NAME | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | Signer::AWSv4::S3 - Implements the AWS v4 signature algorithm | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | use Signer::AWSv4::S3; | 
| 63 |  |  |  |  |  |  | $s3_sig = Signer::AWSv4::S3->new( | 
| 64 |  |  |  |  |  |  | access_key => 'AKIAIOSFODNN7EXAMPLE', | 
| 65 |  |  |  |  |  |  | secret_key => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', | 
| 66 |  |  |  |  |  |  | method => 'GET', | 
| 67 |  |  |  |  |  |  | key => 'test.txt', | 
| 68 |  |  |  |  |  |  | bucket => 'examplebucket', | 
| 69 |  |  |  |  |  |  | region => 'us-east-1', | 
| 70 |  |  |  |  |  |  | expires => 86400, | 
| 71 |  |  |  |  |  |  | ); | 
| 72 |  |  |  |  |  |  | say $s3_sig->signed_url; | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | Generates S3 Presigned URLs. | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head1 Request Attributes | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | This module adds two required attributes in the constructor for obtaining an | 
| 81 |  |  |  |  |  |  | S3 Presigned URL: | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =head2 key | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | The name of the object in S3. This should not start with a slash (/) | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =head2 bucket | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | The name of the S3 bucket | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head1 Signature Attributes | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | Apart from those in L, a convenience attribute is added: | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head2 signed_url | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | The presigned URL to download the object | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head1 BUGS and SOURCE | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | The source code is located here: L | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | Please report bugs to: L | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | =head1 AUTHOR | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | Jose Luis Martinez | 
| 108 |  |  |  |  |  |  | CAPSiDE | 
| 109 |  |  |  |  |  |  | jlmartinez@capside.com | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =head1 COPYRIGHT and LICENSE | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | Copyright (c) 2018 by CAPSiDE | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | This code is distributed under the Apache 2 License. The full text of the license can be found in the LICENSE file included with this module. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =cut |