| 1 | package WWW::eNom::Role::Command::Domain::PrivateNameServer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 46 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 46 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 46 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 46 | ▶ | use MooseX::Params::Validate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 46 | ▶ | use WWW::eNom::Types qw( Domain DomainName IP PrivateNameServer ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 46 | ▶ | use WWW::eNom::PrivateNameServer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 46 | ▶ | use Data::Util qw( is_string is_hash_ref is_array_ref ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 46 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 46 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 46 | requires 'submit', 'update_nameservers_for_domain_name', 'get_domain_by_name'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 46 | our $VERSION = 'v2.6.0'; # VERSION | |||||||||||||||||||||||||||
| 21 | # ABSTRACT: Domain Private Nameserver Operations | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub create_private_nameserver { | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_private_nameserver: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 0 | my ( %args ) = validated_hash( | |||||||||||||||||||||||||||
| 26 | \@_, | ||||||||||||||||||||||||||||
| 27 | domain_name => { isa => DomainName }, | ||||||||||||||||||||||||||||
| 28 | private_nameserver => { isa => PrivateNameServer, coerce => 1 } | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | return try { | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my $domain = $self->get_domain_by_name( $args{domain_name} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | my $response = $self->submit({ | ||||||||||||||||||||||||||||
| 35 | method => 'RegisterNameServer', | ||||||||||||||||||||||||||||
| 36 | params => { | ||||||||||||||||||||||||||||
| 37 | Add => 'true', | ||||||||||||||||||||||||||||
| 38 | NSName => $args{private_nameserver}->name, | ||||||||||||||||||||||||||||
| 39 | IP => $args{private_nameserver}->ip, | ||||||||||||||||||||||||||||
| 40 | }, | ||||||||||||||||||||||||||||
| 41 | 0 | }); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if( $response->{ErrCount} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if( ( grep { $_ eq 'Domain ID not found.' } @{ $response->{errors} } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};} or grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
MC/DC0%0/2
grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};} or grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};}
grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
Truth table0%0/3
A or B
A= grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};}B= grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
| |||||||||||||||||||||||||||||
| 45 | 0 | || ( grep { $_ eq 'Domain cannot be found.' } @{ $response->{errors} } ) ) { | |||||||||||||||||||||||||||
| 46 | 0 | croak 'Domain not found in your account'; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if( grep { $_ eq 'This nameserver is already registered.' } @{ $response->{errors} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | croak 'Private nameserver already registered'; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | croak 'Unknown error'; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | my @new_domain_nameservers; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if( $domain->has_private_nameservers ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | @new_domain_nameservers = ( | ||||||||||||||||||||||||||||
| 59 | 0 | @{ $domain->ns }, | |||||||||||||||||||||||||||
| 60 | $args{private_nameserver}->name, | ||||||||||||||||||||||||||||
| 61 | 0 | map { $_->name } @{ $domain->private_nameservers }, | |||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | else { | ||||||||||||||||||||||||||||
| 65 | 0 | @new_domain_nameservers = ( @{ $domain->ns }, $args{private_nameserver}->name ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | return $self->update_nameservers_for_domain_name( | |||||||||||||||||||||||||||
| 69 | domain_name => $domain->name, | ||||||||||||||||||||||||||||
| 70 | ns => \@new_domain_nameservers, | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | catch { | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | croak $_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 75 | 0 | }; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub update_private_nameserver_ip { | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
update_private_nameserver_ip: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my ( %args ) = validated_hash( | |||||||||||||||||||||||||||
| 81 | \@_, | ||||||||||||||||||||||||||||
| 82 | name => { isa => DomainName }, | ||||||||||||||||||||||||||||
| 83 | old_ip => { isa => IP }, | ||||||||||||||||||||||||||||
| 84 | new_ip => { isa => IP }, | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if( $args{old_ip} eq $args{new_ip} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | return $self->retrieve_private_nameserver_by_name( $args{name} ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | return try { | ||||||||||||||||||||||||||||
| 92 | my $response = $self->submit({ | ||||||||||||||||||||||||||||
| 93 | method => 'UpdateNameServer', | ||||||||||||||||||||||||||||
| 94 | params => { | ||||||||||||||||||||||||||||
| 95 | NS => $args{name}, | ||||||||||||||||||||||||||||
| 96 | OldIP => $args{old_ip}, | ||||||||||||||||||||||||||||
| 97 | NewIP => $args{new_ip}, | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if( $response->{ErrCount} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if( grep { $_ eq 'Nameserver registration failed due to error 545: Object does not exist' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 103 | 0 | || $_ eq 'Domain cannot be found.' } @{ $response->{errors} } ) { | |||||||||||||||||||||||||||
| 104 | 0 | croak 'Nameserver does not exist'; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if( grep { $_ eq 'Domain ID not found.' } @{ $response->{errors} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | croak 'Nameserver not found in your account'; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if( grep { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | $_ =~ m/failed due to error 541: Parameter value policy error;/ | |||||||||||||||||||||||||||
| 113 | 0 | } @{ $response->{errors} } ) { | |||||||||||||||||||||||||||
| 114 | 0 | croak 'Incorrect old_ip'; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | croak 'Unknown error'; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if( !exists $response->{RegisterNameserver}{NsSuccess} || $response->{RegisterNameserver}{NsSuccess} != 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not exists $response->{"RegisterNameserver"}{"NsSuccess"} or $response->{"RegisterNameserver"}{"NsSuccess"} != 1
MC/DC0%0/2
not exists $response->{"RegisterNameserver"}{"NsSuccess"} or $response->{"RegisterNameserver"}{"NsSuccess"} != 1
not exists $response->{"RegisterNameserver"}{"NsSuccess"}
$response->{"RegisterNameserver"}{"NsSuccess"} != 1
Truth table0%0/3
not(A) or B
A= not exists $response->{"RegisterNameserver"}{"NsSuccess"}B= $response->{"RegisterNameserver"}{"NsSuccess"} != 1
| |||||||||||||||||||||||||||||
| 121 | 0 | croak 'Unable to update nameserver'; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | return $self->retrieve_private_nameserver_by_name( $args{name} ); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | catch { | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | croak $_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 128 | 0 | }; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | sub retrieve_private_nameserver_by_name { | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
retrieve_private_nameserver_by_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 0 | my ( $name ) = pos_validated_list( \@_, { isa => DomainName } ); | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | return try { | ||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $response = $self->submit({ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 137 | method => 'CheckNSStatus', | ||||||||||||||||||||||||||||
| 138 | params => { | ||||||||||||||||||||||||||||
| 139 | CheckNSName => $name, | ||||||||||||||||||||||||||||
| 140 | }, | ||||||||||||||||||||||||||||
| 141 | }); | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if( $response->{ErrCount} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if( grep { $_ eq 'Error 545 - Name server does not exist' } @{ $response->{errors} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | croak 'Nameserver does not exist'; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if( grep { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | $_ eq 'Error 531 - You are not authorized to receive information on this name server' | |||||||||||||||||||||||||||
| 149 | 0 | } @{ $response->{errors} } ) { | |||||||||||||||||||||||||||
| 150 | 0 | croak 'Nameserver not found in your account'; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | croak 'Unknown error'; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if( !exists $response->{CheckNsStatus} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | croak 'Response did not contain private nameserver data'; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | my $ip; | |||||||||||||||||||||||||||
| 161 | # Single IP Address | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if( is_string( $response->{CheckNsStatus}{ipaddress} ) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 163 | 0 | $ip = $response->{CheckNsStatus}{ipaddress}; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | # Multiple IP Addresses, we only use the first one. | ||||||||||||||||||||||||||||
| 166 | ▶ | elsif( is_hash_ref( $response->{CheckNsStatus}{ipaddress} ) | |||||||||||||||||||||||||||
|
Condition0%0/3
is_hash_ref($response->{"CheckNsStatus"}{"ipaddress"}) and is_array_ref($response->{"CheckNsStatus"}{"ipaddress"}{"ipaddress"})
MC/DC0%0/2
is_hash_ref($response->{"CheckNsStatus"}{"ipaddress"}) and is_array_ref($response->{"CheckNsStatus"}{"ipaddress"}{"ipaddress"})
is_hash_ref($response->{"CheckNsStatus"}{"ipaddress"})
is_array_ref($response->{"CheckNsStatus"}{"ipaddress"}{"ipaddress"})
Truth table0%0/3
A and B
A= is_hash_ref($response->{"CheckNsStatus"}{"ipaddress"})B= is_array_ref($response->{"CheckNsStatus"}{"ipaddress"}{"ipaddress"})
| |||||||||||||||||||||||||||||
| 167 | && is_array_ref( $response->{CheckNsStatus}{ipaddress}{ipaddress} ) ) { | ||||||||||||||||||||||||||||
| 168 | 0 | $ip = $response->{CheckNsStatus}{ipaddress}{ipaddress}->[0]; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | else { | ||||||||||||||||||||||||||||
| 171 | 0 | croak 'Unable to determine private nameserver ip address'; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | return WWW::eNom::PrivateNameServer->new( | ||||||||||||||||||||||||||||
| 175 | name => $response->{CheckNsStatus}{name}, | ||||||||||||||||||||||||||||
| 176 | 0 | ip => $ip, | |||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | catch { | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | croak $_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 181 | 0 | }; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | sub delete_private_nameserver { | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
delete_private_nameserver: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 0 | my ( %args ) = validated_hash( | |||||||||||||||||||||||||||
| 187 | \@_, | ||||||||||||||||||||||||||||
| 188 | domain_name => { isa => DomainName }, | ||||||||||||||||||||||||||||
| 189 | private_nameserver_name => { isa => DomainName }, | ||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | return try { | ||||||||||||||||||||||||||||
| 193 | # Prevent users from removing last private nameserver | ||||||||||||||||||||||||||||
| 194 | 0 | ▶ | my $domain = $self->get_domain_by_name( $args{domain_name} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if( scalar @{ $domain->ns } == 1 && $domain->ns->[0] eq $args{private_nameserver_name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @{$domain->ns;} == 1 and $domain->ns->[0] eq $args{"private_nameserver_name"}
MC/DC0%0/2
scalar @{$domain->ns;} == 1 and $domain->ns->[0] eq $args{"private_nameserver_name"}
scalar @{$domain->ns;} == 1
$domain->ns->[0] eq $args{"private_nameserver_name"}
Truth table0%0/3
A and B
A= scalar @{$domain->ns;} == 1B= $domain->ns->[0] eq $args{"private_nameserver_name"}
| |||||||||||||||||||||||||||||
| 196 | 0 | croak 'Blocked deletion - Deleting this would leave this domain with no nameservers!'; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | # Remove this private nameserver from the list of authoritative ones | ||||||||||||||||||||||||||||
| 200 | # and let update_nameservers_for_domain_name handle the deletion. | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if( grep { $_ eq $args{private_nameserver_name} } @{ $domain->ns } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | return $self->update_nameservers_for_domain_name( | ||||||||||||||||||||||||||||
| 203 | domain_name => $domain->name, | ||||||||||||||||||||||||||||
| 204 | 0 | ns => [ grep { $_ ne $args{private_nameserver_name} } @{ $domain->ns } ] | |||||||||||||||||||||||||||
| 205 | ); | ||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | my $response = $self->submit({ | ||||||||||||||||||||||||||||
| 209 | method => 'DeleteNameServer', | ||||||||||||||||||||||||||||
| 210 | params => { | ||||||||||||||||||||||||||||
| 211 | NS => $args{private_nameserver_name}, | ||||||||||||||||||||||||||||
| 212 | }, | ||||||||||||||||||||||||||||
| 213 | 0 | }); | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if( $response->{ErrCount} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if( grep { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 0 | $_ eq 'Nameserver registration failed due to error 545: Object does not exist' | |||||||||||||||||||||||||||
| 218 | 0 | } @{ $response->{errors} } ) { | |||||||||||||||||||||||||||
| 219 | 0 | croak 'Nameserver does not exist'; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if( ( grep { $_ eq 'Domain ID not found.' } @{ $response->{errors} } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};} or grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
MC/DC0%0/2
grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};} or grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};}
grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
Truth table0%0/3
A or B
A= grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};}B= grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
| |||||||||||||||||||||||||||||
| 223 | 0 | || ( grep { $_ eq 'Domain cannot be found.' } @{ $response->{errors} } ) ) { | |||||||||||||||||||||||||||
| 224 | 0 | croak 'Domain not found in your account'; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | croak 'Unknown error'; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | return; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | catch { | ||||||||||||||||||||||||||||
| 233 | 0 | ▶ | croak $_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 234 | 0 | }; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 46 | 1; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | __END__ | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | =head1 NAME | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | WWW::eNom::Role::Command::Domain::PrivateNameServer - Domain Private Nameserver Operations | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | # Create a new Private Nameserver | ||||||||||||||||||||||||||||
| 248 | my $domain = WWW::eNom::Domain->new( ... ); | ||||||||||||||||||||||||||||
| 249 | my $private_nameserver = WWW::eNom::PrivateNameServer->new( | ||||||||||||||||||||||||||||
| 250 | name => 'ns1.' . $domain->name, | ||||||||||||||||||||||||||||
| 251 | ip => '4.2.2.1', | ||||||||||||||||||||||||||||
| 252 | ); | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | my $updated_domain = $api->create_private_nameserver( | ||||||||||||||||||||||||||||
| 255 | domain_name => $domain->name, | ||||||||||||||||||||||||||||
| 256 | private_nameserver => $private_nameserver, | ||||||||||||||||||||||||||||
| 257 | ); | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | # Update the IP of an existing Private Nameserver | ||||||||||||||||||||||||||||
| 260 | my $updated_private_nameserver = $api->update_private_nameserver_ip( | ||||||||||||||||||||||||||||
| 261 | name => $private_nameserver->name, | ||||||||||||||||||||||||||||
| 262 | old_ip => $private_nameserver->ip, | ||||||||||||||||||||||||||||
| 263 | new_ip => '8.8.8.8', | ||||||||||||||||||||||||||||
| 264 | ); | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # Retrieve existing Private Nameserver | ||||||||||||||||||||||||||||
| 267 | my $private_nameserver = $api->retrieve_private_nameserver_by_name( 'ns1.' . $domain->name ); | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | # Delete Private Nameserver | ||||||||||||||||||||||||||||
| 270 | $api->delete_private_nameserver( | ||||||||||||||||||||||||||||
| 271 | domain_name => $domain->name, | ||||||||||||||||||||||||||||
| 272 | private_nameserver_name => $private_nameserver->name | ||||||||||||||||||||||||||||
| 273 | ); | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | =head1 REQUIRED | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | =over 4 | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | =item submit | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | =item get_domain_by_name | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =item update_nameservers_for_domain_name | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | Needed in order to keep private nameservers synced with the authoritative ones. | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =back | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | Implemented private name server operations with L<eNom|https://www.enom.com>'s API. | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =head1 LIMITATIONS | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | L<eNom|https://www.enom.com>'s API does not offer a method to retrieve a list of registered nameservers. As a workaround, and so that we do not I<lose track> of L<Private Nameservers|WWW::eNom::PrivateNameServer>, private nameservers are B<always> added to the L<authoritative nameservers|WWW::eNom::Domain/ns>. In the same vein, if a private nameserver is removed then it is also removed from the L<authoritative nameservers|WWW::eNom::Domain/ns>. | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | =head1 METHODS | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | =head2 create_private_nameserver | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | my $domain = WWW::eNom::Domain->new( ... ); | ||||||||||||||||||||||||||||
| 302 | my $private_nameserver = WWW::eNom::PrivateNameServer->new( | ||||||||||||||||||||||||||||
| 303 | name => 'ns1.' . $domain->name, | ||||||||||||||||||||||||||||
| 304 | ip => '4.2.2.1', | ||||||||||||||||||||||||||||
| 305 | ); | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | my $updated_domain = $api->create_private_nameserver( | ||||||||||||||||||||||||||||
| 308 | domain_name => $domain->name, | ||||||||||||||||||||||||||||
| 309 | private_nameserver => $private_nameserver, | ||||||||||||||||||||||||||||
| 310 | ); | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | Abstraction of the L<RegisterNameServer|https://www.enom.com/api/API%20topics/api_RegisterNameServer.htm> eNom API call. Given a FQDN and a L<WWW::eNom::PrivateNameServer> (or a HashRef that can be coerced into one), creates the private nameserver and adds it to the list of L<authoritative nameservers|WWW::eNom::Domain/ns> for the domain. Keep in mind, the name of private nameserver must be a root of the domain. So if the domain is your-domain.com, you can have ns1.your-domain.com as a private nameserver but you can not have ns1.your-other-domain.com as a private nameserver. | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | This method will croak if the domain is owned by someone else, if it's not registered, or if the private nameserver name or ip are invalid. | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | =head2 update_private_nameserver_ip | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | my $existing_private_nameserver = $api->retrieve_private_nameserver_by_name( ... ); | ||||||||||||||||||||||||||||
| 319 | my $updated_private_nameserver = $api->update_private_nameserver_ip( | ||||||||||||||||||||||||||||
| 320 | name => $existing_private_nameserver->name, | ||||||||||||||||||||||||||||
| 321 | old_ip => $existing_private_nameserver->ip, | ||||||||||||||||||||||||||||
| 322 | new_ip => '8.8.8.8', | ||||||||||||||||||||||||||||
| 323 | ); | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | Abstraction of the L<UpdateNameServer|https://www.enom.com/api/API%20topics/api_UpdateNameServer.htm> eNom API call. Given a FQDN of an existing L<WWW::eNom::PrivateNameServer> as well as the old_ip, updates that private nameserver to use the new_ip. Returned is the updated L<WWW::eNom::PrivateNameServer>. | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | This method will croak if the domain is owned by someone else, if it's not registered, if private nameserver does not exist, or if the provided old_ip is incorrect. | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | =head2 retrieve_private_nameserver_by_name | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | my $private_nameserver = $api->retrieve_private_nameserver_by_name( 'ns1.' . $domain->name ); | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | Abstraction of the L<CheckNSStatus|https://www.enom.com/api/API%20topics/api_CheckNSStatus.htm> eNom API Call. Given a FQDN that is the hostname of a private nameserver, returns an instance of L<WWW::eNom::PrivateNameServer> that describes the registered nameserver. | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | This method will croak if the domain is owned by someone else, if it's not registered, or if private nameserver does not exist. | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | B<NOTE> At some point in L<eNom|https://enom.com>'s past it was possible to associate multiple ip addresses with a private nameservers. This is no longer possible but very old private nameservers when retrieved from the API will show both IPs. As a workaround, only the first IP address will be populated into the instance of L<WWW::eNom::PrivateNameServer> returned. | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | =head2 delete_private_nameserver | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | $api->delete_private_nameserver( | ||||||||||||||||||||||||||||
| 342 | domain_name => $domain->name, | ||||||||||||||||||||||||||||
| 343 | private_nameserver_name => 'ns1.' . $domain->name, | ||||||||||||||||||||||||||||
| 344 | ); | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | Abstraction of the L<DeleteNameServer|https://www.enom.com/api/API%20topics/api_DeleteNameServer.htm> eNom API Call. Given a FQDN and a the FQDN of the private nameserver you wish to delete, deletes the private nameserver and removes it from the L<authoritative nameservers|WWW::eNom::Domain/ns>. | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | If deleting this private nameserver would leave the domain with no authoritative nameservers this method will croak with 'Blocked deletion - Deleting this would leave this domain with no nameservers!' This is a safety that is part of the workaround needed in order to implement private nameservers. | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | This method will also croak if the domain is owned by someone else, if it's not registered, or if private nameserver does not exist. | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | =cut | ||||||||||||||||||||||||||||