| 1 | package WWW::Hetzner::Cloud::Firewall; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Firewall object | ||||||||||||
| 3 | |||||||||||||
| 4 | 60 | our $VERSION = '0.102'; | |||||||||||
| 5 | |||||||||||||
| 6 | 60 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 60 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 60 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | 60 | has _client => ( | |||||||||||
| 12 | is => 'ro', | ||||||||||||
| 13 | required => 1, | ||||||||||||
| 14 | weak_ref => 1, | ||||||||||||
| 15 | init_arg => 'client', | ||||||||||||
| 16 | ); | ||||||||||||
| 17 | |||||||||||||
| 18 | 60 | has id => ( is => 'ro' ); | |||||||||||
| 19 | |||||||||||||
| 20 | |||||||||||||
| 21 | 60 | 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 | 60 | has created => ( is => 'ro' ); | |||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | 6 | ▶ | has actions => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 37 | |||||||||||||
| 38 | |||||||||||||
| 39 | # Actions | ||||||||||||
| 40 | 0 | ▶ | sub update { | ||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 41 | 0 | my ($self) = @_; | |||||||||||
| 42 | 0 | ▶ | croak "Cannot update firewall without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | |||||||||||||
| 44 | 0 | my $result = $self->_client->put("/firewalls/" . $self->id, { | |||||||||||
| 45 | name => $self->name, | ||||||||||||
| 46 | labels => $self->labels, | ||||||||||||
| 47 | }); | ||||||||||||
| 48 | 0 | return $self; | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 0 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 53 | 0 | my ($self) = @_; | |||||||||||
| 54 | 0 | ▶ | croak "Cannot delete firewall without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | |||||||||||||
| 56 | 0 | $self->_client->delete("/firewalls/" . $self->id); | |||||||||||
| 57 | 0 | return 1; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | 1 | ▶ | sub set_rules { | ||||||||||
|
Subroutine
set_rules: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 62 | 1 | my ($self, @rules) = @_; | |||||||||||
| 63 | 1 | ▶ | croak "Cannot modify firewall without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | |||||||||||||
| 65 | 1 | my $actions = $self->_client->firewalls->set_rules($self->id, \@rules); | |||||||||||
| 66 | 1 | $self->rules(\@rules); | |||||||||||
| 67 | 1 | return $actions; | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | |||||||||||||
| 71 | 1 | ▶ | sub apply_to_resources { | ||||||||||
|
Subroutine
apply_to_resources: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 72 | 1 | my ($self, @resources) = @_; | |||||||||||
| 73 | 1 | ▶ | croak "Cannot modify firewall without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | |||||||||||||
| 75 | 1 | return $self->_client->firewalls->apply_to_resources($self->id, @resources); | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | |||||||||||||
| 79 | 1 | ▶ | sub remove_from_resources { | ||||||||||
|
Subroutine
remove_from_resources: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 80 | 1 | my ($self, @resources) = @_; | |||||||||||
| 81 | 1 | ▶ | croak "Cannot modify firewall without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | |||||||||||||
| 83 | 1 | return $self->_client->firewalls->remove_from_resources($self->id, @resources); | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | |||||||||||||
| 87 | 0 | ▶ | sub refresh { | ||||||||||
|
Subroutine
refresh: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 88 | 0 | my ($self) = @_; | |||||||||||
| 89 | 0 | ▶ | croak "Cannot refresh firewall without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | |||||||||||||
| 91 | 0 | my $result = $self->_client->get("/firewalls/" . $self->id); | |||||||||||
| 92 | 0 | my $data = $result->{firewall}; | |||||||||||
| 93 | |||||||||||||
| 94 | 0 | $self->name($data->{name}); | |||||||||||
| 95 | 0 | ▶ | $self->rules($data->{rules} // []); | ||||||||||
|
Condition0%0/2
$data->{"rules"} // []
MC/DC0%0/1
$data->{"rules"} // []
$data->{"rules"}
Truth table0%0/2
A
A= $data->{"rules"}
| |||||||||||||
| 96 | 0 | ▶ | $self->labels($data->{labels} // {}); | ||||||||||
|
Condition0%0/2
$data->{"labels"} // {}
MC/DC0%0/1
$data->{"labels"} // {}
$data->{"labels"}
Truth table0%0/2
A
A= $data->{"labels"}
| |||||||||||||
| 97 | |||||||||||||
| 98 | 0 | return $self; | |||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | |||||||||||||
| 102 | 1 | ▶ | sub data { | ||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 103 | 1 | my ($self) = @_; | |||||||||||
| 104 | return { | ||||||||||||
| 105 | 1 | id => $self->id, | |||||||||||
| 106 | name => $self->name, | ||||||||||||
| 107 | rules => $self->rules, | ||||||||||||
| 108 | applied_to => $self->applied_to, | ||||||||||||
| 109 | labels => $self->labels, | ||||||||||||
| 110 | created => $self->created, | ||||||||||||
| 111 | }; | ||||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | |||||||||||||
| 115 | |||||||||||||
| 116 | 60 | 1. | |||||||||||
| 117 | |||||||||||||
| 118 | __END__ | ||||||||||||