| 1 | package WWW::Hetzner::Robot; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Perl client for Hetzner Robot API (Dedicated Servers) | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use WWW::Hetzner::Robot::API::Servers; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 24 | ▶ | use WWW::Hetzner::Robot::API::Keys; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 24 | ▶ | use WWW::Hetzner::Robot::API::IPs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 24 | ▶ | use WWW::Hetzner::Robot::API::Reset; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 24 | ▶ | use WWW::Hetzner::Robot::API::Traffic; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 24 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 14 | our $VERSION = '0.100'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | has user => ( | ||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | default => sub { $ENV{HETZNER_ROBOT_USER} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 19 | 14 | ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | has password => ( | ||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | default => sub { $ENV{HETZNER_ROBOT_PASSWORD} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 25 | 14 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # For Role::HTTP compatibility | ||||||||||||||||||||||||||||
| 29 | sub token { | ||||||||||||||||||||||||||||
| 30 | 13 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
token: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 13 | ▶ | return $self->user && $self->password; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->user && $self->password
MC/DC0%0/2
$self->user && $self->password
$self->user
$self->password
Truth table33%1/3
A && B
A= $self->userB= $self->password
| |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub _check_auth { | ||||||||||||||||||||||||||||
| 35 | 13 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_check_auth: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 36 | 13 | ▶ | unless ($self->user && $self->password) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->user and $self->password
MC/DC0%0/2
$self->user and $self->password
$self->user
$self->password
Truth table33%1/3
A and B
A= $self->userB= $self->password
| |||||||||||||||||||||||||||||
| 37 | 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 | 14 | has base_url => ( | |||||||||||||||||||||||||||
| 46 | is => 'ro', | ||||||||||||||||||||||||||||
| 47 | default => 'https://robot-ws.your-server.de', | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 14 | with 'WWW::Hetzner::Role::HTTP'; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | around _request => sub { | ||||||||||||||||||||||||||||
| 54 | 13 | ▶ | my ($orig, $self, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 13 | $self->_check_auth; | |||||||||||||||||||||||||||
| 56 | 13 | return $self->$orig(@args); | |||||||||||||||||||||||||||
| 57 | 14 | }; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # Override auth for Basic Auth | ||||||||||||||||||||||||||||
| 60 | sub _set_auth { | ||||||||||||||||||||||||||||
| 61 | 14 | ▶ | my ($self, $headers) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_set_auth: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 14 | require MIME::Base64; | |||||||||||||||||||||||||||
| 63 | 14 | $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 | 1 | ▶ | builder => sub { WWW::Hetzner::Robot::API::Servers->new(client => shift) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
_build_servers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | 14 | ); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | has keys => ( | ||||||||||||||||||||||||||||
| 76 | is => 'lazy', | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | builder => sub { WWW::Hetzner::Robot::API::Keys->new(client => shift) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Subroutine
_build_keys: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 78 | 14 | ); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | has ips => ( | ||||||||||||||||||||||||||||
| 82 | is => 'lazy', | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | builder => sub { WWW::Hetzner::Robot::API::IPs->new(client => shift) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Subroutine
_build_ips: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 84 | 14 | ); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | has reset => ( | ||||||||||||||||||||||||||||
| 88 | is => 'lazy', | ||||||||||||||||||||||||||||
| 89 | 1 | ▶ | builder => sub { WWW::Hetzner::Robot::API::Reset->new(client => shift) }, | ||||||||||||||||||||||||||
|
Subroutine
_build_reset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 14 | ); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | has traffic => ( | ||||||||||||||||||||||||||||
| 94 | is => 'lazy', | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | builder => sub { WWW::Hetzner::Robot::API::Traffic->new(client => shift) }, | ||||||||||||||||||||||||||
|
Subroutine
_build_traffic: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 96 | 14 | ); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 14 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||