| 1 | package WWW::Hetzner::Cloud::API::Firewalls; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Firewalls API | ||||||||||||
| 3 | |||||||||||||
| 4 | 60 | our $VERSION = '0.102'; | |||||||||||
| 5 | |||||||||||||
| 6 | 60 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 60 | with 'WWW::Hetzner::Role::Pagination'; | |||||||||||
| 8 | 60 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 60 | ▶ | use WWW::Hetzner::Cloud::Firewall; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 60 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | 60 | has client => ( | |||||||||||
| 14 | is => 'ro', | ||||||||||||
| 15 | required => 1, | ||||||||||||
| 16 | weak_ref => 1, | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | 60 | with 'WWW::Hetzner::Role::HasActions'; | |||||||||||
| 20 | |||||||||||||
| 21 | 8 | ▶ | sub _wrap { | ||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 8 | my ($self, $data, %extra) = @_; | |||||||||||
| 23 | 8 | return WWW::Hetzner::Cloud::Firewall->new( | |||||||||||
| 24 | client => $self->client, | ||||||||||||
| 25 | %$data, | ||||||||||||
| 26 | %extra, | ||||||||||||
| 27 | ); | ||||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 2 | ▶ | sub _wrap_list { | ||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | 2 | my ($self, $list) = @_; | |||||||||||
| 32 | 2 | return [ map { $self->_wrap($_) } @$list ]; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | 2 | ▶ | sub _list_page { | ||||||||||
|
Subroutine
_list_page: called CC=2 SCAR=7.1
| |||||||||||||
| 37 | 2 | my ($self, %params) = @_; | |||||||||||
| 38 | |||||||||||||
| 39 | 2 | my $result = $self->client->get('/firewalls', params => \%params); | |||||||||||
| 40 | 2 | ▶ | return ($self->_wrap_list($result->{firewalls} // []), $result->{meta}); | ||||||||||
|
Condition50%1/2
$result->{"firewalls"} // []
MC/DC0%0/1
$result->{"firewalls"} // []
$result->{"firewalls"}
Truth table50%1/2
A
A= $result->{"firewalls"}
| |||||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | 1 | ▶ | sub list { | ||||||||||
|
Subroutine
list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 44 | 1 | my ($self, %params) = @_; | |||||||||||
| 45 | |||||||||||||
| 46 | 1 | my ($entities) = $self->_list_page(%params); | |||||||||||
| 47 | 1 | return $entities; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 4 | ▶ | sub get { | ||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 53 | 4 | my ($self, $id) = @_; | |||||||||||
| 54 | 4 | ▶ | croak "Firewall ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | |||||||||||||
| 56 | 4 | my $result = $self->client->get("/firewalls/$id"); | |||||||||||
| 57 | 4 | return $self->_wrap($result->{firewall}); | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | 3 | ▶ | sub create { | ||||||||||
|
Subroutine
create: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||
| 62 | 3 | my ($self, %params) = @_; | |||||||||||
| 63 | |||||||||||||
| 64 | 3 | ▶ | croak "name required" unless $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | |||||||||||||
| 66 | my $body = { | ||||||||||||
| 67 | name => $params{name}, | ||||||||||||
| 68 | 2 | }; | |||||||||||
| 69 | |||||||||||||
| 70 | 2 | ▶ | $body->{rules} = $params{rules} if $params{rules}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | 2 | ▶ | $body->{labels} = $params{labels} if $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 72 | 2 | ▶ | $body->{apply_to} = $params{apply_to} if $params{apply_to}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | |||||||||||||
| 74 | 2 | my $result = $self->client->post('/firewalls', $body); | |||||||||||
| 75 | return $self->_wrap( | ||||||||||||
| 76 | $result->{firewall}, | ||||||||||||
| 77 | 2 | actions => $self->_wrap_actions($result->{actions}), | |||||||||||
| 78 | ); | ||||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | |||||||||||||
| 82 | 0 | ▶ | sub update { | ||||||||||
|
Subroutine
update: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 83 | 0 | my ($self, $id, %params) = @_; | |||||||||||
| 84 | 0 | ▶ | croak "Firewall ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | |||||||||||||
| 86 | 0 | my $body = {}; | |||||||||||
| 87 | 0 | ▶ | $body->{name} = $params{name} if exists $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 88 | 0 | ▶ | $body->{labels} = $params{labels} if exists $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | |||||||||||||
| 90 | 0 | my $result = $self->client->put("/firewalls/$id", $body); | |||||||||||
| 91 | 0 | return $self->_wrap($result->{firewall}); | |||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | |||||||||||||
| 95 | 2 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 96 | 2 | my ($self, $id) = @_; | |||||||||||
| 97 | 2 | ▶ | croak "Firewall ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | |||||||||||||
| 99 | 2 | return $self->client->delete("/firewalls/$id"); | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | |||||||||||||
| 103 | 3 | ▶ | sub set_rules { | ||||||||||
|
Subroutine
set_rules: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||
| 104 | 3 | my ($self, $id, $rules) = @_; | |||||||||||
| 105 | 3 | ▶ | croak "Firewall ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 3 | ▶ | croak "Rules arrayref required" unless ref $rules eq 'ARRAY'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 107 | |||||||||||||
| 108 | return $self->_wrap_actions( | ||||||||||||
| 109 | $self->client->post("/firewalls/$id/actions/set_rules", { | ||||||||||||
| 110 | rules => $rules, | ||||||||||||
| 111 | })->{actions} | ||||||||||||
| 112 | 3 | ); | |||||||||||
| 113 | } | ||||||||||||
| 114 | |||||||||||||
| 115 | |||||||||||||
| 116 | 4 | ▶ | sub apply_to_resources { | ||||||||||
|
Subroutine
apply_to_resources: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 117 | 4 | my ($self, $id, @resources) = @_; | |||||||||||
| 118 | 4 | ▶ | croak "Firewall ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 119 | |||||||||||||
| 120 | return $self->_wrap_actions( | ||||||||||||
| 121 | $self->client->post("/firewalls/$id/actions/apply_to_resources", { | ||||||||||||
| 122 | apply_to => \@resources, | ||||||||||||
| 123 | })->{actions} | ||||||||||||
| 124 | 4 | ); | |||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | |||||||||||||
| 128 | 3 | ▶ | sub remove_from_resources { | ||||||||||
|
Subroutine
remove_from_resources: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 129 | 3 | my ($self, $id, @resources) = @_; | |||||||||||
| 130 | 3 | ▶ | croak "Firewall ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 131 | |||||||||||||
| 132 | return $self->_wrap_actions( | ||||||||||||
| 133 | $self->client->post("/firewalls/$id/actions/remove_from_resources", { | ||||||||||||
| 134 | remove_from => \@resources, | ||||||||||||
| 135 | })->{actions} | ||||||||||||
| 136 | 3 | ); | |||||||||||
| 137 | } | ||||||||||||
| 138 | |||||||||||||
| 139 | |||||||||||||
| 140 | 60 | 1; | |||||||||||
| 141 | |||||||||||||
| 142 | __END__ | ||||||||||||