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