File Coverage

blib/lib/WWW/LogicBoxes/Role/Command/Domain/PrivateNameServer.pm
Criterion Covered Total %
statement 24 76 31.5
branch 0 30 0.0
condition 0 3 0.0
subroutine 8 23 34.7
pod 5 5 100.0
total 37 137 27.0


line stmt bran cond sub pod time code
1             package WWW::LogicBoxes::Role::Command::Domain::PrivateNameServer;
2              
3 38     38   529526 use strict;
  38         117  
  38         1352  
4 38     38   235 use warnings;
  38         100  
  38         1452  
5              
6 38     38   713 use Moose::Role;
  38         181767  
  38         358  
7 38     38   213305 use MooseX::Params::Validate;
  38         90515  
  38         378  
8              
9 38     38   19836 use WWW::LogicBoxes::Types qw( DomainName Int IP PrivateNameServer );
  38         109  
  38         430  
10              
11 38     38   404776 use WWW::LogicBoxes::PrivateNameServer;
  38         103  
  38         1056  
12              
13 38     38   216 use Try::Tiny;
  38         97  
  38         2323  
14 38     38   236 use Carp;
  38         121  
  38         50752  
15              
16             requires 'submit', 'get_domain_by_id';
17              
18             our $VERSION = '1.10.0'; # VERSION
19             # ABSTRACT: Domain Private Nameserver API Calls
20              
21             sub create_private_nameserver {
22 0     0 1   my $self = shift;
23 0           my ( $nameserver ) = pos_validated_list( \@_, { isa => PrivateNameServer, coerce => 1 } );
24              
25             return try {
26 0     0     $self->submit({
27             method => 'domains__add_cns',
28             params => {
29             'order-id' => $nameserver->domain_id,
30             'cns' => $nameserver->name,
31             'ip' => $nameserver->ips,
32             }
33             });
34              
35 0           return $self->get_domain_by_id( $nameserver->domain_id );
36             }
37             catch {
38 0 0   0     if( $_ =~ m/^No Entity found for Entityid/ ) {
    0          
39 0           croak 'No such domain';
40             }
41             elsif( $_ =~ m/This IpAddress already exists/ ) {
42 0           croak 'Nameserver with this IP Address already exists';
43             }
44              
45 0           croak $_;
46 0           };
47             }
48              
49             sub rename_private_nameserver {
50 0     0 1   my $self = shift;
51 0           my ( %args ) = validated_hash(
52             \@_,
53             domain_id => { isa => Int },
54             old_name => { isa => DomainName },
55             new_name => { isa => DomainName },
56             );
57              
58             return try {
59             $self->submit({
60             method => 'domains__modify_cns_name',
61             params => {
62             'order-id' => $args{domain_id},
63             'old-cns' => $args{old_name},
64             'new-cns' => $args{new_name},
65             }
66 0     0     });
67              
68 0           return $self->get_domain_by_id( $args{domain_id} );
69             }
70             catch {
71             ## no critic (ControlStructures::ProhibitCascadingIfElse RegularExpressions::ProhibitComplexRegexes)
72 0 0 0 0     if( $_ =~ m/^No Entity found for Entityid/ ) {
    0          
    0          
    0          
    0          
73 0           croak 'No such domain';
74             }
75             elsif( $_ =~ m/^Invalid Old Child NameServer. Its not registered nameserver for this domain/ ) {
76 0           croak 'No such existing private nameserver';
77             }
78             elsif( $_ =~ m/^Parent Domain for New child nameServer is not registered by us/
79             || $_ =~ m/^\{hostname=Parent DomainName is not registered by you\}/ ) {
80 0           croak 'Invalid domain for private nameserver';
81             }
82             elsif( $_ =~ m/^Same value for new and old Child NameServer/ ) {
83 0           croak 'Same value for old and new private nameserver name';
84             }
85             elsif( $_ =~ m/^\{hostname=Child NameServer already exists\}/ ) {
86 0           croak 'A nameserver with that name already exists';
87             }
88             ## use critic
89              
90 0           croak $_;
91 0           };
92             }
93              
94             sub modify_private_nameserver_ip {
95 0     0 1   my $self = shift;
96 0           my ( %args ) = validated_hash(
97             \@_,
98             domain_id => { isa => Int },
99             name => { isa => DomainName },
100             old_ip => { isa => IP },
101             new_ip => { isa => IP },
102             );
103              
104             return try {
105             $self->submit({
106             method => 'domains__modify_cns_ip',
107             params => {
108             'order-id' => $args{domain_id},
109             'cns' => $args{name},
110             'old-ip' => $args{old_ip},
111             'new-ip' => $args{new_ip},
112             }
113 0     0     });
114              
115 0           return $self->get_domain_by_id( $args{domain_id} );
116             }
117             catch {
118             ## no critic (ControlStructures::ProhibitCascadingIfElse RegularExpressions::ProhibitComplexRegexes)
119 0 0   0     if( $_ =~ m/^No Entity found for Entityid/ ) {
    0          
    0          
    0          
120 0           croak 'No such domain';
121             }
122             elsif( $_ =~ m/^Invalid Child Name Server. Its not registered nameserver for this domain/ ) {
123 0           croak 'No such existing private nameserver';
124             }
125             elsif( $_ =~ m/^Same value for new and old IpAddress/ ) {
126 0           croak 'Same value for old and new private nameserver ip';
127             }
128             elsif( $_ =~ m/^Invalid Old IpAddress. Its not attached to Nameserver/ ) {
129 0           croak 'Nameserver does not have specified ip';
130             }
131             ## use critic
132              
133 0           croak $_;
134 0           };
135             }
136              
137             sub delete_private_nameserver_ip {
138 0     0 1   my $self = shift;
139 0           my ( %args ) = validated_hash(
140             \@_,
141             domain_id => { isa => Int },
142             name => { isa => DomainName },
143             ip => { isa => IP },
144             );
145              
146             return try {
147             $self->submit({
148             method => 'domains__delete_cns_ip',
149             params => {
150             'order-id' => $args{domain_id},
151             'cns' => $args{name},
152             'ip' => $args{ip},
153             }
154 0     0     });
155              
156 0           return $self->get_domain_by_id( $args{domain_id} );
157             }
158             catch {
159             ## no critic (ControlStructures::ProhibitCascadingIfElse RegularExpressions::ProhibitComplexRegexes)
160 0 0   0     if( $_ =~ m/^No Entity found for Entityid/ ) {
    0          
    0          
161 0           croak 'No such domain';
162             }
163             elsif( $_ =~ m/^Invalid Child Name Server. Its not registered nameserver for this domain/ ) {
164 0           croak 'No such existing private nameserver';
165             }
166             elsif( $_ =~ m/^\{ipaddress1=Invalid IpAddress .* Its not attached to Nameserver\}/ ) {
167 0           croak 'IP address not assigned to private nameserver';
168             }
169             ## use critic
170              
171 0           croak $_;
172 0           };
173             }
174              
175             sub delete_private_nameserver {
176 0     0 1   my $self = shift;
177 0           my ( $nameserver ) = pos_validated_list( \@_, { isa => PrivateNameServer, coerce => 1 } );
178              
179             return try {
180 0     0     for my $ip (@{ $nameserver->ips } ) {
  0            
181 0           $self->delete_private_nameserver_ip(
182             domain_id => $nameserver->domain_id,
183             name => $nameserver->name,
184             ip => $ip,
185             );
186             }
187              
188 0           return $self->get_domain_by_id( $nameserver->domain_id );
189             }
190             catch {
191 0 0   0     if( $_ =~ m/^No Entity found for Entityid/ ) {
192 0           croak 'No such domain';
193             }
194              
195 0           croak $_;
196 0           };
197             }
198              
199             1;
200              
201             __END__
202             =pod
203              
204             =head1 NAME
205              
206             WWW::LogicBoxes::Role::Command::Domain::PrivateNameServer - Private Nameserver Related Operations
207              
208             =head1 SYNOPSIS
209              
210             use WWW::LogicBoxes;
211             use WWW::LogicBoxes::Domain;
212             use WWW::LogicBoxes::PrivateNameServer;
213              
214             my $logic_boxes = WWW::LogicBoxes->new( ... );
215             my $domain = WWW::LogicBoxes::Domain->new( ... );
216              
217             # Creation
218             my $private_nameserver = WWW::LogicBoxes::PrivateNameServer->new(
219             domain_id => $domain->id,
220             name => 'ns1.' . $domain->name,
221             ips => [ '4.2.2.1' ],
222             );
223              
224             $logic_boxes->create_private_nameserver( $private_nameserver );
225              
226             # Rename
227             $logic_boxes->rename_private_nameserver(
228             domain_id => $domain->id,
229             old_name => 'ns1.' . $domain->name,
230             new_name => 'ns2.' . $domain->name,
231             );
232              
233             # Modify IP
234             $logic_boxes->modify_private_nameserver_ip(
235             domain_id => $domain->id,
236             name => 'ns1.' . $domain->name,
237             old_ip => '4.2.2.1',
238             new_ip => '8.8.8.8',
239             );
240              
241             # Delete IP
242             $logic_boxes->delete_private_nameserver_ip(
243             domain_id => $domain->id,
244             name => 'ns1.' . $domain->name,
245             ip => '4.2.2.1',
246             );
247              
248             # Delete Private Nameserver
249             my $private_nameserver = WWW::LogicBoxes::PrivateNameServer->new( ... );
250             $logic_boxes->delete_private_nameserver( $private_nameserver )
251              
252             =head1 REQUIRES
253              
254             =over 4
255              
256             =item submit
257              
258             =item get_domain_by_id
259              
260             =back
261              
262             =head1 DESCRIPTION
263              
264             Implementes Private Nameserver related operations (what L<LogicBoxes|http://www.logicboxes.com> refers to as "Child Nameservers") with the L<LogicBoxes|http://www.logicboxes.com> API.
265              
266             B<NOTE> All private nameservers must be a subdomain of the parent domain. If the domain name is test-domain.com, ns1.test-domain.com would be valid while ns1.something-else.com would not be.
267              
268             =head1 METHOD
269              
270             =head2 create_private_nameserver
271              
272             use WWW::LogicBoxes;
273             use WWW::LogicBoxes::Domain;
274             use WWW::LogicBoxes::PrivateNameServer;
275              
276             my $logic_boxes = WWW::LogicBoxes->new( ... );
277             my $domain = WWW::LogicBoxes::Domain->new( ... );
278              
279             my $private_nameserver = WWW::LogicBoxes::PrivateNameServer->new(
280             domain_id => $domain->id,
281             name => 'ns1.' . $domain->name,
282             ips => [ '4.2.2.1', '2001:4860:4860:0:0:0:0:8888' ],
283             );
284              
285             $logic_boxes->create_private_nameserver( $private_nameserver );
286              
287             Given a L<WWW::LogicBoxes::PrivateNameServer> or a HashRef that can be coerced into a L<WWW::LogicBoxes::PrivateNameServer>, creates the specified private nameserver with L<LogicBoxes|http://www.logicboxes.com>.
288              
289             =head2 rename_private_nameserver
290              
291             use WWW::LogicBoxes;
292             use WWW::LogicBoxes::Domain;
293              
294             my $domain = WWW::LogicBoxes::Domain->new( ... );
295              
296             $logic_boxes->rename_private_nameserver(
297             domain_id => $domain->id,
298             old_name => 'ns1.' . $domain->name,
299             new_name => 'ns2.' . $domain->name,
300             );
301              
302             Given an Integer L<domain|WWW::LogicBoxes::Domain> id, the old nameserver hostname, and a new nameserver hostname, renames a L<WWW::LogicBoxes::PrivateNameServer>.
303              
304             =head2 modify_private_nameserver_ip
305              
306             use WWW::LogicBoxes;
307             use WWW::LogicBoxes::Domain;
308              
309             my $domain = WWW::LogicBoxes::Domain->new( ... );
310              
311             $logic_boxes->modify_private_nameserver_ip(
312             domain_id => $domain->id,
313             name => 'ns1.' . $domain->name,
314             old_ip => '4.2.2.1',
315             new_ip => '2001:4860:4860:0:0:0:0:8888',
316             );
317              
318             Given an Integer L<domain|WWW::LogicBoxes::Domain> id, nameserver hostname, an old_ip (that is currently assigned to the L<private nameserver|WWW::LogicBoxes::PrivateNameServer>), and a new_ip, modifies the ips assoicated with a L<WWW::LogicBoxes::PrivateNameServer>.
319              
320             =head2 delete_private_nameserver_ip
321              
322             use WWW::LogicBoxes;
323             use WWW::LogicBoxes::Domain;
324              
325             my $domain = WWW::LogicBoxes::Domain->new( ... );
326              
327             $logic_boxes->delete_private_nameserver_ip(
328             domain_id => $domain->id,
329             name => 'ns1.' . $domain->name,
330             ip => '4.2.2.1', # Or an IPv4 Address
331             );
332              
333             Given an Integer L<domain|WWW::LogicBoxes::Domain> id, nameserver hostname, and an ip (that is currently assigned to the L<private nameserver|WWW::LogicBoxes::PrivateNameServer>), removes the ip assoicated with a L<WWW::LogicBoxes::PrivateNameServer>.
334              
335             =head2 delete_private_nameserver
336              
337             use WWW::LogicBoxes;
338             use WWW::LogicBoxes::Domain;
339             use WWW::LogicBoxes::PrivateNameServer;
340              
341             my $domain = WWW::LogicBoxes::Domain->new( ... );
342              
343             my $private_nameserver = WWW::LogicBoxes::PrivateNameServer->new( ... );
344             $logic_boxes->delete_private_nameserver( $private_nameserver )
345              
346              
347             Given a L<WWW::LogicBoxes::PrivateNameServer> or a HashRef that can be coerced into a L<WWW::LogicBoxes::PrivateNameServer>, deletes the specified private nameserver with L<LogicBoxes|http://www.logicboxes.com>.
348              
349             =cut