Lite/Policies.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 51 CC 3 SCAR 14.6
CC
3
Cov
0%
restrict_bucket_access_to_ip
6.0
restrict_bucket_access_to_vpc
6.0
BEGIN
2.0
CRAP 4.3
1 package Amazon::S3::Lite::Policies;
2 use strict;
3 use warnings;
4  
5 use Role::Tiny;
6  
7 ########################################################################
8 sub restrict_bucket_access_to_ip {
9 ########################################################################
10 my ( $self, $bucket, $ip, $action ) = @_;
11  
12 die "ERROR: usage: restrict_bucket_to_ip(bucket, ip)\n"
13 if !$bucket || !$ip;
14  
15 $action //= 's3:*';
16  
17 $self->put_bucket_policy(
18 $bucket,
19 { Version => '2012-10-17',
20 Statement => [
21 { Sid => 'AllowAccessFromSpecificIP',
22 Effect => 'Allow',
23 Principal => q{*},
24 Action => $action,
25 Resource => "arn:aws:s3:::$bucket/*",
26 Condition => { IpAddress => { 'aws:SourceIp' => $ip } },
27 }
28 ],
29 }
30 );
31  
32 return;
33 }
34  
35 ########################################################################
36 sub restrict_bucket_access_to_vpc {
37 ########################################################################
38 my ( $self, $bucket, $vpc_id, $action ) = @_;
39  
40 die "ERROR: usage: restrict_bucket_access_to_vpc(bucket, vpc_id)\n"
41 if !$bucket || !$vpc_id;
42  
43 $action //= 's3:GetObject'; # read-only default — see note
44  
45 $self->put_bucket_policy(
46 $bucket,
47 { Version => '2012-10-17',
48 Statement => [
49 { Sid => 'AllowAccessFromVPC',
50 Effect => 'Allow',
51 Principal => q{*},
52 Action => $action,
53 Resource => [ "arn:aws:s3:::$bucket", "arn:aws:s3:::$bucket/*" ],
54 Condition => { StringEquals => { 'aws:SourceVpc' => $vpc_id } },
55 },
56 ],
57 }
58 );
59  
60 return;
61 }
62  
63 1;