| 1 | package Net::Amazon::S3::ACL::Set; | ||||||||||||
| 2 | # ABSTRACT: Representation of explicit ACL | ||||||||||||
| 3 | 100 | $Net::Amazon::S3::ACL::Set::VERSION = '0.99'; | |||||||||||
| 4 | 100 | ▶ | use Moose 0.85; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 100 | ▶ | use MooseX::StrictConstructor 0.16; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 100 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 100 | ▶ | use Ref::Util (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 100 | ▶ | use Safe::Isa (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 100 | ▶ | use Net::Amazon::S3::Constants; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 100 | ▶ | use Net::Amazon::S3::ACL::Grantee::User; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 100 | ▶ | use Net::Amazon::S3::ACL::Grantee::Group; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 100 | ▶ | use Net::Amazon::S3::ACL::Grantee::Email; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | 100 | class_type 'Net::Amazon::S3::ACL::Set'; | |||||||||||
| 17 | |||||||||||||
| 18 | 100 | my %permission_map = ( | |||||||||||
| 19 | full_control => Net::Amazon::S3::Constants::HEADER_GRANT_FULL_CONTROL, | ||||||||||||
| 20 | read => Net::Amazon::S3::Constants::HEADER_GRANT_READ, | ||||||||||||
| 21 | read_acp => Net::Amazon::S3::Constants::HEADER_GRANT_READ_ACP, | ||||||||||||
| 22 | write => Net::Amazon::S3::Constants::HEADER_GRANT_WRITE, | ||||||||||||
| 23 | write_acp => Net::Amazon::S3::Constants::HEADER_GRANT_WRITE_ACP, | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | |||||||||||||
| 26 | 100 | my %grantees_map = ( | |||||||||||
| 27 | id => 'Net::Amazon::S3::ACL::Grantee::User', | ||||||||||||
| 28 | user => 'Net::Amazon::S3::ACL::Grantee::User', | ||||||||||||
| 29 | uri => 'Net::Amazon::S3::ACL::Grantee::Group', | ||||||||||||
| 30 | group => 'Net::Amazon::S3::ACL::Grantee::Group', | ||||||||||||
| 31 | email => 'Net::Amazon::S3::ACL::Grantee::Email', | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | has _grantees => ( | ||||||||||||
| 35 | is => 'ro', | ||||||||||||
| 36 | 15 | ▶ | default => sub { +{} }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 37 | 100 | ); | |||||||||||
| 38 | |||||||||||||
| 39 | sub build_headers { | ||||||||||||
| 40 | 30 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
build_headers: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 41 | |||||||||||||
| 42 | 30 | my %headers; | |||||||||||
| 43 | 30 | ▶ | while (my ($header, $grantees) = each %{ $self->_grantees }) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 61 | $headers{$header} = join ', ', map $_->format_for_header, @$grantees; | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 30 | %headers; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | sub grant_full_control { | ||||||||||||
| 51 | 1 | ▶ | my ($self, @grantees) = @_; | ||||||||||
|
Subroutine
grant_full_control: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 52 | |||||||||||||
| 53 | 1 | $self->_grant (full_control => @grantees); | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | sub grant_read { | ||||||||||||
| 57 | 15 | ▶ | my ($self, @grantees) = @_; | ||||||||||
|
Subroutine
grant_read: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 58 | |||||||||||||
| 59 | 15 | $self->_grant (read => @grantees); | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | sub grant_read_acp { | ||||||||||||
| 63 | 0 | ▶ | my ($self, @grantees) = @_; | ||||||||||
|
Subroutine
grant_read_acp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 64 | |||||||||||||
| 65 | 0 | $self->_grant (read_acp => @grantees); | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | sub grant_write { | ||||||||||||
| 69 | 16 | ▶ | my ($self, @grantees) = @_; | ||||||||||
|
Subroutine
grant_write: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 70 | |||||||||||||
| 71 | 16 | $self->_grant (write => @grantees); | |||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | sub grant_write_acp { | ||||||||||||
| 75 | 0 | ▶ | my ($self, @grantees) = @_; | ||||||||||
|
Subroutine
grant_write_acp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 76 | |||||||||||||
| 77 | 0 | $self->_grant (write_acp => @grantees); | |||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | sub _grant { | ||||||||||||
| 81 | 32 | ▶ | my ($self, $permission, @grantees) = @_; | ||||||||||
|
Subroutine
_grant: called CC=10 SCAR=23.6
| |||||||||||||
| 82 | 32 | ▶ | $self = $self->new unless ref $self; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | |||||||||||||
| 84 | 32 | my $key = lc $permission; | |||||||||||
| 85 | 32 | $key =~ tr/-/_/; | |||||||||||
| 86 | |||||||||||||
| 87 | die "Unknown permission $permission" | ||||||||||||
| 88 | 32 | ▶ | unless exists $permission_map{$key}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | |||||||||||||
| 90 | 32 | ▶ | return unless @grantees; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | |||||||||||||
| 92 | 32 | ▶ | my $list = $self->_grantees->{$permission_map{$key}} ||= []; | ||||||||||
|
Condition100%2/2
$self->_grantees->{$permission_map{$key}} ||= []
MC/DC100%1/1
$self->_grantees->{$permission_map{$key}} ||= []
$self->_grantees->{$permission_map{$key}}
Truth table100%2/2
A
A= $self->_grantees->{$permission_map{$key}}
| |||||||||||||
| 93 | 32 | ▶ | while (@grantees) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | 49 | my $type = shift @grantees; | |||||||||||
| 95 | |||||||||||||
| 96 | 49 | ▶ | if ($type->$Safe::Isa::_isa ('Net::Amazon::S3::ACL::Grantee')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | 2 | push @{ $list }, $type; | |||||||||||
| 98 | 2 | next; | |||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | die "Unknown grantee type $type" | ||||||||||||
| 102 | 47 | ▶ | unless exists $grantees_map{$type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 103 | |||||||||||||
| 104 | 47 | ▶ | die "Grantee type $type requires one argument" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | unless @grantees; | ||||||||||||
| 106 | |||||||||||||
| 107 | 47 | my @grantee = (shift @grantees); | |||||||||||
| 108 | 47 | ▶ | @grantees = @{ $grantee[0] } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 109 | if Ref::Util::is_plain_arrayref ($grantee[0]); | ||||||||||||
| 110 | |||||||||||||
| 111 | 47 | push @{ $list }, map $grantees_map{$type}->new ($_), @grantee; | |||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | 32 | return $self; | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | 100 | 1; | |||||||||||
| 118 | |||||||||||||
| 119 | __END__ | ||||||||||||
| 120 | |||||||||||||
| 121 | =pod | ||||||||||||
| 122 | |||||||||||||
| 123 | =encoding UTF-8 | ||||||||||||
| 124 | |||||||||||||
| 125 | =head1 NAME | ||||||||||||
| 126 | |||||||||||||
| 127 | Net::Amazon::S3::ACL::Set - Representation of explicit ACL | ||||||||||||
| 128 | |||||||||||||
| 129 | =head1 VERSION | ||||||||||||
| 130 | |||||||||||||
| 131 | version 0.99 | ||||||||||||
| 132 | |||||||||||||
| 133 | =head1 SYNOPSIS | ||||||||||||
| 134 | |||||||||||||
| 135 | use Net::Amazon::S3::ACL; | ||||||||||||
| 136 | |||||||||||||
| 137 | $acl = Net::Amazon::S3::ACL->new | ||||||||||||
| 138 | ->grant_full_control ( | ||||||||||||
| 139 | id => 11112222333, | ||||||||||||
| 140 | id => 444455556666, | ||||||||||||
| 141 | uri => 'predefined group uri', | ||||||||||||
| 142 | email => 'email-address', | ||||||||||||
| 143 | ) | ||||||||||||
| 144 | ->grant_write ( | ||||||||||||
| 145 | ... | ||||||||||||
| 146 | ) | ||||||||||||
| 147 | ; | ||||||||||||
| 148 | |||||||||||||
| 149 | =head1 DESCRIPTION | ||||||||||||
| 150 | |||||||||||||
| 151 | Class representing explicit Amazon S3 ACL configuration. | ||||||||||||
| 152 | |||||||||||||
| 153 | =head1 METHODS | ||||||||||||
| 154 | |||||||||||||
| 155 | =head2 new | ||||||||||||
| 156 | |||||||||||||
| 157 | Creates new instance. | ||||||||||||
| 158 | |||||||||||||
| 159 | =head2 grant_full_control (@grantees) | ||||||||||||
| 160 | |||||||||||||
| 161 | =head2 grant_read (@grantees) | ||||||||||||
| 162 | |||||||||||||
| 163 | =head2 grant_read_acp (@grantees) | ||||||||||||
| 164 | |||||||||||||
| 165 | =head2 grant_write (@grantees) | ||||||||||||
| 166 | |||||||||||||
| 167 | =head2 grant_write_acp (@grantees) | ||||||||||||
| 168 | |||||||||||||
| 169 | =head1 GRANTEES | ||||||||||||
| 170 | |||||||||||||
| 171 | See also L<"Who Is a Grantee?"|https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#specifying-grantee> | ||||||||||||
| 172 | in Amazon S3 documentation. | ||||||||||||
| 173 | |||||||||||||
| 174 | Each grant_* method accepts list of grantees either in key-value format or as an | ||||||||||||
| 175 | instance of C<Net::Amazon::S3::ACL::Grantee::*>. | ||||||||||||
| 176 | |||||||||||||
| 177 | =over | ||||||||||||
| 178 | |||||||||||||
| 179 | =item canonical user ID | ||||||||||||
| 180 | |||||||||||||
| 181 | ->grant_read ( | ||||||||||||
| 182 | id => 123, | ||||||||||||
| 183 | Net::Amazon::S3::ACL::Grantee::User->new (123), | ||||||||||||
| 184 | ) | ||||||||||||
| 185 | |||||||||||||
| 186 | =item predefined group uri | ||||||||||||
| 187 | |||||||||||||
| 188 | ->grant_read ( | ||||||||||||
| 189 | uri => 'http://...', | ||||||||||||
| 190 | Net::Amazon::S3::ACL::Grantee::Group->new ('http://...'), | ||||||||||||
| 191 | Net::Amazon::S3::ACL::Grantee::Group->ALL_USERS, | ||||||||||||
| 192 | ) | ||||||||||||
| 193 | |||||||||||||
| 194 | =item email address | ||||||||||||
| 195 | |||||||||||||
| 196 | ->grant_read ( | ||||||||||||
| 197 | email => 'foo@bar.baz', | ||||||||||||
| 198 | Net::Amazon::S3::ACL::Grantee::Email->new ('foo@bar.baz'), | ||||||||||||
| 199 | ); | ||||||||||||
| 200 | |||||||||||||
| 201 | =back | ||||||||||||
| 202 | |||||||||||||
| 203 | =head1 AUTHOR | ||||||||||||
| 204 | |||||||||||||
| 205 | Branislav Zahradník <barney@cpan.org> | ||||||||||||
| 206 | |||||||||||||
| 207 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 208 | |||||||||||||
| 209 | This module is part of L<Net::Amazon::S3>. | ||||||||||||
| 210 | |||||||||||||
| 211 | =head1 AUTHOR | ||||||||||||
| 212 | |||||||||||||
| 213 | Branislav Zahradník <barney@cpan.org> | ||||||||||||
| 214 | |||||||||||||
| 215 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 216 | |||||||||||||
| 217 | This software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník. | ||||||||||||
| 218 | |||||||||||||
| 219 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 220 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 221 | |||||||||||||
| 222 | =cut | ||||||||||||