lib/WWW/Hetzner/Cloud/Firewall.pm

filter: Statementstmt 38.4% 20 / 52 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 30.7% 4 / 13 Podpod 100% 7 / 7 totaltotal 34.4% 31 / 90 CC 9 SCAR 19.5
CC
9
Cov
29%
refresh
20.0
update
6.0
delete
6.0
CRAP 7.0
« lib/WWW/Hetzner/CLI/Cmd/FloatingIp/Cmd/Create.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Certificates.pm »
1 package WWW::Hetzner::Cloud::Firewall;
2 # ABSTRACT: Hetzner Cloud Firewall object
3  
4 25 our $VERSION = '0.100';
5  
6 25 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 25 has _client => (
12 is => 'ro',
13 required => 1,
14 weak_ref => 1,
15 init_arg => 'client',
16 );
17  
18 25 has id => ( is => 'ro' );
19  
20  
21 25 has name => ( is => 'rw' );
22  
23  
24 0 ▶has rules => ( is => 'rw', default => sub { [] } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
25  
26  
27 0 ▶has applied_to => ( is => 'ro', default => sub { [] } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
28  
29  
30 0 ▶has labels => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
31  
32  
33 25 has created => ( is => 'ro' );
34  
35  
36 # Actions
37 sub update {
38 0 ▶ my ($self) = @_;
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
39 0 ▶ croak "Cannot update firewall without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
40  
41 0 my $result = $self->_client->put("/firewalls/" . $self->id, {
42 name => $self->name,
43 labels => $self->labels,
44 });
45 0 return $self;
46 }
47  
48  
49 sub delete {
50 0 ▶ my ($self) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
51 0 ▶ croak "Cannot delete firewall without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
52  
53 0 $self->_client->delete("/firewalls/" . $self->id);
54 0 return 1;
55 }
56  
57  
58 sub set_rules {
59 0 ▶ my ($self, @rules) = @_;
Subroutine set_rules: not called CC=2 SCAR=17.9
Pod documented
60 0 ▶ croak "Cannot modify firewall without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
61  
62 0 $self->_client->post("/firewalls/" . $self->id . "/actions/set_rules", {
63 rules => \@rules,
64 });
65 0 $self->rules(\@rules);
66 0 return $self;
67 }
68  
69  
70 sub apply_to_resources {
71 0 ▶ my ($self, @resources) = @_;
Subroutine apply_to_resources: not called CC=2 SCAR=17.9
Pod documented
72 0 ▶ croak "Cannot modify firewall without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
73  
74 0 $self->_client->post("/firewalls/" . $self->id . "/actions/apply_to_resources", {
75 apply_to => \@resources,
76 });
77 0 return $self;
78 }
79  
80  
81 sub remove_from_resources {
82 0 ▶ my ($self, @resources) = @_;
Subroutine remove_from_resources: not called CC=2 SCAR=17.9
Pod documented
83 0 ▶ croak "Cannot modify firewall without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
84  
85 0 $self->_client->post("/firewalls/" . $self->id . "/actions/remove_from_resources", {
86 remove_from => \@resources,
87 });
88 0 return $self;
89 }
90  
91  
92 sub refresh {
93 0 ▶ my ($self) = @_;
Subroutine refresh: not called CC=4 SCAR=30.0
Pod documented
94 0 ▶ croak "Cannot refresh firewall without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
95  
96 0 my $result = $self->_client->get("/firewalls/" . $self->id);
97 0 my $data = $result->{firewall};
98  
99 0 $self->name($data->{name});
100 0 ▶ $self->rules($data->{rules} // []);
Condition0%0/2
$data->{"rules"} // []
l!l
00
MC/DC0%0/1
$data->{"rules"} // []
$data->{"rules"}
Truth table0%0/2
A
A= $data->{"rules"}
Aresult
11
00
101 0 ▶ $self->labels($data->{labels} // {});
Condition0%0/2
$data->{"labels"} // {}
l!l
00
MC/DC0%0/1
$data->{"labels"} // {}
$data->{"labels"}
Truth table0%0/2
A
A= $data->{"labels"}
Aresult
11
00
102  
103 0 return $self;
104 }
105  
106  
107 sub data {
108 1 ▶ my ($self) = @_;
Subroutine data: called CC=1 SCAR=0.0
Pod documented
109 return {
110 1 id => $self->id,
111 name => $self->name,
112 rules => $self->rules,
113 applied_to => $self->applied_to,
114 labels => $self->labels,
115 created => $self->created,
116 };
117 }
118  
119  
120  
121 25 1.
122  
123 __END__
« lib/WWW/Hetzner/CLI/Cmd/FloatingIp/Cmd/Create.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Certificates.pm »