blib/lib/VM/EC2/REST/network_acl.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 63 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 161 CC 8 SCAR 27.2
CC
8
Cov
0%
create_network_acl_entry
30.0
replace_network_acl_entry
20.0
describe_network_acls
2.0
CRAP 15.2
1 package VM::EC2::REST::network_acl;
2  
3 use strict;
4 use VM::EC2 ''; # important not to import anything!
5 package VM::EC2; # add methods to VM::EC2
6  
7 VM::EC2::Dispatch->register(
8 CreateNetworkAcl => 'fetch_one,networkAcl,VM::EC2::VPC::NetworkAcl',
9 CreateNetworkAclEntry => 'boolean',
10 DeleteNetworkAcl => 'boolean',
11 DeleteNetworkAclEntry => 'boolean',
12 DescribeNetworkAcls => 'fetch_items,networkAclSet,VM::EC2::VPC::NetworkAcl',
13 ReplaceNetworkAclAssociation => sub { shift->{newAssociationId} },
14 ReplaceNetworkAclEntry => 'boolean',
15 );
16  
17 my $VEP = 'VM::EC2::ParmParser';
18  
19 =head1 NAME VM::EC2::REST::network_acl
20  
21 =head1 SYNOPSIS
22  
23 use VM::EC2 ':vpc'
24  
25 =head1 METHODS
26  
27 These methods allow you to create and manipulate VPC Network Access
28 Control Lists.
29  
30 Implemented:
31 CreateNetworkAcl
32 CreateNetworkAclEntry
33 DeleteNetworkAcl
34 DeleteNetworkAclEntry
35 DescribeNetworkAcls
36 ReplaceNetworkAclAssociation
37 ReplaceNetworkAclEntry
38  
39 Unimplemented:
40 (none)
41  
42 =head2 @acls = $ec2->describe_network_acls(-network_acl_id=>\@ids, -filter=>\%filters)
43  
44 =head2 @acls = $ec2->describe_network_acls(\@network_acl_ids)
45  
46 =head2 @acls = $ec2->describe_network_acls(%filters)
47  
48 Provides information about network ACLs.
49  
50 Returns a series of L<VM::EC2::VPC::NetworkAcl> objects.
51  
52 Optional parameters are:
53  
54 -network_acl_id -- ID of the network ACL(s) to return information on.
55 This can be a string scalar, or an arrayref.
56  
57 -filter -- Tags and other filters to apply.
58  
59 The filter argument is a hashreference in which the keys are the
60 filter names, and the values are the match strings. Some filters
61 accept wildcards.
62  
63 There are a number of filters, which are listed in full at
64 http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeNetworkAcls.html
65  
66 Here is a alpha-sorted list of filter names:
67 association.association-id, association.network-acl-id,
68 association.subnet-id, default, entry.cidr, entry.egress,
69 entry.icmp.code, entry.icmp.type, entry.port-range.from,
70 entry.port-range.to, entry.protocol, entry.rule-action,
71 entry.rule-number, network-acl-id, tag-key, tag-value,
72 tag:key, vpc-id
73  
74 =cut
75  
76 sub describe_network_acls {
77 my $self = shift;
78 my %args = $VEP->args(-network_acl_id,@_);
79 my @params = $VEP->format_parms(\%args,
80 {
81 list_parm => 'NetworkAclId',
82 filter_parm => 'Filter',
83 });
84 return $self->call('DescribeNetworkAcls',@params);
85 }
86  
87 =head2 $acl = $ec2->create_network_acl(-vpc_id=>$vpc_id)
88  
89 =head2 $acl = $ec2->create_network_acl($vpc_id)
90  
91 Creates a new network ACL in a VPC. Network ACLs provide an optional layer of
92 security (on top of security groups) for the instances in a VPC.
93  
94 Arguments:
95  
96 -vpc_id -- The VPC ID to create the ACL in
97  
98 Retuns a VM::EC2::VPC::NetworkAcl object on success.
99  
100 =cut
101  
102 sub create_network_acl {
103 my $self = shift;
104 my %args = $VEP->args(-vpc_id,@_);
105 $args{-vpc_id} or
106 croak "create_network_acl(): -vpc_id argument missing";
107 my @params = $VEP->format_parms(\%args,
108 {
109 single_parm => 'VpcId',
110 });
111 return $self->call('CreateNetworkAcl',@params);
112 }
113  
114 =head2 $boolean = $ec2->delete_network_acl(-network_acl_id=>$id)
115  
116 =head2 $boolean = $ec2->delete_network_acl($id)
117  
118 Deletes a network ACL from a VPC. The ACL must not have any subnets associated
119 with it. The default network ACL cannot be deleted.
120  
121 Arguments:
122  
123 -network_acl_id -- The ID of the network ACL to delete
124  
125 Returns true on successful deletion.
126  
127 =cut
128  
129 sub delete_network_acl {
130 my $self = shift;
131 my %args = $VEP->args(-network_acl_id,@_);
132 my @params = $VEP->format_parms(\%args,
133 {
134 single_parm => 'NetworkAclId',
135 });
136 return $self->call('DeleteNetworkAcl',@params);
137 }
138  
139 =head2 $boolean = $ec2->create_network_acl_entry(%args)
140  
141 Creates an entry (i.e., rule) in a network ACL with the rule number you
142 specified. Each network ACL has a set of numbered ingress rules and a
143 separate set of numbered egress rules. When determining whether a packet
144 should be allowed in or out of a subnet associated with the ACL, Amazon
145 VPC processes the entries in the ACL according to the rule numbers, in
146 ascending order.
147  
148 Arguments:
149  
150 -network_acl_id -- ID of the ACL where the entry will be created
151 (Required)
152 -rule_number -- Rule number to assign to the entry (e.g., 100).
153 ACL entries are processed in ascending order by
154 rule number. Positive integer from 1 to 32766.
155 (Required)
156 -protocol -- The IP protocol the rule applies to. You can use
157 -1 to mean all protocols. See
158 http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
159 for a list of protocol numbers. (Required)
160 -rule_action -- Indicates whether to allow or deny traffic that
161 matches the rule. allow | deny (Required)
162 -egress -- Indicates whether this rule applies to egress
163 traffic from the subnet (true) or ingress traffic
164 to the subnet (false). Default is false.
165 -cidr_block -- The CIDR range to allow or deny, in CIDR notation
166 (e.g., 172.16.0.0/24). (Required)
167 -icmp_code -- For the ICMP protocol, the ICMP code. You can use
168 -1 to specify all ICMP codes for the given ICMP
169 type. Required if specifying 1 (ICMP) for protocol.
170 -icmp_type -- For the ICMP protocol, the ICMP type. You can use
171 -1 to specify all ICMP types. Required if
172 specifying 1 (ICMP) for the protocol
173 -port_range_from -- The first port in the range. Required if specifying
174 6 (TCP) or 17 (UDP) for the protocol.
175 -port_range_to -- The last port in the range. Required if specifying
176 6 (TCP) or 17 (UDP) for the protocol.
177  
178 -port_from -- Alias for -port_range_from
179  
180 -port_to -- Alias for -port_range_to
181  
182 Returns true on successful creation.
183  
184 =cut
185  
186 sub create_network_acl_entry {
187 my $self = shift;
188 my %args = @_;
189 $args{-network_acl_id} or
190 croak "create_network_acl_entry(): -network_acl_id argument missing";
191 $args{-rule_number} or
192 croak "create_network_acl_entry(): -rule_number argument missing";
193 defined $args{-protocol} or
194 croak "create_network_acl_entry(): -protocol argument missing";
195 $args{-rule_action} or
196 croak "create_network_acl_entry(): -rule_action argument missing";
197 $args{-cidr_block} or
198 croak "create_network_acl_entry(): -cidr_block argument missing";
199 $args{-port_range_from} ||= $args{-port_from};
200 $args{-port_range_to} ||= $args{-port_to};
201 if ($args{-protocol} == 1) {
202 defined $args{-icmp_type} && defined $args{-icmp_code} or
203 croak "create_network_acl_entry(): -icmp_type or -icmp_code argument missing";
204 }
205 elsif ($args{-protocol} == 6 || $args{-protocol} == 17) {
206 defined $args{-port_range_from} or
207 croak "create_network_acl_entry(): -port_range_from argument missing";
208 $args{-port_range_to} = $args{-port_range_from} if ! defined $args{-port_range_to};
209 }
210 $args{-egress} ||= $args{-egress} ? 'true' : 'false';
211 my @params = $VEP->format_parms(\%args,
212 {
213 single_parm => [qw(NetworkAclId RuleNumber Protocol
214 RuleAction Egress CidrBlock Icmp.Code
215 Icmp.Type PortRange.From PortRange.To)],
216 });
217 return $self->call('CreateNetworkAclEntry',@params);
218 }
219  
220 =head2 $success = $ec2->delete_network_acl_entry(-network_acl_id=>$id,
221 -rule_number =>$int,
222 -egress =>$bool)
223  
224 Deletes an ingress or egress entry (i.e., rule) from a network ACL.
225  
226 Arguments:
227  
228 -network_acl_id -- ID of the ACL where the entry will be created
229  
230 -rule_number -- Rule number of the entry (e.g., 100).
231  
232 Optional arguments:
233  
234 -egress -- Whether the rule to delete is an egress rule (true) or ingress
235 rule (false). Default is false.
236  
237 Returns true on successful deletion.
238  
239 =cut
240  
241 sub delete_network_acl_entry {
242 my $self = shift;
243 my %args = @_;
244 $args{-network_acl_id} or
245 croak "delete_network_acl_entry(): -network_acl_id argument missing";
246 $args{-rule_number} or
247 croak "delete_network_acl_entry(): -rule_number argument missing";
248 my @params = $VEP->format_parms(\%args,
249 {
250 single_parm => [qw(NetworkAclId RuleNumber Egress)],
251 });
252 return $self->call('DeleteNetworkAclEntry',@params);
253 }
254  
255 =head2 $assoc_id = $ec2->replace_network_acl_association(-association_id=>$assoc_id,
256 -network_acl_id=>$id)
257  
258 Changes which network ACL a subnet is associated with. By default when you
259 create a subnet, it's automatically associated with the default network ACL.
260  
261 Arguments:
262  
263 -association_id -- The ID of the association to replace
264  
265 -network_acl_id -- The ID of the network ACL to associated the subnet with
266  
267 Returns the new association ID.
268  
269 =cut
270  
271 sub replace_network_acl_association {
272 my $self = shift;
273 my %args = @_;
274 $args{-association_id} or
275 croak "replace_network_acl_association(): -association_id argument missing";
276 $args{-network_acl_id} or
277 croak "replace_network_acl_association(): -network_acl_id argument missing";
278 my @params = $VEP->format_parms(\%args,
279 {
280 single_parm => [qw(AssociationId NetworkAclId)],
281 });
282 return $self->call('ReplaceNetworkAclAssociation',@params);
283 }
284  
285 =head2 $success = $ec2->replace_network_acl_entry(%args)
286  
287 Replaces an entry (i.e., rule) in a network ACL.
288  
289 Arguments:
290  
291 -network_acl_id -- ID of the ACL where the entry will be created
292 (Required)
293 -rule_number -- Rule number of the entry to replace. (Required)
294 -protocol -- The IP protocol the rule applies to. You can use
295 -1 to mean all protocols. See
296 http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
297 for a list of protocol numbers. (Required)
298 -rule_action -- Indicates whether to allow or deny traffic that
299 matches the rule. allow | deny (Required)
300 -egress -- Indicates whether this rule applies to egress
301 traffic from the subnet (true) or ingress traffic
302 to the subnet (false). Default is false.
303 -cidr_block -- The CIDR range to allow or deny, in CIDR notation
304 (e.g., 172.16.0.0/24). (Required)
305 -icmp_code -- For the ICMP protocol, the ICMP code. You can use
306 -1 to specify all ICMP codes for the given ICMP
307 type. Required if specifying 1 (ICMP) for protocol.
308 -icmp_type -- For the ICMP protocol, the ICMP type. You can use
309 -1 to specify all ICMP types. Required if
310 specifying 1 (ICMP) for the protocol
311 -port_range_from -- The first port in the range. Required if specifying
312 6 (TCP) or 17 (UDP) for the protocol.
313 -port_range_to -- The last port in the range. Only required if
314 specifying 6 (TCP) or 17 (UDP) for the protocol and
315 is a different port than -port_range_from.
316  
317 -port_from -- Alias for -port_range_from
318  
319 -port_to -- Alias for -port_range_from
320  
321 Returns true on successful replacement.
322  
323 =cut
324  
325 sub replace_network_acl_entry {
326 my $self = shift;
327 my %args = @_;
328 $args{-network_acl_id} or
329 croak "replace_network_acl_entry(): -network_acl_id argument missing";
330 $args{-rule_number} or
331 croak "replace_network_acl_entry(): -rule_number argument missing";
332 $args{-protocol} or
333 croak "replace_network_acl_entry(): -protocol argument missing";
334 $args{-rule_action} or
335 croak "replace_network_acl_entry(): -rule_action argument missing";
336 $args{-port_range_from} ||= $args{-port_from};
337 $args{-port_range_to} ||= $args{-port_to};
338 if ($args{-protocol} == 1) {
339 defined $args{-icmp_type} && defined $args{-icmp_code} or
340 croak "replace_network_acl_entry(): -icmp_type or -icmp_code argument missing";
341 }
342 elsif ($args{-protocol} == 6 || $args{-protocol} == 17) {
343 defined $args{-port_range_from} or
344 croak "create_network_acl_entry(): -port_range_from argument missing";
345 $args{-port_range_to} = $args{-port_range_from} if ! defined $args{-port_range_to};
346 }
347 my @params = $VEP->format_parms(\%args,
348 {
349 single_parm => [qw(NetworkAclId RuleNumber Protocol
350 RuleAction Egress CidrBlock Icmp.Code
351 Icmp.Type PortRange.From PortRange.To)],
352 });
353 return $self->call('ReplaceNetworkAclEntry',@params);
354 }
355  
356 =head1 SEE ALSO
357  
358 L<VM::EC2>
359  
360 =head1 AUTHOR
361  
362 Lance Kinley E<lt>lkinley@loyaltymethods.comE<gt>.
363 Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
364  
365 Copyright (c) 2012 Loyalty Methods, Inc.
366 Copyright (c) 2012 Ontario Institute for Cancer Research
367  
368 This package and its accompanying libraries is free software; you can
369 redistribute it and/or modify it under the terms of the GPL (either
370 version 1, or at your option, any later version) or the Artistic
371 License 2.0. Refer to LICENSE for the full license text. In addition,
372 please see DISCLAIMER.txt for disclaimers of warranty.
373  
374 =cut
375  
376 1;