blib/lib/WWW/eNom/Role/Command/Domain/PrivateNameServer.pm

filter: Statementstmt 27.0% 27 / 100 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 47.0% 8 / 17 Podpod 100% 3 / 3 totaltotal 23.6% 38 / 161 CC 17 SCAR 34.1
CC
17
Cov
20%
__ANON__
72.0
__ANON__
42.0
__ANON__
30.0
CRAP 30.2
« blib/lib/WWW/eNom/DomainRequest/Registration.pm ↑ Summary blib/lib/WWW/eNom/Contact.pm »
1 package WWW::eNom::Role::Command::Domain::PrivateNameServer;
2  
3 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 44 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 44 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 44 ▶use WWW::eNom::Types qw( Domain DomainName PrivateNameServer );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 44 ▶use WWW::eNom::PrivateNameServer;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 44 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 44 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 44 requires 'submit', 'update_nameservers_for_domain_name', 'get_domain_by_name';
17  
18 44 our $VERSION = 'v2.0.0'; # VERSION
19 # ABSTRACT: Domain Private Nameserver Operations
20  
21 sub create_private_nameserver {
22 0 ▶ my $self = shift;
Subroutine create_private_nameserver: not called CC=1 SCAR=6.9
Pod documented
23 0 my ( %args ) = validated_hash(
24 \@_,
25 domain_name => { isa => DomainName },
26 private_nameserver => { isa => PrivateNameServer, coerce => 1 }
27 );
28  
29 return try {
30 0 ▶ my $domain = $self->get_domain_by_name( $args{domain_name} );
Subroutine __ANON__: not called CC=6 SCAR=37.4
31  
32 my $response = $self->submit({
33 method => 'RegisterNameServer',
34 params => {
35 Add => 'true',
36 NSName => $args{private_nameserver}->name,
37 IP => $args{private_nameserver}->ip,
38 },
39 0 });
40  
41 0 ▶ if( $response->{ErrCount} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"ErrCount"} > 0) 0 0 0
42 0 ▶ if( ( grep { $_ eq 'Domain ID not found.' } @{ $response->{errors} } )
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};} or grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}) 0 0 0
Condition0%0/3
grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};} or grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
l!l&&r!l&&!r
000
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"};}
ABresult
1X1
011
000
43 0 || ( grep { $_ eq 'Domain cannot be found.' } @{ $response->{errors} } ) ) {
44 0 croak 'Domain not found in your account';
45 }
46  
47 0 ▶ if( grep { $_ eq 'This nameserver is already registered.' } @{ $response->{errors} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "This nameserver is already registered.";} @{$$response{"errors"};}) 0 0 0
48 0 croak 'Private nameserver already registered';
49 }
50  
51 0 croak 'Unknown error';
52 }
53  
54 0 my @new_domain_nameservers;
55 0 ▶ if( $domain->has_private_nameservers ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($domain->has_private_nameservers) { } 0 0 0
56 @new_domain_nameservers = (
57 0 @{ $domain->ns },
58 $args{private_nameserver}->name,
59 0 map { $_->name } @{ $domain->private_nameservers },
60 );
61 }
62 else {
63 0 @new_domain_nameservers = ( @{ $domain->ns }, $args{private_nameserver}->name );
64 }
65  
66 0 return $self->update_nameservers_for_domain_name(
67 domain_name => $domain->name,
68 ns => \@new_domain_nameservers,
69 );
70 }
71 catch {
72 0 ▶ croak $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 0 };
74 }
75  
76 sub retrieve_private_nameserver_by_name {
77 0 ▶ my $self = shift;
Subroutine retrieve_private_nameserver_by_name: not called CC=1 SCAR=6.9
Pod documented
78 0 my ( $name ) = pos_validated_list( \@_, { isa => DomainName } );
79  
80 return try {
81 0 ▶ my $response = $self->submit({
Subroutine __ANON__: not called CC=5 SCAR=34.0
82 method => 'CheckNSStatus',
83 params => {
84 CheckNSName => $name,
85 },
86 });
87  
88 0 ▶ if( $response->{ErrCount} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"ErrCount"} > 0) 0 0 0
89 0 ▶ if( grep { $_ eq 'Error 545 - Name server does not exist' } @{ $response->{errors} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "Error 545 - Name server does not exist";} @{$$response{"errors"};}) 0 0 0
90 0 croak 'Nameserver does not exist';
91 }
92 0 ▶ if( grep {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "Error 531 - You are not authorized to receive information on this name server";} @{$$response{"errors"};}) 0 0 0
93 0 $_ eq 'Error 531 - You are not authorized to receive information on this name server'
94 0 } @{ $response->{errors} } ) {
95 0 croak 'Nameserver not found in your account';
96 }
97  
98 0 croak 'Unknown error';
99 }
100  
101 0 ▶ if( !exists $response->{CheckNsStatus} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $response->{"CheckNsStatus"}) 0 0 0
102 0 croak 'Response did not contain private nameserver data';
103 }
104  
105 return WWW::eNom::PrivateNameServer->new(
106 name => $response->{CheckNsStatus}{name},
107 ip => $response->{CheckNsStatus}{ipaddress},
108 0 );
109 }
110 catch {
111 0 ▶ croak $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 0 };
113 }
114  
115 sub delete_private_nameserver {
116 0 ▶ my $self = shift;
Subroutine delete_private_nameserver: not called CC=1 SCAR=6.9
Pod documented
117 0 my ( %args ) = validated_hash(
118 \@_,
119 domain_name => { isa => DomainName },
120 private_nameserver_name => { isa => DomainName },
121 );
122  
123 return try {
124 # Prevent users from removing last private nameserver
125 0 ▶ my $domain = $self->get_domain_by_name( $args{domain_name} );
Subroutine __ANON__: not called CC=8 SCAR=42.8
126 0 ▶ if( scalar @{ $domain->ns } == 1 && $domain->ns->[0] eq $args{private_nameserver_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$domain->ns;} == 1 and $domain->ns->[0] eq $args{"private_nameserver_name"}) 0 0 0
Condition0%0/3
scalar @{$domain->ns;} == 1 and $domain->ns->[0] eq $args{"private_nameserver_name"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
127 0 croak 'Blocked deletion - Deleting this would leave this domain with no nameservers!';
128 }
129  
130 # Remove this private nameserver from the list of authoritative ones
131 # and let update_nameservers_for_domain_name handle the deletion.
132 0 ▶ if( grep { $_ eq $args{private_nameserver_name} } @{ $domain->ns } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $args{"private_nameserver_name"};} @{$domain->ns;}) 0 0 0
133 return $self->update_nameservers_for_domain_name(
134 domain_name => $domain->name,
135 0 ns => [ grep { $_ ne $args{private_nameserver_name} } @{ $domain->ns } ]
136 );
137 }
138  
139 my $response = $self->submit({
140 method => 'DeleteNameServer',
141 params => {
142 NS => $args{private_nameserver_name},
143 },
144 0 });
145  
146 0 ▶ if( $response->{ErrCount} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"ErrCount"} > 0) 0 0 0
147 0 ▶ if( grep {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "Nameserver registration failed due to error 545: Object does not exist";} @{$$response{"errors"};}) 0 0 0
148 0 $_ eq 'Nameserver registration failed due to error 545: Object does not exist'
149 0 } @{ $response->{errors} } ) {
150 0 croak 'Nameserver does not exist';
151 }
152  
153 0 ▶ if( ( grep { $_ eq 'Domain ID not found.' } @{ $response->{errors} } )
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};} or grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}) 0 0 0
Condition0%0/3
grep {$_ eq "Domain ID not found.";} @{$$response{"errors"};} or grep {$_ eq "Domain cannot be found.";} @{$$response{"errors"};}
l!l&&r!l&&!r
000
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"};}
ABresult
1X1
011
000
154 0 || ( grep { $_ eq 'Domain cannot be found.' } @{ $response->{errors} } ) ) {
155 0 croak 'Domain not found in your account';
156 }
157  
158 0 croak 'Unknown error';
159 }
160  
161 0 return;
162 }
163 catch {
164 0 ▶ croak $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
165 0 };
166 }
167  
168 44 1;
169  
170 __END__
171  
172 =head1 NAME
173  
174 WWW::eNom::Role::Command::Domain::PrivateNameServer - Domain Private Nameserver Operations
175  
176 =head1 SYNOPSIS
177  
178 =head1 REQUIRED
179  
180 =over 4
181  
182 =item submit
183  
184 =item get_domain_by_name
185  
186 =item update_nameservers_for_domain_name
187  
188 Needed in order to keep private nameservers synced with the authoritative ones.
189  
190 =back
191  
192 =head1 DESCRIPTION
193  
194 Implemented private name server operations with L<eNom|https://www.enom.com>'s API.
195  
196 =head1 LIMITATIONS
197  
198 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>.
199  
200 =head1 METHODS
201  
202 =head2 create_private_nameserver
203  
204 my $domain = WWW::eNom::Domain->new( ... );
205 my $private_nameserver = WWW::eNom::PrivateNameServer->new(
206 name => 'ns1.' . $domain->name,
207 ip => '4.2.2.1',
208 );
209  
210 my $updated_domain = $api->create_private_nameserver(
211 domain_name => $domain->name,
212 private_nameserver => $private_nameserver,
213 );
214  
215 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.
216  
217 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.
218  
219 =head2 retrieve_private_nameserver_by_name
220  
221 my $private_nameserver = $api->retrieve_private_nameserver_by_name( 'ns1.' . $domain->name );
222  
223 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.
224  
225 This method will croak if the domain is owned by someone else, if it's not registered, or if private nameserver does not exist.
226  
227 =head2 delete_private_nameserver
228  
229 $api->delete_private_nameserver(
230 domain_name => $domain->name,
231 private_nameserver_name => 'ns1.' . $domain->name,
232 );
233  
234 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>.
235  
236 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.
237  
238 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.
239  
240 =cut
« blib/lib/WWW/eNom/DomainRequest/Registration.pm ↑ Summary blib/lib/WWW/eNom/Contact.pm »