lib/WWW/Hetzner/Cloud/API/Certificates.pm

filter: Statementstmt 87.2% 48 / 55 Branchbran 37.5% 9 / 24 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 92.3% 12 / 13 Podpod 100% 6 / 6 totaltotal 75.2% 76 / 101 CC 14 SCAR 18.1
CC
14
Cov
72%
update
20.0
create
8.0
_list_page
2.0
CRAP 6.1
« lib/WWW/Hetzner/CLI/Cmd/Pricing.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Networks.pm »
1 package WWW::Hetzner::Cloud::API::Certificates;
2 # ABSTRACT: Hetzner Cloud Certificates 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::Certificate;
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 7 ▶sub _wrap {
Subroutine _wrap: called CC=1 SCAR=0.0
22 7 my ($self, $data, %extra) = @_;
23 7 return WWW::Hetzner::Cloud::Certificate->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('/certificates', params => \%params);
40 2 ▶ return ($self->_wrap_list($result->{certificates} // []), $result->{meta});
Condition50%1/2
$result->{"certificates"} // []
l!l
20
MC/DC0%0/1
$result->{"certificates"} // []
$result->{"certificates"}
Truth table50%1/2
A
A= $result->{"certificates"}
Aresult
11
00
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 3 ▶sub get {
Subroutine get: called CC=2 SCAR=7.0
Pod documented
53 3 my ($self, $id) = @_;
54 3 ▶ croak "Certificate ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 3 3
55  
56 3 my $result = $self->client->get("/certificates/$id");
57 3 return $self->_wrap($result->{certificate});
58 }
59  
60  
61 2 ▶sub create {
Subroutine create: called CC=7 SCAR=20.8
Pod documented
62 2 my ($self, %params) = @_;
63  
64 2 ▶ croak "name required" unless $params{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"name"} 0 2 2
65 2 ▶ croak "type required (uploaded or managed)" unless $params{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"type"} 0 2 2
66  
67 my $body = {
68 name => $params{name},
69 type => $params{type},
70 2 };
71  
72 # For uploaded certificates
73 2 ▶ $body->{certificate} = $params{certificate} if $params{certificate};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"certificate"} 0 2 2
74 2 ▶ $body->{private_key} = $params{private_key} if $params{private_key};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"private_key"} 0 2 2
75  
76 # For managed certificates
77 2 ▶ $body->{domain_names} = $params{domain_names} if $params{domain_names};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"domain_names"} 2 0 2
78  
79 2 ▶ $body->{labels} = $params{labels} if $params{labels};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"labels"} 0 2 2
80  
81 2 my $result = $self->client->post('/certificates', $body);
82 return $self->_wrap(
83 $result->{certificate},
84 action => $self->_wrap_action($result->{action}),
85 2 next_actions => $self->_wrap_actions($result->{next_actions}),
86 );
87 }
88  
89  
90 0 ▶sub update {
Subroutine update: not called CC=4 SCAR=30.0
Pod documented
91 0 my ($self, $id, %params) = @_;
92 0 ▶ croak "Certificate ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
93  
94 0 my $body = {};
95 0 ▶ $body->{name} = $params{name} if exists $params{name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"name"} 0 0 0
96 0 ▶ $body->{labels} = $params{labels} if exists $params{labels};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"labels"} 0 0 0
97  
98 0 my $result = $self->client->put("/certificates/$id", $body);
99 0 return $self->_wrap($result->{certificate});
100 }
101  
102  
103 2 ▶sub delete {
Subroutine delete: called CC=2 SCAR=7.1
Pod documented
104 2 my ($self, $id) = @_;
105 2 ▶ croak "Certificate ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 2 2
106  
107 2 return $self->client->delete("/certificates/$id");
108 }
109  
110  
111 2 ▶sub retry {
Subroutine retry: called CC=2 SCAR=7.1
Pod documented
112 2 my ($self, $id) = @_;
113 2 ▶ croak "Certificate ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 2 2
114  
115 return $self->_wrap_action(
116 $self->client->post("/certificates/$id/actions/retry", {})->{action}
117 2 );
118 }
119  
120  
121 60 1;
122  
123 __END__
« lib/WWW/Hetzner/CLI/Cmd/Pricing.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Networks.pm »