| 1 | package Net::Blossom::Server::Backend::S3::_Client; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Class::Tiny qw(bucket); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Net::Amazon::S3 0.992; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Net::Amazon::S3::Client; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Net::Amazon::S3::Signature::V4; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Net::Amazon::S3::Vendor::Generic; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | my $MIB = 1024 * 1024; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | my $GIB = 1024 * $MIB; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | my $GB = 1_000_000_000; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | my $MAX_PARTS = 10_000; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | my $MAX_PART_SIZE = 5 * $GIB; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | my $MAX_OBJECT_SIZE = $MAX_PARTS * $MAX_PART_SIZE; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | my $MAX_SINGLE_PUT = 5 * $GB; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 31 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=14 SCAR=31.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 31 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 31 | my %args = _constructor_args(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 31 | my %known = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | bucket bucket_object endpoint region access_key_id secret_access_key | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | session_token path_style s3 timeout retry | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 31 | my @unknown = grep { !$known{$_} } keys %args; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 31 | ▶ | croak "unknown argument(s): " . join(', ', sort @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 31 | ▶ | if (defined $args{bucket_object}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 17 | ▶ | my @other = grep { exists $args{$_} && $_ ne 'bucket_object' } keys %args; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
exists $args{$_} && $_ ne 'bucket_object'
MC/DC0%0/2
exists $args{$_} && $_ ne 'bucket_object'
exists $args{$_}
$_ ne 'bucket_object'
Truth table33%1/3
A && B
A= exists $args{$_}B= $_ ne 'bucket_object'
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 17 | ▶ | croak "bucket_object cannot be combined with connection arguments" if @other; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | croak "bucket_object must provide object" | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 17 | ▶ | unless blessed($args{bucket_object}) && $args{bucket_object}->can('object'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($args{"bucket_object"}) and $args{"bucket_object"}->can("object")
MC/DC0%0/2
builtin::blessed($args{"bucket_object"}) and $args{"bucket_object"}->can("object")
builtin::blessed($args{"bucket_object"})
$args{"bucket_object"}->can("object")
Truth table33%1/3
A and B
A= builtin::blessed($args{"bucket_object"})B= $args{"bucket_object"}->can("object")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 17 | return {bucket => $args{bucket_object}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | croak "bucket is required" | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 14 | ▶ | unless defined $args{bucket} && !ref($args{bucket}) && length $args{bucket}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $args{"bucket"} and not ref $args{"bucket"} and length $args{"bucket"}
defined $args{"bucket"} and not ref $args{"bucket"}
MC/DC0%0/3
defined $args{"bucket"} and not ref $args{"bucket"} and length $args{"bucket"}
defined $args{"bucket"}
not ref $args{"bucket"}
length $args{"bucket"}
Truth table25%1/4
A and not(B) and C
A= defined $args{"bucket"}B= not ref $args{"bucket"}C= length $args{"bucket"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 14 | my $s3 = delete $args{s3}; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 14 | ▶ | if (defined $s3) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my @connection_args = grep { exists $args{$_} } qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | endpoint region access_key_id secret_access_key session_token | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | path_style timeout retry | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | croak "s3 cannot be combined with connection arguments" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | if @connection_args; | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | croak "s3 must be a Net::Amazon::S3 object" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($s3) and $s3->isa("Net::Amazon::S3")
MC/DC0%0/2
builtin::blessed($s3) and $s3->isa("Net::Amazon::S3")
builtin::blessed($s3)
$s3->isa("Net::Amazon::S3")
Truth table0%0/3
A and B
A= builtin::blessed($s3)B= $s3->isa("Net::Amazon::S3")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | unless blessed($s3) && $s3->isa('Net::Amazon::S3'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 13 | $s3 = _build_s3(%args); | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | my $client = Net::Amazon::S3::Client->new(s3 => $s3); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | return {bucket => $client->bucket(name => $args{bucket})}; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 12 | ▶ | sub upload_file { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload_file: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | croak "S3 object size exceeds multipart limit" | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 12 | ▶ | if $args{size} > $MAX_OBJECT_SIZE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | croak "multipart part size exceeds 5 GiB" | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 11 | ▶ | if $args{multipart_part_size} > $MAX_PART_SIZE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | return $args{size} < $args{multipart_threshold} | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 11 | ▶ | && $args{size} <= $MAX_SINGLE_PUT | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$args{"size"} < $args{"multipart_threshold"} and $args{"size"} <= $MAX_SINGLE_PUT
MC/DC100%2/2
$args{"size"} < $args{"multipart_threshold"} and $args{"size"} <= $MAX_SINGLE_PUT
$args{"size"} < $args{"multipart_threshold"}
$args{"size"} <= $MAX_SINGLE_PUT
Truth table100%3/3
A and B
A= $args{"size"} < $args{"multipart_threshold"}B= $args{"size"} <= $MAX_SINGLE_PUT
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ? $self->_put_file(%args) | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | : $self->_multipart_put_file(%args); | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 6 | ▶ | sub head { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
head: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | my $response = $self->_object($key)->_perform_operation( | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 'Net::Amazon::S3::Operation::Object::Head', | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | ▶ | return if $response->code == 404; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | _assert_success('S3 HEAD', $response); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | my $size = $response->http_response->header('Content-Length'); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | croak "S3 HEAD response has no Content-Length" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | unless defined $size; | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | return {size => 0 + $size}; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | sub get_range { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_range: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | my ($self, $key, $start, $end) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | my $response = $self->_object($key)->range("bytes=$start-$end")->_get; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | return if $response->code == 404; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | _assert_success('S3 ranged GET', $response); | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | return $response->content; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | ▶ | return 0 unless defined $self->head($key); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | my $response = $self->_object($key)->_perform_operation( | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 'Net::Amazon::S3::Operation::Object::Delete', | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | _assert_success('S3 DELETE', $response); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | sub _put_file { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_put_file: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | my $object = $self->_object( | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | $args{key}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | content_type => $args{content_type}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | user_metadata => {sha256 => $args{sha256}}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | size => $args{size}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | $object->put_filename($args{path}); | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 9 | ▶ | sub _multipart_put_file { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_multipart_put_file: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 9 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 9 | my $object = $self->_object($args{key}); | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | my $part_size = _part_size_for($args{size}, $args{multipart_part_size}); | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 9 | my $upload_id; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 9 | my (@etags, @part_numbers); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 9 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | $upload_id = $object->initiate_multipart_upload(headers => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 'Content-Type' => $args{content_type}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 'x-amz-meta-sha256' => $args{sha256}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 9 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 9 | ▶ | croak "S3 did not return a multipart upload ID" unless defined $upload_id; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | open my $fh, '<:raw', $args{path} | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 9 | ▶ | or croak "unable to read upload temp file: $!"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | my $part_number = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 8 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 16 | my $part = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 16 | my $bytes = read $fh, $part, $part_size; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 16 | ▶ | croak "unable to read upload temp file: $!" unless defined $bytes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 16 | ▶ | last unless $bytes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 11 | ++$part_number; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 11 | my $response = $object->put_part( | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | upload_id => $upload_id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | part_number => $part_number, | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | value => $part, | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | headers => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 11 | ▶ | croak "S3 multipart part $part_number failed: " . $response->status_line | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | unless $response->is_success; | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 9 | my $etag = $response->header('ETag'); | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | ▶ | croak "S3 multipart part $part_number returned no ETag" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $etag and length $etag
MC/DC50%1/2
defined $etag and length $etag
defined $etag
length $etag
Truth table66%2/3
A and B
A= defined $etagB= length $etag
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | unless defined $etag && length $etag; | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 8 | push @etags, $etag; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | 8 | push @part_numbers, $part_number; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | ▶ | close $fh or croak "unable to close upload temp file: $!"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | my $response = $object->_perform_operation( | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 'Net::Amazon::S3::Operation::Object::Upload::Complete', | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | upload_id => $upload_id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | etags => \@etags, | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | part_numbers => \@part_numbers, | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | _assert_success('S3 multipart completion', $response); | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 9 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 9 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 6 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 6 | ▶ | $object->abort_multipart_upload(upload_id => $upload_id) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | if defined $upload_id; | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 6 | die $error; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 21 | ▶ | sub _object { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_object: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 21 | my ($self, $key, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 21 | return $self->bucket->object(key => $key, %args); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 11 | ▶ | sub _part_size_for { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_part_size_for: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 11 | my ($size, $preferred) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | 11 | my $minimum = int(($size + $MAX_PARTS - 1) / $MAX_PARTS); | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 11 | ▶ | my $part_size = $preferred > $minimum ? $preferred : $minimum; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 11 | ▶ | $part_size = 5 * $MIB if $part_size < 5 * $MIB; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 11 | return $part_size; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 14 | ▶ | sub _assert_success { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_success: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 14 | my ($action, $response) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 14 | ▶ | my $embedded_error = $response->is_success | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$response->is_success && $response->can('is_error') && $response->is_error
$response->is_success and $response->can("is_error")
MC/DC66%2/3
$response->is_success && $response->can('is_error') && $response->is_error
$response->is_success
$response->can("is_error")
$response->is_error
Truth table75%3/4
A and B && C
A= $response->is_successB= $response->can("is_error")C= $response->is_error
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | && $response->can('is_error') | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | && $response->is_error; | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 14 | ▶ | return 1 if $response->is_success && !$embedded_error; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$response->is_success and not $embedded_error
MC/DC100%2/2
$response->is_success and not $embedded_error
$response->is_success
not $embedded_error
Truth table100%3/3
A and not(B)
A= $response->is_successB= not $embedded_error
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 6 | ▶ | my $detail = $embedded_error && $response->can('error_code') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$embedded_error and $response->can("error_code")
MC/DC50%1/2
$embedded_error and $response->can("error_code")
$embedded_error
$response->can("error_code")
Truth table66%2/3
A and B
A= $embedded_errorB= $response->can("error_code")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ? $response->error_code | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | : $response->status_line; | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | croak "$action failed: $detail"; | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 13 | ▶ | sub _build_s3 { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_s3: called CC=21 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 13 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 13 | ▶ | my $region = defined $args{region} ? $args{region} : 'us-east-1'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 13 | ▶ | croak "region must be a non-empty scalar" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $region or not length $region
MC/DC0%0/2
ref $region or not length $region
ref $region
not length $region
Truth table33%1/3
A or not(B)
A= ref $regionB= not length $region
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | if ref($region) || !length $region; | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 13 | ▶ | croak "region contains unsafe characters" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | unless $region =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | my ($host, $use_https, $custom_endpoint) = _endpoint( | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | $args{endpoint}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 12 | $region, | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | my $path_style = defined $args{path_style} | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 6 | ▶ | ? _boolean($args{path_style}, 'path_style') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | : $custom_endpoint; | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | my $retry = defined $args{retry} | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 5 | ▶ | ? _boolean($args{retry}, 'retry') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | : 1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | my $access_key_id = defined $args{access_key_id} | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ? $args{access_key_id} | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | ▶ | : $ENV{AWS_ACCESS_KEY_ID}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | my $secret_access_key = defined $args{secret_access_key} | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | ? $args{secret_access_key} | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | ▶ | : $ENV{AWS_SECRET_ACCESS_KEY}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | my $session_token = defined $args{session_token} | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ? $args{session_token} | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | ▶ | : $ENV{AWS_SESSION_TOKEN}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | ▶ | croak "access_key_id or AWS_ACCESS_KEY_ID is required" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $access_key_id and not ref $access_key_id and length $access_key_id
defined $access_key_id and not ref $access_key_id
MC/DC0%0/3
defined $access_key_id and not ref $access_key_id and length $access_key_id
defined $access_key_id
not ref $access_key_id
length $access_key_id
Truth table25%1/4
A and not(B) and C
A= defined $access_key_idB= not ref $access_key_idC= length $access_key_id
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | unless defined $access_key_id && !ref($access_key_id) && length $access_key_id; | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | croak "secret_access_key or AWS_SECRET_ACCESS_KEY is required" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $secret_access_key and not ref $secret_access_key and length $secret_access_key
defined $secret_access_key and not ref $secret_access_key
MC/DC0%0/3
defined $secret_access_key and not ref $secret_access_key and length $secret_access_key
defined $secret_access_key
not ref $secret_access_key
length $secret_access_key
Truth table25%1/4
A and not(B) and C
A= defined $secret_access_keyB= not ref $secret_access_keyC= length $secret_access_key
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | unless defined $secret_access_key && !ref($secret_access_key) && length $secret_access_key; | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | ▶ | croak "session_token must be a non-empty scalar" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $session_token and ref $session_token || !length($session_token)
ref $session_token or not length $session_token
MC/DC66%2/3
defined $session_token and ref $session_token || !length($session_token)
defined $session_token
ref $session_token
not length $session_token
Truth table75%3/4
A and B or not(C)
A= defined $session_tokenB= ref $session_tokenC= not length $session_token
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | if defined $session_token && (ref($session_token) || !length $session_token); | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | my $vendor = Net::Amazon::S3::Vendor::Generic->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | host => $host, | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | use_https => $use_https, | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | use_virtual_host => !$path_style, | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | authorization_method => 'Net::Amazon::S3::Signature::V4', | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | default_region => $region, | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | return Net::Amazon::S3->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | vendor => $vendor, | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | aws_access_key_id => $access_key_id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | aws_secret_access_key => $secret_access_key, | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | (defined $session_token ? (aws_session_token => $session_token) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | ▶ | timeout => defined $args{timeout} ? $args{timeout} : 30, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | retry => $retry, | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 12 | ▶ | sub _endpoint { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_endpoint: called CC=22 SCAR=32.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 12 | my ($endpoint, $region) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | 12 | ▶ | if (!defined $endpoint) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 3 | ▶ | my $host = $region eq 'us-east-1' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | ? 's3.amazonaws.com' | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | : "s3.$region.amazonaws.com"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 3 | return ($host, 1, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 9 | ▶ | croak "endpoint must be a scalar" if ref($endpoint); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 9 | my $uri = URI->new($endpoint); | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 9 | ▶ | croak "endpoint must be an HTTP URL with a host" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition62%5/8
($uri->scheme || "") =~ /\Ahttps?\z/ and defined $uri->host and length $uri->host
($uri->scheme || "") =~ /\Ahttps?\z/ and defined $uri->host
$uri->scheme || ''
MC/DC0%0/3
($uri->scheme || "") =~ /\Ahttps?\z/ and defined $uri->host and length $uri->host
$uri->scheme
defined $uri->host
length $uri->host
Truth table25%1/4
A and B and C
A= $uri->schemeB= defined $uri->hostC= length $uri->host
| |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | unless ($uri->scheme || '') =~ /\Ahttps?\z/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | && defined $uri->host | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | && length $uri->host; | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 8 | ▶ | croak "endpoint cannot contain userinfo, query, or fragment" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $uri->userinfo or defined $uri->query or defined $uri->fragment
defined $uri->userinfo or defined $uri->query
MC/DC33%1/3
defined $uri->userinfo or defined $uri->query or defined $uri->fragment
defined $uri->userinfo
defined $uri->query
defined $uri->fragment
Truth table50%2/4
A or B or C
A= defined $uri->userinfoB= defined $uri->queryC= defined $uri->fragment
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | if defined $uri->userinfo || defined $uri->query || defined $uri->fragment; | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 7 | ▶ | croak "endpoint cannot contain a path" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $uri->path and $uri->path ne "" and $uri->path ne "/"
defined $uri->path and $uri->path ne ""
MC/DC33%1/3
defined $uri->path and $uri->path ne "" and $uri->path ne "/"
defined $uri->path
$uri->path ne ""
$uri->path ne "/"
Truth table50%2/4
A and B and C
A= defined $uri->pathB= $uri->path ne ""C= $uri->path ne "/"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | if defined $uri->path && $uri->path ne '' && $uri->path ne '/'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 6 | ▶ | croak "endpoint contains unsafe characters" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | if $endpoint =~ /[\x00-\x20\x7f]/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 6 | my $authority = $uri->authority; | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 6 | my $port; | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 6 | ▶ | if ($authority =~ /\A\[[^\]]+\](?::([^:]+))?\z/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $port = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | elsif ($authority =~ /\A[^:]+(?::([^:]+))?\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 6 | $port = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | croak "endpoint authority is invalid"; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 6 | ▶ | if (defined $port) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 4 | ▶ | croak "endpoint must use a numeric port" unless $port =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 3 | ▶ | croak "endpoint port must be between 1 and 65535" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$port < 1 or $port > 65535
MC/DC100%2/2
$port < 1 or $port > 65535
$port < 1
$port > 65535
Truth table100%3/3
A or B
A= $port < 1B= $port > 65535
| |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | if $port < 1 || $port > 65_535; | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 3 | ▶ | return ($authority, $uri->scheme eq 'https' ? 1 : 0, 1); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | ▶ | sub _boolean { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_boolean: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 3 | my ($value, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 3 | ▶ | croak "$name must be 0 or 1" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $value or not $value =~ /\A[01]\z/
MC/DC50%1/2
ref $value or not $value =~ /\A[01]\z/
ref $value
not $value =~ /\A[01]\z/
Truth table66%2/3
A or not(B)
A= ref $valueB= not $value =~ /\A[01]\z/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | if ref($value) || $value !~ /\A[01]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | return 0 + $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 31 | ▶ | sub _constructor_args { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_constructor_args: called CC=4 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | return %{$_[0]} if @_ == 1 && ref($_[0]) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 31 | ▶ | croak "constructor arguments must be name/value pairs" if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 31 | return @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||