| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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 // "-"
MC/DC0%0/1
$fw->created // "-"
$fw->created
Truth table50%1/2
A
A= $fw->created
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 1 | my $rules = $fw->rules; | |||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | if ($rules && @$rules) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rules and @$rules
MC/DC0%0/2
$rules and @$rules
$rules
@$rules
Truth table33%1/3
A and B
A= $rulesB= @$rules
| |||||||||||||||||||||||||||||||||
| 31 | 1 | print "\nRules:\n"; | |||||||||||||||||||||||||||||||
| 32 | 1 | for my $r (@$rules) { | |||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | my $port = $r->{port} // 'any'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$r->{"port"} // "any"
MC/DC0%0/1
$r->{"port"} // "any"
$r->{"port"}
Truth table50%1/2
A
A= $r->{"port"}
| |||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | my $proto = $r->{protocol} // 'any'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$r->{"protocol"} // "any"
MC/DC0%0/1
$r->{"protocol"} // "any"
$r->{"protocol"}
Truth table50%1/2
A
A= $r->{"protocol"}
| |||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | my $dir = $r->{direction} // 'in'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$r->{"direction"} // "in"
MC/DC0%0/1
$r->{"direction"} // "in"
$r->{"direction"}
Truth table50%1/2
A
A= $r->{"direction"}
| |||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | my $sources = $r->{source_ips} ? join(', ', @{$r->{source_ips}}) : 'any'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my $dests = $r->{destination_ips} ? join(', ', @{$r->{destination_ips}}) : 'any'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | if ($dir eq 'in') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$applied and @$applied
MC/DC0%0/2
$applied and @$applied
$applied
@$applied
Truth table33%1/3
A and B
A= $appliedB= @$applied
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$type eq "server" and $a->{"server"}
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"}
| |||||||||||||||||||||||||||||||||
| 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"}
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"}
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$labels and %$labels
MC/DC0%0/2
$labels and %$labels
$labels
%$labels
Truth table33%1/3
A and B
A= $labelsB= %$labels
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||