| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Hetzner::Cloud::Firewall; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Hetzner Cloud Firewall object |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.100'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
25
|
|
|
25
|
|
163
|
use Moo; |
|
|
25
|
|
|
|
|
47
|
|
|
|
25
|
|
|
|
|
149
|
|
|
7
|
25
|
|
|
25
|
|
8982
|
use Carp qw(croak); |
|
|
25
|
|
|
|
|
51
|
|
|
|
25
|
|
|
|
|
1375
|
|
|
8
|
25
|
|
|
25
|
|
161
|
use namespace::clean; |
|
|
25
|
|
|
|
|
72
|
|
|
|
25
|
|
|
|
|
199
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has _client => ( |
|
12
|
|
|
|
|
|
|
is => 'ro', |
|
13
|
|
|
|
|
|
|
required => 1, |
|
14
|
|
|
|
|
|
|
weak_ref => 1, |
|
15
|
|
|
|
|
|
|
init_arg => 'client', |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has id => ( is => 'ro' ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has name => ( is => 'rw' ); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has rules => ( is => 'rw', default => sub { [] } ); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has applied_to => ( is => 'ro', default => sub { [] } ); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has labels => ( is => 'rw', default => sub { {} } ); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has created => ( is => 'ro' ); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Actions |
|
37
|
|
|
|
|
|
|
sub update { |
|
38
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
39
|
0
|
0
|
|
|
|
0
|
croak "Cannot update firewall without ID" unless $self->id; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
my $result = $self->_client->put("/firewalls/" . $self->id, { |
|
42
|
|
|
|
|
|
|
name => $self->name, |
|
43
|
|
|
|
|
|
|
labels => $self->labels, |
|
44
|
|
|
|
|
|
|
}); |
|
45
|
0
|
|
|
|
|
0
|
return $self; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub delete { |
|
50
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
51
|
0
|
0
|
|
|
|
0
|
croak "Cannot delete firewall without ID" unless $self->id; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
$self->_client->delete("/firewalls/" . $self->id); |
|
54
|
0
|
|
|
|
|
0
|
return 1; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub set_rules { |
|
59
|
0
|
|
|
0
|
1
|
0
|
my ($self, @rules) = @_; |
|
60
|
0
|
0
|
|
|
|
0
|
croak "Cannot modify firewall without ID" unless $self->id; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
$self->_client->post("/firewalls/" . $self->id . "/actions/set_rules", { |
|
63
|
|
|
|
|
|
|
rules => \@rules, |
|
64
|
|
|
|
|
|
|
}); |
|
65
|
0
|
|
|
|
|
0
|
$self->rules(\@rules); |
|
66
|
0
|
|
|
|
|
0
|
return $self; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub apply_to_resources { |
|
71
|
0
|
|
|
0
|
1
|
0
|
my ($self, @resources) = @_; |
|
72
|
0
|
0
|
|
|
|
0
|
croak "Cannot modify firewall without ID" unless $self->id; |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
$self->_client->post("/firewalls/" . $self->id . "/actions/apply_to_resources", { |
|
75
|
|
|
|
|
|
|
apply_to => \@resources, |
|
76
|
|
|
|
|
|
|
}); |
|
77
|
0
|
|
|
|
|
0
|
return $self; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub remove_from_resources { |
|
82
|
0
|
|
|
0
|
1
|
0
|
my ($self, @resources) = @_; |
|
83
|
0
|
0
|
|
|
|
0
|
croak "Cannot modify firewall without ID" unless $self->id; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
$self->_client->post("/firewalls/" . $self->id . "/actions/remove_from_resources", { |
|
86
|
|
|
|
|
|
|
remove_from => \@resources, |
|
87
|
|
|
|
|
|
|
}); |
|
88
|
0
|
|
|
|
|
0
|
return $self; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub refresh { |
|
93
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
94
|
0
|
0
|
|
|
|
0
|
croak "Cannot refresh firewall without ID" unless $self->id; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
my $result = $self->_client->get("/firewalls/" . $self->id); |
|
97
|
0
|
|
|
|
|
0
|
my $data = $result->{firewall}; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
0
|
$self->name($data->{name}); |
|
100
|
0
|
|
0
|
|
|
0
|
$self->rules($data->{rules} // []); |
|
101
|
0
|
|
0
|
|
|
0
|
$self->labels($data->{labels} // {}); |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
return $self; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub data { |
|
108
|
1
|
|
|
1
|
1
|
36
|
my ($self) = @_; |
|
109
|
|
|
|
|
|
|
return { |
|
110
|
1
|
|
|
|
|
14
|
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
|
|
|
|
|
|
|
1. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |