lib/WWW/Hetzner/CLI/Cmd/Firewall/Cmd/Describe.pm

filter: Statementstmt 90.3% 47 / 52 Branchbran 45.0% 9 / 20 Conditioncond 34.7% 8 / 23 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 60.0% 69 / 115 CC 23 SCAR 38.1
CC
23
Cov
67%
execute
52.7
BEGIN
1.0
BEGIN
1.0
CRAP 45.0
↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Create.pm »
1 package WWW::Hetzner::CLI::Cmd::Firewall::Cmd::Describe;
2 # ABSTRACT: Describe a firewall
3  
4 1 our $VERSION = '0.102';
5  
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooX::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MooX::Options protect_argv => 0, usage_string => 'USAGE: hcloud.pl firewall describe <id>';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use JSON::MaybeXS qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub execute {
Subroutine execute: called CC=23 SCAR=39.6
Pod undocumented
12 1 my ($self, $args, $chain) = @_;
13 1 ▶ my $id = $args->[0] or die "Usage: hcloud.pl firewall describe <id>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $id = $args->[0] or die "Usage: hcloud.pl firewall describe <id>\n" 1 0 1
14  
15 1 my $main = $chain->[0];
16 1 my $cloud = $main->cloud;
17  
18 1 my $fw = $cloud->firewalls->get($id);
19  
20 1 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 0 1 1
21 0 print encode_json($fw->data), "\n";
22 0 return;
23 }
24  
25 1 printf "ID: %s\n", $fw->id;
26 1 printf "Name: %s\n", $fw->name;
27 1 ▶ printf "Created: %s\n", $fw->created // '-';
Condition50%1/2
$fw->created // "-"
l!l
10
MC/DC0%0/1
$fw->created // "-"
$fw->created
Truth table50%1/2
A
A= $fw->created
Aresult
11
00
28  
29 1 my $rules = $fw->rules;
30 1 ▶ if ($rules && @$rules) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rules and @$rules) 1 0 1
Condition33%1/3
$rules and @$rules
!ll&&!rl&&r
001
MC/DC0%0/2
$rules and @$rules
$rules @$rules
Truth table33%1/3
A and B
A= $rulesB= @$rules
ABresult
0X0
100
111
31 1 print "\nRules:\n";
32 1 for my $r (@$rules) {
33 2 ▶ my $port = $r->{port} // 'any';
Condition50%1/2
$r->{"port"} // "any"
l!l
20
MC/DC0%0/1
$r->{"port"} // "any"
$r->{"port"}
Truth table50%1/2
A
A= $r->{"port"}
Aresult
11
00
34 2 ▶ my $proto = $r->{protocol} // 'any';
Condition50%1/2
$r->{"protocol"} // "any"
l!l
20
MC/DC0%0/1
$r->{"protocol"} // "any"
$r->{"protocol"}
Truth table50%1/2
A
A= $r->{"protocol"}
Aresult
11
00
35 2 ▶ my $dir = $r->{direction} // 'in';
Condition50%1/2
$r->{"direction"} // "in"
l!l
20
MC/DC0%0/1
$r->{"direction"} // "in"
$r->{"direction"}
Truth table50%1/2
A
A= $r->{"direction"}
Aresult
11
00
36 2 ▶ my $sources = $r->{source_ips} ? join(', ', @{$r->{source_ips}}) : 'any';
Branch: 1 branch
BranchTrueFalseTotal
$r->{'source_ips'} ? : 2 0 2
37 0 ▶ my $dests = $r->{destination_ips} ? join(', ', @{$r->{destination_ips}}) : 'any';
Branch: 1 branch
BranchTrueFalseTotal
$r->{'destination_ips'} ? : 0 2 2
38  
39 2 ▶ if ($dir eq 'in') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq 'in') { } 2 0 2
40 2 printf " - %s %s/%s from %s\n", $dir, $proto, $port, $sources;
41 } else {
42 0 printf " - %s %s/%s to %s\n", $dir, $proto, $port, $dests;
43 }
44 }
45 }
46  
47 1 my $applied = $fw->applied_to;
48 1 ▶ if ($applied && @$applied) {
Branch: 1 branch
BranchTrueFalseTotal
if ($applied and @$applied) 1 0 1
Condition33%1/3
$applied and @$applied
!ll&&!rl&&r
001
MC/DC0%0/2
$applied and @$applied
$applied @$applied
Truth table33%1/3
A and B
A= $appliedB= @$applied
ABresult
0X0
100
111
49 1 print "\nApplied to:\n";
50 1 for my $a (@$applied) {
51 1 my $type = $a->{type};
52 1 ▶ if ($type eq 'server' && $a->{server}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'server' and $a->{'server'}) { } 1 0 1
elsif ($type eq 'label_selector' and $a->{'label_selector'}) { } 0 0 0
Condition33%1/3
$type eq "server" and $a->{"server"}
!ll&&!rl&&r
001
MC/DC0%0/2
$type eq "server" and $a->{"server"}
$type eq "server" $a->{"server"}
Truth table33%1/3
A and B
A= $type eq "server"B= $a->{"server"}
ABresult
0X0
100
111
53 1 printf " - Server %d\n", $a->{server}{id};
54 ▶ } elsif ($type eq 'label_selector' && $a->{label_selector}) {
Condition0%0/3
$type eq "label_selector" and $a->{"label_selector"}
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "label_selector" and $a->{"label_selector"}
$type eq "label_selector" $a->{"label_selector"}
Truth table0%0/3
A and B
A= $type eq "label_selector"B= $a->{"label_selector"}
ABresult
0X0
100
111
55 0 printf " - Label: %s\n", $a->{label_selector}{selector};
56 }
57 }
58 }
59  
60 1 my $labels = $fw->labels;
61 1 ▶ if ($labels && %$labels) {
Branch: 1 branch
BranchTrueFalseTotal
if ($labels and %$labels) 1 0 1
Condition33%1/3
$labels and %$labels
!ll&&!rl&&r
001
MC/DC0%0/2
$labels and %$labels
$labels %$labels
Truth table33%1/3
A and B
A= $labelsB= %$labels
ABresult
0X0
100
111
62 1 print "\nLabels:\n";
63 1 for my $k (sort keys %$labels) {
64 1 printf " %s: %s\n", $k, $labels->{$k};
65 }
66 }
67 }
68  
69 1 1;
70  
71 __END__
↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Create.pm »