lib/WWW/Hetzner/Robot.pm

filter: Statementstmt 91.0% 51 / 56 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 80.9% 17 / 21 Podpod 0.0% 0 / 1 totaltotal 78.8% 71 / 90 CC 4 SCAR 4.4
CC
4
Cov
84%
_check_auth
4.1
token
2.3
__ANON__
2.0
CRAP 1.6
« script/hrobot.pl ↑ Summary lib/WWW/Hetzner/Robot/Key.pm »
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
!ll&&!rl&&r
0013
MC/DC0%0/2
$self->user && $self->password
$self->user $self->password
Truth table33%1/3
A && B
A= $self->userB= $self->password
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless ($self->user and $self->password) 0 13 13
Condition33%1/3
$self->user and $self->password
!ll&&!rl&&r
0013
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
ABresult
0X0
100
111
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__
« script/hrobot.pl ↑ Summary lib/WWW/Hetzner/Robot/Key.pm »