File Coverage

blib/lib/WWW/Hetzner/Cloud/Certificate.pm
Criterion Covered Total %
statement 10 26 38.4
branch 0 8 0.0
condition 0 2 0.0
subroutine 4 9 44.4
pod 6 6 100.0
total 20 51 39.2


line stmt bran cond sub pod time code
1             package WWW::Hetzner::Cloud::Certificate;
2             # ABSTRACT: Hetzner Cloud Certificate object
3              
4             our $VERSION = '0.100';
5              
6 25     25   171 use Moo;
  25         54  
  25         190  
7 25     25   9528 use Carp qw(croak);
  25         59  
  25         1638  
8 25     25   151 use namespace::clean;
  25         74  
  25         173  
9              
10              
11             has _client => (
12             is => 'ro',
13             required => 1,
14             weak_ref => 1,
15             init_arg => 'client',
16             );
17              
18             has id => ( is => 'ro' );
19              
20              
21             has name => ( is => 'rw' );
22              
23              
24             has certificate => ( is => 'ro' );
25              
26              
27             has domain_names => ( is => 'ro', default => sub { [] } );
28              
29              
30             has fingerprint => ( is => 'ro' );
31              
32              
33             has status => ( is => 'ro', default => sub { {} } );
34              
35              
36             has type => ( is => 'ro' );
37              
38              
39             has labels => ( is => 'rw', default => sub { {} } );
40              
41              
42             has created => ( is => 'ro' );
43              
44              
45             has not_valid_before => ( is => 'ro' );
46              
47              
48             has not_valid_after => ( is => 'ro' );
49              
50              
51             # Convenience
52 1     1 1 9330 sub is_managed { shift->type eq 'managed' }
53              
54              
55 0   0 0 1   sub is_valid { (shift->status->{issuance} // '') eq 'completed' }
56              
57              
58             # Actions
59             sub update {
60 0     0 1   my ($self) = @_;
61 0 0         croak "Cannot update certificate without ID" unless $self->id;
62              
63 0           $self->_client->put("/certificates/" . $self->id, {
64             name => $self->name,
65             labels => $self->labels,
66             });
67 0           return $self;
68             }
69              
70              
71             sub delete {
72 0     0 1   my ($self) = @_;
73 0 0         croak "Cannot delete certificate without ID" unless $self->id;
74              
75 0           $self->_client->delete("/certificates/" . $self->id);
76 0           return 1;
77             }
78              
79              
80             sub retry {
81 0     0 1   my ($self) = @_;
82 0 0         croak "Cannot retry certificate without ID" unless $self->id;
83 0 0         croak "Only managed certificates can be retried" unless $self->is_managed;
84              
85 0           $self->_client->post("/certificates/" . $self->id . "/actions/retry", {});
86 0           return $self;
87             }
88              
89              
90             sub data {
91 0     0 1   my ($self) = @_;
92             return {
93 0           id => $self->id,
94             name => $self->name,
95             certificate => $self->certificate,
96             domain_names => $self->domain_names,
97             fingerprint => $self->fingerprint,
98             status => $self->status,
99             type => $self->type,
100             labels => $self->labels,
101             created => $self->created,
102             not_valid_before => $self->not_valid_before,
103             not_valid_after => $self->not_valid_after,
104             };
105             }
106              
107              
108              
109             1.
110              
111             __END__