| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Hetzner::Robot; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Perl client for Hetzner Robot API (Dedicated Servers) |
|
4
|
|
|
|
|
|
|
|
|
5
|
24
|
|
|
24
|
|
14432
|
use Moo; |
|
|
24
|
|
|
|
|
60
|
|
|
|
24
|
|
|
|
|
180
|
|
|
6
|
24
|
|
|
24
|
|
23041
|
use WWW::Hetzner::Robot::API::Servers; |
|
|
24
|
|
|
|
|
103
|
|
|
|
24
|
|
|
|
|
1054
|
|
|
7
|
24
|
|
|
24
|
|
14997
|
use WWW::Hetzner::Robot::API::Keys; |
|
|
24
|
|
|
|
|
101
|
|
|
|
24
|
|
|
|
|
907
|
|
|
8
|
24
|
|
|
24
|
|
12931
|
use WWW::Hetzner::Robot::API::IPs; |
|
|
24
|
|
|
|
|
105
|
|
|
|
24
|
|
|
|
|
1168
|
|
|
9
|
24
|
|
|
24
|
|
13697
|
use WWW::Hetzner::Robot::API::Reset; |
|
|
24
|
|
|
|
|
102
|
|
|
|
24
|
|
|
|
|
979
|
|
|
10
|
24
|
|
|
24
|
|
14082
|
use WWW::Hetzner::Robot::API::Traffic; |
|
|
24
|
|
|
|
|
100
|
|
|
|
24
|
|
|
|
|
979
|
|
|
11
|
24
|
|
|
24
|
|
168
|
use namespace::clean; |
|
|
24
|
|
|
|
|
51
|
|
|
|
24
|
|
|
|
|
128
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.100'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has user => ( |
|
17
|
|
|
|
|
|
|
is => 'ro', |
|
18
|
|
|
|
|
|
|
default => sub { $ENV{HETZNER_ROBOT_USER} }, |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has password => ( |
|
23
|
|
|
|
|
|
|
is => 'ro', |
|
24
|
|
|
|
|
|
|
default => sub { $ENV{HETZNER_ROBOT_PASSWORD} }, |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# For Role::HTTP compatibility |
|
29
|
|
|
|
|
|
|
sub token { |
|
30
|
13
|
|
|
13
|
0
|
29
|
my $self = shift; |
|
31
|
13
|
|
33
|
|
|
115
|
return $self->user && $self->password; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _check_auth { |
|
35
|
13
|
|
|
13
|
|
33
|
my ($self) = @_; |
|
36
|
13
|
50
|
33
|
|
|
123
|
unless ($self->user && $self->password) { |
|
37
|
0
|
|
|
|
|
0
|
die "No Robot credentials configured.\n\n" . |
|
38
|
|
|
|
|
|
|
"Set credentials via:\n" . |
|
39
|
|
|
|
|
|
|
" Environment: HETZNER_ROBOT_USER and HETZNER_ROBOT_PASSWORD\n" . |
|
40
|
|
|
|
|
|
|
" Options: --user and --password\n\n" . |
|
41
|
|
|
|
|
|
|
"Get credentials at: https://robot.hetzner.com/preferences/index\n"; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has base_url => ( |
|
46
|
|
|
|
|
|
|
is => 'ro', |
|
47
|
|
|
|
|
|
|
default => 'https://robot-ws.your-server.de', |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
with 'WWW::Hetzner::Role::HTTP'; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
around _request => sub { |
|
54
|
|
|
|
|
|
|
my ($orig, $self, @args) = @_; |
|
55
|
|
|
|
|
|
|
$self->_check_auth; |
|
56
|
|
|
|
|
|
|
return $self->$orig(@args); |
|
57
|
|
|
|
|
|
|
}; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Override auth for Basic Auth |
|
60
|
|
|
|
|
|
|
sub _set_auth { |
|
61
|
14
|
|
|
14
|
|
4580
|
my ($self, $headers) = @_; |
|
62
|
14
|
|
|
|
|
3520
|
require MIME::Base64; |
|
63
|
14
|
|
|
|
|
5136
|
$headers->{Authorization} = 'Basic ' . |
|
64
|
|
|
|
|
|
|
MIME::Base64::encode_base64($self->user . ':' . $self->password, ''); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Resource accessors |
|
69
|
|
|
|
|
|
|
has servers => ( |
|
70
|
|
|
|
|
|
|
is => 'lazy', |
|
71
|
2
|
|
|
2
|
|
322293
|
builder => sub { WWW::Hetzner::Robot::API::Servers->new(client => shift) }, |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has keys => ( |
|
76
|
|
|
|
|
|
|
is => 'lazy', |
|
77
|
1
|
|
|
1
|
|
483427
|
builder => sub { WWW::Hetzner::Robot::API::Keys->new(client => shift) }, |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
has ips => ( |
|
82
|
|
|
|
|
|
|
is => 'lazy', |
|
83
|
1
|
|
|
1
|
|
431314
|
builder => sub { WWW::Hetzner::Robot::API::IPs->new(client => shift) }, |
|
84
|
|
|
|
|
|
|
); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
has reset => ( |
|
88
|
|
|
|
|
|
|
is => 'lazy', |
|
89
|
1
|
|
|
1
|
|
470337
|
builder => sub { WWW::Hetzner::Robot::API::Reset->new(client => shift) }, |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
has traffic => ( |
|
94
|
|
|
|
|
|
|
is => 'lazy', |
|
95
|
1
|
|
|
1
|
|
439302
|
builder => sub { WWW::Hetzner::Robot::API::Traffic->new(client => shift) }, |
|
96
|
|
|
|
|
|
|
); |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |