line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::S3::ACL::Grant; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5439
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
77
|
|
6
|
1
|
|
|
1
|
|
5
|
use English qw( -no_match_vars ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
501
|
use Scalar::Util qw( blessed ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
121
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use base qw(Class::Accessor::Fast); |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
1076
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw( key permissions )); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @Classes; |
13
|
|
|
|
|
|
|
BEGIN { |
14
|
1
|
|
|
1
|
|
5004
|
@Classes = qw( Email URI ID ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Module implementation here |
18
|
|
|
|
|
|
|
sub new { |
19
|
0
|
|
|
0
|
1
|
|
my $package = shift; |
20
|
0
|
|
0
|
|
|
|
my $params = shift || {}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $self = $package->SUPER::new($params); |
23
|
0
|
0
|
0
|
|
|
|
if ($params->{xpc} && $params->{node}) { |
|
|
0
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$self->parse($params->{xpc}, $params->{node}); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif ($params->{target}) { |
27
|
0
|
|
|
|
|
|
$self->populate_from_target($params->{target}); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$self->_set_key(); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $permissions = $self->permissions(); |
33
|
0
|
|
|
|
|
|
$self->permissions([]); |
34
|
0
|
0
|
|
|
|
|
$self->add_permissions($permissions) if $permissions; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $self; |
37
|
|
|
|
|
|
|
} ## end sub new |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my %permission_normalisation_for = ( |
40
|
|
|
|
|
|
|
WRITE => 'WRITE', |
41
|
|
|
|
|
|
|
W => 'WRITE', |
42
|
|
|
|
|
|
|
'>' => 'WRITE', |
43
|
|
|
|
|
|
|
READ => 'READ', |
44
|
|
|
|
|
|
|
R => 'READ', |
45
|
|
|
|
|
|
|
'<' => 'READ', |
46
|
|
|
|
|
|
|
FULL_CONTROL => 'FULL_CONTROL', |
47
|
|
|
|
|
|
|
'FULL-CONTROL' => 'FULL_CONTROL', |
48
|
|
|
|
|
|
|
FULL => 'FULL_CONTROL', |
49
|
|
|
|
|
|
|
F => 'FULL_CONTROL', |
50
|
|
|
|
|
|
|
'*' => 'FULL_CONTROL', |
51
|
|
|
|
|
|
|
'WRITE_ACP' => 'WRITE_ACP', |
52
|
|
|
|
|
|
|
'WP' => 'WRITE_ACP', |
53
|
|
|
|
|
|
|
'WRITE-ACP' => 'WRITE_ACP', |
54
|
|
|
|
|
|
|
'READ_ACP' => 'READ_ACP', |
55
|
|
|
|
|
|
|
'RP' => 'READ_ACP', |
56
|
|
|
|
|
|
|
'READ-ACP' => 'READ_ACP', |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub add_permissions { |
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
my @input = grep {defined} ref($_[0]) ? @{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my @permissions = @{$self->permissions()}; |
|
0
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
for my $new_perm (@input) { |
65
|
0
|
|
|
|
|
|
$new_perm = uc $new_perm; |
66
|
0
|
0
|
|
|
|
|
croak "unknown permission $new_perm" |
67
|
|
|
|
|
|
|
unless exists $permission_normalisation_for{$new_perm}; |
68
|
0
|
|
|
|
|
|
push @permissions, $permission_normalisation_for{$new_perm}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my %flag; |
72
|
0
|
|
|
|
|
|
@permissions = grep { ! $flag{$_}++ } @permissions; |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$self->permissions(\@permissions); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub delete_permissions { |
79
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
my @input = ref($_[0]) ? @{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
my %flag = map { |
83
|
0
|
|
|
|
|
|
croak "unknown permission $_" |
84
|
|
|
|
|
|
|
unless exists $permission_normalisation_for{$_}; |
85
|
0
|
|
|
|
|
|
$permission_normalisation_for{$_} => 1; |
86
|
|
|
|
|
|
|
} @input; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my @permissions = grep { ! $flag{$_}++ } @{$self->permissions()}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$self->permissions(\@permissions); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return $self; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
1
|
|
sub is_valid { return scalar(@{$_[0]->permissions()}) > 0; } |
|
0
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub class_for { |
97
|
0
|
|
|
0
|
1
|
|
my ($package, $name) = @_; |
98
|
0
|
|
0
|
|
|
|
$package = ref($package) || $package; |
99
|
0
|
|
|
|
|
|
return join '::', $package, $name; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub create { |
103
|
0
|
|
|
0
|
1
|
|
my $package = shift; |
104
|
0
|
|
0
|
|
|
|
my $params = shift || {}; |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
0
|
|
|
|
croak "not enough parameters to create a grant" |
|
|
|
0
|
|
|
|
|
107
|
|
|
|
|
|
|
unless ($params->{xpc} && $params->{node}) |
108
|
|
|
|
|
|
|
|| $params->{target}; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
for my $type (@Classes) { |
111
|
0
|
|
|
|
|
|
my $class = $package->class_for($type); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $sub_new = $class->can('new'); |
114
|
0
|
0
|
|
|
|
|
if (! $sub_new) { |
115
|
0
|
0
|
|
|
|
|
eval "require $class" or die "no package $class available"; |
116
|
0
|
0
|
|
|
|
|
$sub_new = $class->can('new') |
117
|
|
|
|
|
|
|
or die "package $class does not support 'new'"; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
my $self; |
121
|
0
|
0
|
|
|
|
|
$self = eval { $class->$sub_new($params) } |
|
0
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
and return $self; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
require Data::Dumper; |
126
|
0
|
|
|
|
|
|
croak 'no suitable subclass found to handle input data: ', |
127
|
|
|
|
|
|
|
Data::Dumper::Dumper($params); |
128
|
|
|
|
|
|
|
} ## end sub new |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub canonical { |
132
|
0
|
|
|
0
|
1
|
|
my ($pack, $target, $item) = @_; |
133
|
|
|
|
|
|
|
|
134
|
0
|
0
|
|
|
|
|
return $item if blessed $item; |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
$target = $target->key() if blessed $target; |
137
|
0
|
|
|
|
|
|
$item = $pack->create( |
138
|
|
|
|
|
|
|
{ |
139
|
|
|
|
|
|
|
target => $target, |
140
|
|
|
|
|
|
|
permissions => $item, |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
return $item; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub parse { |
148
|
0
|
|
|
0
|
1
|
|
my ($self, $xpc, $node) = @_; |
149
|
0
|
|
|
|
|
|
$self->parse_grantee($xpc, $node); |
150
|
0
|
|
|
|
|
|
my @permissions = |
151
|
0
|
|
|
|
|
|
map { $_->to_literal() } $xpc->findnodes('.//s3:Permission', $node); |
152
|
0
|
|
|
|
|
|
$self->permissions(\@permissions); |
153
|
0
|
|
|
|
|
|
return $self; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub stringify { |
157
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
158
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
|
return '' unless $self->is_valid(); |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
(my $grantee = $self->stringify_grantee()) =~ s/^/ /mxsg; |
162
|
|
|
|
|
|
|
return join "\n", map { |
163
|
0
|
|
|
|
|
|
; |
164
|
0
|
|
|
|
|
|
"\n$grantee $_\n"; |
165
|
0
|
|
|
|
|
|
} @{$self->permissions()}; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
169
|
|
|
|
|
|
|
__END__ |