| 1 | package WWW::Hetzner::Cloud::API::Certificates; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Certificates API | ||||||||||||
| 3 | |||||||||||||
| 4 | 25 | our $VERSION = '0.100'; | |||||||||||
| 5 | |||||||||||||
| 6 | 25 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 25 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 25 | ▶ | use WWW::Hetzner::Cloud::Certificate; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 25 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | |||||||||||||
| 12 | 25 | has client => ( | |||||||||||
| 13 | is => 'ro', | ||||||||||||
| 14 | required => 1, | ||||||||||||
| 15 | weak_ref => 1, | ||||||||||||
| 16 | ); | ||||||||||||
| 17 | |||||||||||||
| 18 | sub _wrap { | ||||||||||||
| 19 | 3 | ▶ | my ($self, $data) = @_; | ||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 3 | return WWW::Hetzner::Cloud::Certificate->new( | |||||||||||
| 21 | client => $self->client, | ||||||||||||
| 22 | %$data, | ||||||||||||
| 23 | ); | ||||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | sub _wrap_list { | ||||||||||||
| 27 | 1 | ▶ | my ($self, $list) = @_; | ||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 1 | return [ map { $self->_wrap($_) } @$list ]; | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | |||||||||||||
| 32 | sub list { | ||||||||||||
| 33 | 1 | ▶ | my ($self, %params) = @_; | ||||||||||
|
Subroutine
list: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 34 | |||||||||||||
| 35 | 1 | my $result = $self->client->get('/certificates', params => \%params); | |||||||||||
| 36 | 1 | ▶ | return $self->_wrap_list($result->{certificates} // []); | ||||||||||
|
Condition50%1/2
$result->{"certificates"} // []
MC/DC0%0/1
$result->{"certificates"} // []
$result->{"certificates"}
Truth table50%1/2
A
A= $result->{"certificates"}
| |||||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | |||||||||||||
| 40 | sub get { | ||||||||||||
| 41 | 1 | ▶ | my ($self, $id) = @_; | ||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 42 | 1 | ▶ | croak "Certificate ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | |||||||||||||
| 44 | 1 | my $result = $self->client->get("/certificates/$id"); | |||||||||||
| 45 | 1 | return $self->_wrap($result->{certificate}); | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | |||||||||||||
| 49 | sub create { | ||||||||||||
| 50 | 1 | ▶ | my ($self, %params) = @_; | ||||||||||
|
Subroutine
create: called CC=7 SCAR=20.8
Pod
documented
| |||||||||||||
| 51 | |||||||||||||
| 52 | 1 | ▶ | croak "name required" unless $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | 1 | ▶ | croak "type required (uploaded or managed)" unless $params{type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | |||||||||||||
| 55 | my $body = { | ||||||||||||
| 56 | name => $params{name}, | ||||||||||||
| 57 | type => $params{type}, | ||||||||||||
| 58 | 1 | }; | |||||||||||
| 59 | |||||||||||||
| 60 | # For uploaded certificates | ||||||||||||
| 61 | 1 | ▶ | $body->{certificate} = $params{certificate} if $params{certificate}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 1 | ▶ | $body->{private_key} = $params{private_key} if $params{private_key}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | |||||||||||||
| 64 | # For managed certificates | ||||||||||||
| 65 | 1 | ▶ | $body->{domain_names} = $params{domain_names} if $params{domain_names}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | |||||||||||||
| 67 | 1 | ▶ | $body->{labels} = $params{labels} if $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | |||||||||||||
| 69 | 1 | my $result = $self->client->post('/certificates', $body); | |||||||||||
| 70 | 1 | return $self->_wrap($result->{certificate}); | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | |||||||||||||
| 74 | sub update { | ||||||||||||
| 75 | 0 | ▶ | my ($self, $id, %params) = @_; | ||||||||||
|
Subroutine
update: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 76 | 0 | ▶ | croak "Certificate ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | |||||||||||||
| 78 | 0 | my $body = {}; | |||||||||||
| 79 | 0 | ▶ | $body->{name} = $params{name} if exists $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | 0 | ▶ | $body->{labels} = $params{labels} if exists $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | |||||||||||||
| 82 | 0 | my $result = $self->client->put("/certificates/$id", $body); | |||||||||||
| 83 | 0 | return $self->_wrap($result->{certificate}); | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | |||||||||||||
| 87 | sub delete { | ||||||||||||
| 88 | 1 | ▶ | my ($self, $id) = @_; | ||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 89 | 1 | ▶ | croak "Certificate ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | |||||||||||||
| 91 | 1 | return $self->client->delete("/certificates/$id"); | |||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | |||||||||||||
| 95 | sub retry { | ||||||||||||
| 96 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||
|
Subroutine
retry: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 97 | 0 | ▶ | croak "Certificate ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | |||||||||||||
| 99 | 0 | return $self->client->post("/certificates/$id/actions/retry", {}); | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | |||||||||||||
| 103 | 25 | 1; | |||||||||||
| 104 | |||||||||||||
| 105 | __END__ | ||||||||||||