| 1 | package WWW::Hetzner::Cloud::API::RRSets; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud DNS RRSets (Records) 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::RRSet; | ||||||||||
|
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 | 25 | has zone_id => ( | |||||||||||
| 19 | is => 'ro', | ||||||||||||
| 20 | required => 1, | ||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | sub _wrap { | ||||||||||||
| 24 | 25 | ▶ | my ($self, $data) = @_; | ||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 25 | return WWW::Hetzner::Cloud::RRSet->new( | |||||||||||
| 26 | client => $self->client, | ||||||||||||
| 27 | zone_id => $self->zone_id, | ||||||||||||
| 28 | %$data, | ||||||||||||
| 29 | ); | ||||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | sub _wrap_list { | ||||||||||||
| 33 | 3 | ▶ | my ($self, $list) = @_; | ||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | 3 | return [ map { $self->_wrap($_) } @$list ]; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | sub _base_path { | ||||||||||||
| 38 | 14 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
_base_path: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | 14 | return "/zones/" . $self->zone_id . "/rrsets"; | |||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | |||||||||||||
| 43 | sub list { | ||||||||||||
| 44 | 3 | ▶ | my ($self, %params) = @_; | ||||||||||
|
Subroutine
list: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 45 | |||||||||||||
| 46 | 3 | my $result = $self->client->get($self->_base_path, params => \%params); | |||||||||||
| 47 | 3 | ▶ | return $self->_wrap_list($result->{rrsets} // []); | ||||||||||
|
Condition50%1/2
$result->{"rrsets"} // []
MC/DC0%0/1
$result->{"rrsets"} // []
$result->{"rrsets"}
Truth table50%1/2
A
A= $result->{"rrsets"}
| |||||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | sub get { | ||||||||||||
| 52 | 3 | ▶ | my ($self, $name, $type) = @_; | ||||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 53 | 3 | ▶ | croak "Record name required" unless $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | 2 | ▶ | croak "Record type required" unless $type; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | |||||||||||||
| 56 | 1 | my $path = $self->_base_path . "/$name/$type"; | |||||||||||
| 57 | 1 | my $result = $self->client->get($path); | |||||||||||
| 58 | 1 | return $self->_wrap($result->{rrset}); | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | |||||||||||||
| 62 | sub create { | ||||||||||||
| 63 | 11 | ▶ | my ($self, %params) = @_; | ||||||||||
|
Subroutine
create: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||
| 64 | |||||||||||||
| 65 | 11 | ▶ | croak "name required" unless $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | 10 | ▶ | croak "type required" unless $params{type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 9 | ▶ | croak "records required" unless $params{records}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | |||||||||||||
| 69 | my $body = { | ||||||||||||
| 70 | name => $params{name}, | ||||||||||||
| 71 | type => $params{type}, | ||||||||||||
| 72 | records => $params{records}, | ||||||||||||
| 73 | 8 | }; | |||||||||||
| 74 | |||||||||||||
| 75 | 8 | ▶ | $body->{ttl} = $params{ttl} if $params{ttl}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | |||||||||||||
| 77 | 8 | my $result = $self->client->post($self->_base_path, $body); | |||||||||||
| 78 | 8 | return $self->_wrap($result->{rrset}); | |||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | |||||||||||||
| 82 | sub update { | ||||||||||||
| 83 | 3 | ▶ | my ($self, $name, $type, %params) = @_; | ||||||||||
|
Subroutine
update: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||
| 84 | 3 | ▶ | croak "Record name required" unless $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | 2 | ▶ | croak "Record type required" unless $type; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | |||||||||||||
| 87 | 1 | my $body = {}; | |||||||||||
| 88 | 1 | ▶ | $body->{ttl} = $params{ttl} if exists $params{ttl}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | 1 | ▶ | $body->{records} = $params{records} if exists $params{records}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | |||||||||||||
| 91 | 1 | my $path = $self->_base_path . "/$name/$type"; | |||||||||||
| 92 | 1 | my $result = $self->client->put($path, $body); | |||||||||||
| 93 | 1 | return $self->_wrap($result->{rrset}); | |||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | |||||||||||||
| 97 | sub delete { | ||||||||||||
| 98 | 3 | ▶ | my ($self, $name, $type) = @_; | ||||||||||
|
Subroutine
delete: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 99 | 3 | ▶ | croak "Record name required" unless $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 100 | 2 | ▶ | croak "Record type required" unless $type; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | |||||||||||||
| 102 | 1 | my $path = $self->_base_path . "/$name/$type"; | |||||||||||
| 103 | 1 | return $self->client->delete($path); | |||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | |||||||||||||
| 107 | sub add_a { | ||||||||||||
| 108 | 4 | ▶ | my ($self, $name, $ip, %opts) = @_; | ||||||||||
|
Subroutine
add_a: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 109 | 4 | ▶ | croak "name required" unless $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 110 | 3 | ▶ | croak "IP address required" unless $ip; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | |||||||||||||
| 112 | 2 | return $self->create( | |||||||||||
| 113 | name => $name, | ||||||||||||
| 114 | type => 'A', | ||||||||||||
| 115 | records => [{ value => $ip }], | ||||||||||||
| 116 | %opts, | ||||||||||||
| 117 | ); | ||||||||||||
| 118 | } | ||||||||||||
| 119 | |||||||||||||
| 120 | |||||||||||||
| 121 | sub add_aaaa { | ||||||||||||
| 122 | 3 | ▶ | my ($self, $name, $ip, %opts) = @_; | ||||||||||
|
Subroutine
add_aaaa: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 123 | 3 | ▶ | croak "name required" unless $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 124 | 2 | ▶ | croak "IPv6 address required" unless $ip; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 125 | |||||||||||||
| 126 | 1 | return $self->create( | |||||||||||
| 127 | name => $name, | ||||||||||||
| 128 | type => 'AAAA', | ||||||||||||
| 129 | records => [{ value => $ip }], | ||||||||||||
| 130 | %opts, | ||||||||||||
| 131 | ); | ||||||||||||
| 132 | } | ||||||||||||
| 133 | |||||||||||||
| 134 | |||||||||||||
| 135 | sub add_cname { | ||||||||||||
| 136 | 3 | ▶ | my ($self, $name, $target, %opts) = @_; | ||||||||||
|
Subroutine
add_cname: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 137 | 3 | ▶ | croak "name required" unless $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 138 | 2 | ▶ | croak "target required" unless $target; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 139 | |||||||||||||
| 140 | 1 | return $self->create( | |||||||||||
| 141 | name => $name, | ||||||||||||
| 142 | type => 'CNAME', | ||||||||||||
| 143 | records => [{ value => $target }], | ||||||||||||
| 144 | %opts, | ||||||||||||
| 145 | ); | ||||||||||||
| 146 | } | ||||||||||||
| 147 | |||||||||||||
| 148 | |||||||||||||
| 149 | sub add_mx { | ||||||||||||
| 150 | 3 | ▶ | my ($self, $name, $mailserver, $priority, %opts) = @_; | ||||||||||
|
Subroutine
add_mx: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 151 | 3 | ▶ | croak "name required" unless $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 152 | 2 | ▶ | croak "mailserver required" unless $mailserver; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 153 | 1 | ▶ | $priority //= 10; | ||||||||||
|
Condition50%1/2
$priority //= 10
MC/DC0%0/1
$priority //= 10
$priority
Truth table50%1/2
A
A= $priority
| |||||||||||||
| 154 | |||||||||||||
| 155 | 1 | return $self->create( | |||||||||||
| 156 | name => $name, | ||||||||||||
| 157 | type => 'MX', | ||||||||||||
| 158 | records => [{ value => "$priority $mailserver" }], | ||||||||||||
| 159 | %opts, | ||||||||||||
| 160 | ); | ||||||||||||
| 161 | } | ||||||||||||
| 162 | |||||||||||||
| 163 | |||||||||||||
| 164 | sub add_txt { | ||||||||||||
| 165 | 3 | ▶ | my ($self, $name, $value, %opts) = @_; | ||||||||||
|
Subroutine
add_txt: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 166 | 3 | ▶ | croak "name required" unless $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 167 | 2 | ▶ | croak "value required" unless $value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 168 | |||||||||||||
| 169 | 1 | return $self->create( | |||||||||||
| 170 | name => $name, | ||||||||||||
| 171 | type => 'TXT', | ||||||||||||
| 172 | records => [{ value => $value }], | ||||||||||||
| 173 | %opts, | ||||||||||||
| 174 | ); | ||||||||||||
| 175 | } | ||||||||||||
| 176 | |||||||||||||
| 177 | |||||||||||||
| 178 | 25 | 1; | |||||||||||
| 179 | |||||||||||||
| 180 | __END__ | ||||||||||||