| 1 | package Net::Amazon::S3::Request; | ||||||||||||||||||||||||||||
| 2 | 99 | $Net::Amazon::S3::Request::VERSION = '0.99'; | |||||||||||||||||||||||||||
| 3 | 99 | ▶ | use Moose 0.85; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 99 | ▶ | use MooseX::StrictConstructor 0.16; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 99 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 99 | ▶ | use Regexp::Common qw /net/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # ABSTRACT: Base class for request objects | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 99 | ▶ | use Net::Amazon::S3::Constraint::ACL::Canned; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 99 | enum 'LocationConstraint' => [ | |||||||||||||||||||||||||||
| 13 | # https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region | ||||||||||||||||||||||||||||
| 14 | # https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html#API_CreateBucket_RequestSyntax | ||||||||||||||||||||||||||||
| 15 | 'af-south-1', | ||||||||||||||||||||||||||||
| 16 | 'ap-east-1', | ||||||||||||||||||||||||||||
| 17 | 'ap-northeast-1', | ||||||||||||||||||||||||||||
| 18 | 'ap-northeast-2', | ||||||||||||||||||||||||||||
| 19 | 'ap-northeast-3', | ||||||||||||||||||||||||||||
| 20 | 'ap-south-1', | ||||||||||||||||||||||||||||
| 21 | 'ap-southeast-1', | ||||||||||||||||||||||||||||
| 22 | 'ap-southeast-2', | ||||||||||||||||||||||||||||
| 23 | 'ca-central-1', | ||||||||||||||||||||||||||||
| 24 | 'cn-north-1', | ||||||||||||||||||||||||||||
| 25 | 'cn-northwest-1', | ||||||||||||||||||||||||||||
| 26 | 'EU', | ||||||||||||||||||||||||||||
| 27 | 'eu-central-1', | ||||||||||||||||||||||||||||
| 28 | 'eu-north-1', | ||||||||||||||||||||||||||||
| 29 | 'eu-south-1', | ||||||||||||||||||||||||||||
| 30 | 'eu-west-1', | ||||||||||||||||||||||||||||
| 31 | 'eu-west-2', | ||||||||||||||||||||||||||||
| 32 | 'eu-west-3', | ||||||||||||||||||||||||||||
| 33 | 'me-south-1', | ||||||||||||||||||||||||||||
| 34 | 'sa-east-1', | ||||||||||||||||||||||||||||
| 35 | 'us-east-1', | ||||||||||||||||||||||||||||
| 36 | 'us-east-2', | ||||||||||||||||||||||||||||
| 37 | 'us-gov-east-1', | ||||||||||||||||||||||||||||
| 38 | 'us-gov-west-1', | ||||||||||||||||||||||||||||
| 39 | 'us-west-1', | ||||||||||||||||||||||||||||
| 40 | 'us-west-2', | ||||||||||||||||||||||||||||
| 41 | ]; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 99 | subtype 'MaybeLocationConstraint' | |||||||||||||||||||||||||||
| 44 | => as 'Maybe[LocationConstraint]' | ||||||||||||||||||||||||||||
| 45 | ; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # maintain backward compatiblity with 'US' and 'EU' values | ||||||||||||||||||||||||||||
| 48 | 99 | my %location_constraint_alias = ( | |||||||||||||||||||||||||||
| 49 | US => 'us-east-1', | ||||||||||||||||||||||||||||
| 50 | EU => 'eu-west-1', | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 99 | enum 'LocationConstraintAlias' => [ keys %location_constraint_alias ]; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | coerce 'LocationConstraint' | ||||||||||||||||||||||||||||
| 56 | => from 'LocationConstraintAlias' | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | => via { $location_constraint_alias{$_} } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 58 | 99 | ; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | coerce 'MaybeLocationConstraint' | ||||||||||||||||||||||||||||
| 61 | => from 'LocationConstraintAlias' | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | => via { $location_constraint_alias{$_} } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 63 | 99 | ; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # To comply with Amazon S3 requirements, bucket names must: | ||||||||||||||||||||||||||||
| 66 | # Contain lowercase letters, numbers, periods (.), underscores (_), and dashes (-) | ||||||||||||||||||||||||||||
| 67 | # Start with a number or letter | ||||||||||||||||||||||||||||
| 68 | # Be between 3 and 255 characters long | ||||||||||||||||||||||||||||
| 69 | # Not be in an IP address style (e.g., "192.168.5.4") | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | subtype 'BucketName1' => as 'Str' => where { | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $_ =~ /^[a-zA-Z0-9._-]+$/; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 73 | } => message { | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | "Bucket name ($_) must contain lowercase letters, numbers, periods (.), underscores (_), and dashes (-)"; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 75 | 99 | }; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | subtype 'BucketName2' => as 'BucketName1' => where { | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $_ =~ /^[a-zA-Z0-9]/; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 79 | } => message { | ||||||||||||||||||||||||||||
| 80 | 0 | ▶ | "Bucket name ($_) must start with a number or letter"; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 81 | 99 | }; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | subtype 'BucketName3' => as 'BucketName2' => where { | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | length($_) >= 3 && length($_) <= 255; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | } => message { | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | "Bucket name ($_) must be between 3 and 255 characters long"; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 87 | 99 | }; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | subtype 'BucketName' => as 'BucketName3' => where { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $_ !~ /^$RE{net}{IPv4}$/; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 91 | } => message { | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | "Bucket name ($_) must not be in an IP address style (e.g., '192.168.5.4')"; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 93 | 99 | }; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 99 | has 's3' => ( is => 'ro', isa => 'Net::Amazon::S3', required => 1 ); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 99 | has '_http_request_content' => ( | |||||||||||||||||||||||||||
| 98 | is => 'ro', | ||||||||||||||||||||||||||||
| 99 | init_arg => undef, | ||||||||||||||||||||||||||||
| 100 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||
| 101 | lazy => 1, | ||||||||||||||||||||||||||||
| 102 | builder => '_request_content', | ||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 99 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub _request_content { | ||||||||||||||||||||||||||||
| 108 | 139 | ▶ | ''; | ||||||||||||||||||||||||||
|
Subroutine
_request_content: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub _request_path { | ||||||||||||||||||||||||||||
| 112 | 430 | ▶ | ''; | ||||||||||||||||||||||||||
|
Subroutine
_request_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | ▶ | sub _request_headers { | |||||||||||||||||||||||||||
|
Subroutine
_request_headers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | ▶ | sub _request_query_action { | |||||||||||||||||||||||||||
|
Subroutine
_request_query_action: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | ▶ | sub _request_query_params { | |||||||||||||||||||||||||||
|
Subroutine
_request_query_params: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub _request_query_string { | ||||||||||||||||||||||||||||
| 125 | 416 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_request_query_string: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 416 | my %query_params = $self->_request_query_params; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 416 | my @parts = ( | |||||||||||||||||||||||||||
| 130 | ($self->_request_query_action) x!! $self->_request_query_action, | ||||||||||||||||||||||||||||
| 131 | 74 | map "$_=${\ $self->s3->_urlencode( $query_params{$_} ) }", sort keys %query_params, | |||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 416 | ▶ | return '' unless @parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 232 | return '?' . join '&', @parts; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | sub _http_request_path { | ||||||||||||||||||||||||||||
| 139 | 416 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_http_request_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 416 | return $self->_request_path . $self->_request_query_string; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | sub _http_request_headers { | ||||||||||||||||||||||||||||
| 145 | 430 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_http_request_headers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 430 | return +{ $self->_request_headers }; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | sub _build_signed_request { | ||||||||||||||||||||||||||||
| 151 | 430 | ▶ | my ($self, %params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build_signed_request: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 430 | ▶ | $params{path} = $self->_http_request_path unless exists $params{path}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 430 | ▶ | $params{method} = $self->_http_request_method unless exists $params{method}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 430 | ▶ | $params{headers} = $self->_http_request_headers unless exists $params{headers}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 430 | ▶ | $params{content} = $self->_http_request_content unless exists $params{content} or ! defined $self->_http_request_content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $params{"content"} or not defined $self->_http_request_content
MC/DC50%1/2
exists $params{"content"} or not defined $self->_http_request_content
exists $params{"content"}
not defined $self->_http_request_content
Truth table66%2/3
A or not(B)
A= exists $params{"content"}B= not defined $self->_http_request_content
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # Although Amazon's Signature 4 test suite explicitely handles // it appears | ||||||||||||||||||||||||||||
| 159 | # it's inconsistent with their implementation so removing it here | ||||||||||||||||||||||||||||
| 160 | 430 | $params{path} =~ s{//+}{/}g; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 430 | ▶ | return Net::Amazon::S3::HTTPRequest->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | %params, | ||||||||||||||||||||||||||||
| 164 | s3 => $self->s3, | ||||||||||||||||||||||||||||
| 165 | $self->can( 'bucket' ) ? (bucket => $self->bucket) : (), | ||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | sub _build_http_request { | ||||||||||||||||||||||||||||
| 170 | 210 | ▶ | my ($self, %params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build_http_request: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 210 | return $self->_build_signed_request( %params )->http_request; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | sub http_request { | ||||||||||||||||||||||||||||
| 176 | 294 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
http_request: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 294 | return $self->_build_http_request; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 99 | 1; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | __END__ | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =pod | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =head1 NAME | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | Net::Amazon::S3::Request - Base class for request objects | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =head1 VERSION | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | version 0.99 | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | # do not instantiate directly | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | This module is a base class for all the Net::Amazon::S3::Request::* | ||||||||||||||||||||||||||||
| 204 | classes. | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Branislav Zahradník <barney@cpan.org> | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | This software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník. | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 215 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||