Codeguard/User.pm

filter: Statementstmt 23.2% 37 / 159 Branchbran 7.6% 2 / 26 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 28.8% 13 / 45 Podpod 96.8% 31 / 32 totaltotal 28.6% 83 / 290 SCAR 57.1
CC
23
Cov
19%
_fetch_required_params
90.0
_set_uri
56.0
enable_website
6.0
CRAP 301.9
« Codeguard.pm ↑ Summary Codeguard/Partner.pm »
1 package WWW::Codeguard::User;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings FATAL => 'all', NONFATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use parent qw(WWW::Codeguard);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use JSON qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Net::OAuth;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 WWW::Codeguard::User - Perl interface to interact with the Codeguard API as a 'user'
16  
17 =cut
18  
19 =head1 SYNOPSIS
20  
21 This module provides you with an perl interface to interact with the Codeguard API and perform the 'user' level calls.
22  
23 use WWW::Codeguard::User;
24  
25 my $api = WWW::Codeguard::User->new(
26 $api_url,
27 {
28 api_secret => $user_api_secret,
29 api_key => $user_api_key,
30 access_secret => $user_access_secret,
31 access_token => $user_access_token,
32 verify_hostname => 1,
33 }
34 );
35  
36 =cut
37  
38 sub new {
39  
40 2 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
41 2 my $self = {};
42 2 bless $self, $class;
43 2 $self->_initialize(@_);
44 2 return $self;
45 }
46  
47 sub _initialize {
48  
49 2 ▶ my ($self, $api_url, $opts) = @_;
Subroutine _initialize: called CC=4 SCAR=14.2
50  
51 2 $self->{api_url} = $api_url;
52 2 foreach my $key (qw(api_secret api_key access_secret access_token)) {
53 8 ▶ $self->{$key} = delete $opts->{$key} or $self->_error($key.' is a required parameter', 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{$key} = delete $opts->{$key} or $self->_error($key . ' is a required parameter', 1) 0 8 8
54 }
55  
56 # initialize the UA
57 $self->{_ua} = LWP::UserAgent->new(
58 agent => 'WWW-Codeguard-User '.$self->VERSION(),
59 max_redirect => 0,
60 ssl_opts => {
61 2 ▶ verify_hostname => (exists $opts->{verify_hostname}? $opts->{verify_hostname} : 1),
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'verify_hostname'} ? : 0 2 2
62 },
63 );
64  
65 2 return $self;
66 }
67  
68 =head1 METHODS
69  
70 Each of these map to a call on Codeguard's User API.
71  
72 =cut
73  
74 =head2 create_website
75  
76 This allows you to create a website resource under your User account. Params should be a hashref that contains the following attributes:
77  
78 Required: The request will not succeed without these attributes.
79  
80 url
81 hostname
82 account
83 password or key
84 provider
85  
86 Optional:
87  
88 dir_path
89 port
90  
91 =cut
92  
93 sub create_website {
94  
95 0 ▶ my ($self, $params) = @_;
Subroutine create_website: not called CC=1 SCAR=6.9
Pod documented
96 0 return $self->_do_method('create_website', $params);
97 }
98  
99 =head2 list_websites
100  
101 This allows you to list the website resources under your User account. Params should be a hashref that contains the following attributes:
102  
103 Required:
104  
105 None
106  
107 Optional:
108  
109 None
110  
111 =cut
112  
113 sub list_websites {
114  
115 0 ▶ my ($self, $params) = @_;
Subroutine list_websites: not called CC=1 SCAR=6.9
Pod documented
116 0 return $self->_do_method('list_websites', $params);
117 }
118  
119 =head2 list_website_rules
120  
121 This allows you to list the exclusion rules for a website resource under your User account. Params should be a hashref that contains the following attributes:
122  
123 Required:
124  
125 website_id
126  
127 Optional:
128  
129 None
130  
131 =cut
132  
133 sub list_website_rules {
134  
135 0 ▶ my ($self, $params) = @_;
Subroutine list_website_rules: not called CC=1 SCAR=6.9
Pod documented
136 0 return $self->_do_method('list_website_rules', $params);
137 }
138  
139 =head2 set_website_rules
140  
141 This allows you to set the exclusion rules for a website resource under your User account. Params should be a hashref that contains the following attributes:
142  
143 Required:
144  
145 website_id
146 exclude_rules - must be an array ref with elements specifying what paths/files to ignore. Example:
147 [
148 'access-logs/*'
149 '*error_log*'
150 '*stats/*'
151 '/path/to/a/folder/*'
152 '/path/to/a/file.txt'
153 ]
154  
155 Optional:
156  
157 None
158  
159 =cut
160  
161 sub set_website_rules {
162  
163 0 ▶ my ($self, $params) = @_;
Subroutine set_website_rules: not called CC=1 SCAR=6.9
Pod documented
164 0 return $self->_do_method('set_website_rules', $params);
165 }
166  
167 =head2 edit_website
168  
169 This allows you to edit information for the specified website resource under your User account. Params should be a hashref that contains the following attributes:
170  
171 Required:
172  
173 website_id
174  
175 Optional:
176  
177 url
178 monitor_frequency
179 account
180 password or key
181 dir_path
182 hostname
183 disabled
184  
185 =cut
186  
187 sub edit_website {
188  
189 0 ▶ my ($self, $params) = @_;
Subroutine edit_website: not called CC=1 SCAR=6.9
Pod documented
190 0 return $self->_do_method('edit_website', $params);
191 }
192  
193 =head2 delete_website
194  
195 This allows you to delete the specified website resource under your User account. Params should be a hashref that contains the following attributes:
196  
197 Required:
198  
199 website_id
200  
201 Optional:
202  
203 None
204  
205 =cut
206  
207 sub delete_website {
208  
209 0 ▶ my ($self, $params) = @_;
Subroutine delete_website: not called CC=1 SCAR=6.9
Pod documented
210 0 return $self->_do_method('delete_website', $params);
211 }
212  
213 =head2 enable_website
214  
215 This allows you to enable a specified website resource under your User account. Params should be a hashref that contains the following attributes:
216  
217 Required:
218  
219 website_id
220  
221 Optional:
222  
223 None
224  
225 =cut
226  
227 sub enable_website {
228  
229 0 ▶ my ($self, $params) = @_;
Subroutine enable_website: not called CC=2 SCAR=17.9
Pod documented
230 my $real_params = {
231 0 ▶ UNIVERSAL::isa($params, 'HASH') ? ( website_id => $params->{website_id} ) : (),
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($params, 'HASH') ? : 0 0 0
232 };
233  
234 0 $real_params->{disabled} = JSON::false;
235 0 return $self->_do_method('edit_website', $real_params);
236 }
237  
238 =head2 disable_website
239  
240 This allows you to disable a specified website resource under your User account. Params should be a hashref that contains the following attributes:
241  
242 Required:
243  
244 website_id
245  
246 Optional:
247  
248 None
249  
250 =cut
251  
252 sub disable_website {
253  
254 0 ▶ my ($self, $params) = @_;
Subroutine disable_website: not called CC=2 SCAR=17.9
Pod documented
255 0 ▶ $self->_sanitize_params('edit_website', $params) or
Branch: 1 branch
BranchTrueFalseTotal
$self->_sanitize_params("edit_website", $params) or $self->_error('Failed to sanitize params: "' . $self->get_error . '" - The parameters passed in were: ' . "\n" . $self->_stringify_hash($params), 1) 0 0 0
256 $self->_error('Failed to sanitize params: "'.$self->get_error.'" - The parameters passed in were: '."\n".$self->_stringify_hash($params), 1);
257 0 $params->{disabled} = JSON::true;
258 0 return $self->_do_method('edit_website', $params);
259 }
260  
261 =head2 create_database
262  
263 This allows you to create a database resource under your User account. Params should be a hashref that contains the following attributes:
264  
265 Required:
266  
267 server_address - MySQL Database Hostname or IP address.
268 account - MySQL username which has access to the database_name database.
269 password - MySQL password associated with account.
270 Note: This parameter is only used during the create action. It is never returned by other API requests.
271 port - MySQL server port number for use with the server_name.
272 database_name - The name of the target database.
273  
274 Optional:
275  
276 website_id - Numeric ID of the parent Website record.
277 If no website_id is provided, the Database will not be associated with any website resource.
278  
279 B<Experimental features>: SSH functionality for DB backups is currently not fully functional on CodeGuard's side, and as such might not function as expected.
280  
281 authentication_mode - This can be one of two values: 'direct' or 'ssh'.
282 The direct method will attempt to open a connection using a MySQL client on the specified server and port.
283 The ssh method will create an SSH tunnel through server_name using the server_account and
284 server_password credentials to connect to the database on server_name.
285  
286 server_account - SSH username on server_address. Note: This field is only valid if the authenticationmode is ssh.
287 Note: Required if authentication_mode is 'ssh'.
288  
289 server_password - SSH password associated with server_account.
290 Note: Required if authentication_mode is 'ssh'.
291  
292 =cut
293  
294 sub create_database {
295  
296 0 ▶ my ($self, $params) = @_;
Subroutine create_database: not called CC=1 SCAR=6.9
Pod documented
297 0 return $self->_do_method('create_database', $params);
298 }
299  
300 =head2 list_databases
301  
302 This allows you to fetch all Database Records owned by the user.
303  
304 Required:
305  
306 None
307  
308 Optional:
309  
310 None
311  
312 =cut
313  
314 sub list_databases {
315  
316 0 ▶ my ($self, $params) = @_;
Subroutine list_databases: not called CC=1 SCAR=6.9
Pod documented
317 0 return $self->_do_method('list_databases', $params);
318 }
319  
320 =head2 show_database
321  
322 This allows you to fetch information for the specified database resource under your User account. Params should be a hashref that contains the following attributes:
323  
324 Required:
325  
326 database_id
327  
328 Optional:
329  
330 None
331  
332 =cut
333  
334 sub show_database {
335  
336 0 ▶ my ($self, $params) = @_;
Subroutine show_database: not called CC=1 SCAR=6.9
Pod documented
337 0 return $self->_do_method('show_database', $params);
338 }
339  
340 =head2 edit_database
341  
342 This allows you to edit information for the specified database resource under your User account. Params should be a hashref that contains the following attributes:
343  
344 Required:
345  
346 database_id
347  
348 Optional:
349  
350 website_id
351 server_address
352 account
353 password
354 port
355 database_name
356 authentication_mode
357 server_account
358 server_password
359 disabled
360  
361 =cut
362  
363 sub edit_database {
364  
365 0 ▶ my ($self, $params) = @_;
Subroutine edit_database: not called CC=1 SCAR=6.9
Pod documented
366 0 return $self->_do_method('edit_database', $params);
367 }
368  
369 =head2 delete_database
370  
371 This allows you to delete the specified database resource under your User account. Params should be a hashref that contains the following attributes:
372  
373 Required:
374  
375 database_id
376  
377 Optional:
378  
379 None
380  
381 =cut
382  
383 sub delete_database {
384  
385 0 ▶ my ($self, $params) = @_;
Subroutine delete_database: not called CC=1 SCAR=6.9
Pod documented
386 0 return $self->_do_method('delete_database', $params);
387 }
388  
389 =head2 enable_database
390  
391 This allows you to enable a specified database resource under your User account. Params should be a hashref that contains the following attributes:
392  
393 Required:
394  
395 database_id
396  
397 Optional:
398  
399 None
400  
401 =cut
402  
403 sub enable_database {
404  
405 0 ▶ my ($self, $params) = @_;
Subroutine enable_database: not called CC=2 SCAR=17.9
Pod documented
406 my $real_params = {
407 0 ▶ UNIVERSAL::isa($params, 'HASH') ? ( database_id => $params->{database_id} ) : (),
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($params, 'HASH') ? : 0 0 0
408 };
409  
410 0 $real_params->{disabled} = JSON::false;
411 0 return $self->_do_method('edit_database', $real_params);
412 }
413  
414 =head2 disable_database
415  
416 This allows you to disable a specified database resource under your User account. Params should be a hashref that contains the following attributes:
417  
418 Required:
419  
420 database_id
421  
422 Optional:
423  
424 None
425  
426 =cut
427  
428 sub disable_database {
429  
430 0 ▶ my ($self, $params) = @_;
Subroutine disable_database: not called CC=2 SCAR=17.9
Pod documented
431 my $real_params = {
432 0 ▶ UNIVERSAL::isa($params, 'HASH') ? ( database_id => $params->{database_id} ) : (),
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($params, 'HASH') ? : 0 0 0
433 };
434  
435 0 $real_params->{disabled} = JSON::true;
436 0 return $self->_do_method('edit_database', $real_params);
437 }
438  
439 =head2 create_website_backup
440  
441 Will initiate an on-demand backup for a Website.
442  
443 Required:
444  
445 website_id - Id of the Website to create a backup for.
446  
447 Optional:
448  
449 None
450  
451 =cut
452  
453 sub create_website_backup {
454  
455 0 ▶ my ($self, $params) = @_;
Subroutine create_website_backup: not called CC=1 SCAR=6.9
Pod documented
456 0 return $self->_do_method('create_website_backup', $params);
457 }
458  
459 =head2 restore_website_backup
460  
461 Will initiate a full restore for a Website.
462  
463 Required:
464  
465 website_id - Id of the Website to perform restore on.
466 commit_id - The commit to restore the website from.
467  
468 Optional:
469  
470 None
471  
472 =cut
473  
474 sub restore_website_backup {
475  
476 0 ▶ my ($self, $params) = @_;
Subroutine restore_website_backup: not called CC=1 SCAR=6.9
Pod documented
477 0 return $self->_do_method('restore_website_backup', $params)
478 }
479  
480 =head2 selective_restore_website_backup
481  
482 Will initiate a restore of the specified files and directories for a Website.
483  
484 Required:
485  
486 website_id - Id of the Website to perform the restore on.
487 commit_id - The commit to restore files from.
488 paths - A list of paths to restore.
489  
490 Optional:
491  
492 None
493  
494 =cut
495  
496 sub selective_restore_website_backup {
497  
498 0 ▶ my ($self, $params) = @_;
Subroutine selective_restore_website_backup: not called CC=1 SCAR=6.9
Pod documented
499 0 return $self->_do_method('selective_restore_website_backup', $params)
500 }
501  
502 =head2 archive_website_backup
503  
504 Will initiate the production of a zip file which contains the entire contents of the selected backup. Upon completion a perishable link will be provided to the customer so that they can retrieve the zip file. The links expire after 1 week.
505  
506 Required:
507  
508 website_id - Id of the Website to download the file for.
509 commit_id - The commit to create the zip file from.
510  
511 Optional:
512  
513 None
514  
515 =cut
516  
517 sub archive_website_backup {
518  
519 0 ▶ my ($self, $params) = @_;
Subroutine archive_website_backup: not called CC=1 SCAR=6.9
Pod documented
520 0 return $self->_do_method('download_website_backup', $params);
521 }
522  
523 =head2 archive_website_selective_backup
524  
525 Will initiate the production of a zip file which contains the the specified files and directories. Upon completion a perishable link will be provided to the customer so that they can retrieve the zip file. The links expire after 1 week.
526  
527 Required:
528  
529 website_id - Id of the Website to download the file for.
530 commit_id - The commit to create the zip file from.
531 paths - A list of paths to include in the archive.
532  
533 Optional:
534  
535 None
536  
537 =cut
538  
539 sub archive_website_selective_backup {
540  
541 0 ▶ my ($self, $params) = @_;
Subroutine archive_website_selective_backup: not called CC=1 SCAR=6.9
Pod documented
542 0 return $self->_do_method('download_selective_website_backup', $params);
543 }
544  
545 =head2 list_website_backups
546  
547 List all of the backups for a Website.
548  
549 Required:
550  
551 website_id - Id of the Website to list the backups for.
552  
553 Optional:
554  
555 None
556  
557 =cut
558  
559 sub list_website_backups {
560  
561 0 ▶ my ($self, $params) = @_;
Subroutine list_website_backups: not called CC=1 SCAR=6.9
Pod documented
562 0 return $self->_do_method('list_website_backups', $params);
563 }
564  
565 =head2 browse_website_backup
566  
567 Response includes files, directories and their associated metadata as an array of entries.
568 Requests can be scoped to an optional C<path> parameter.
569  
570 Required:
571  
572 website_id - Id of the Website to brose the backup of.
573 commit_id - The commit to brwose the contents of.
574  
575 Optional:
576  
577 path - scopes the results to this path within the backup.
578  
579 =cut
580  
581 sub browse_website_backup {
582  
583 0 ▶ my ($self, $params) = @_;
Subroutine browse_website_backup: not called CC=1 SCAR=6.9
Pod documented
584 0 return $self->_do_method('browse_website_backup', $params);
585 }
586  
587  
588 =head2 list_website_database_backup_commits
589  
590 List all backups of the database associated with selected website backup commit_id.
591  
592 Required:
593  
594 website_id - Id of the Website associated with the database to list backups for.
595 commit_id - The website backup commit to retrieve associated database backups for.
596  
597 Optional:
598  
599 None
600  
601 =cut
602  
603 sub list_website_database_backup_commits {
604  
605 0 ▶ my ($self, $params) = @_;
Subroutine list_website_database_backup_commits: not called CC=1 SCAR=6.9
Pod documented
606 0 return $self->_do_method('list_website_database_backup_commits', $params);
607 }
608  
609  
610 =head2 create_database_backup
611  
612 Will initiate an on-demand backup for a Database.
613  
614 Required:
615  
616 website_id - Id of the Website associated with the database to create a backup for.
617 database_id - Id of the Database to create a backup for.
618  
619 Optional:
620  
621 None
622  
623 =cut
624  
625 sub create_database_backup {
626  
627 0 ▶ my ($self, $params) = @_;
Subroutine create_database_backup: not called CC=1 SCAR=6.9
Pod documented
628 0 return $self->_do_method('create_database_backup', $params);
629 }
630  
631 =head2 restore_database_backup
632  
633 Will initiate a full restore for a Database.
634  
635 Required:
636  
637 website_id - Id of the Website associated with the database to restore.
638 database_id - Id of the Database to restore a backup for.
639 commit_id - The commit to restore the database from.
640  
641 Optional:
642  
643 None
644  
645 =cut
646  
647 sub restore_database_backup {
648  
649 0 ▶ my ($self, $params) = @_;
Subroutine restore_database_backup: not called CC=1 SCAR=6.9
Pod documented
650 0 return $self->_do_method('restore_database_backup', $params);
651 }
652  
653 =head2 list_database_backups
654  
655 List all the bacukps for a Database.
656  
657 Required:
658  
659 website_id - Id of the Website associated with the requested database.
660 database_id - Id of the Database to list the backups for.
661  
662 Optional:
663  
664 None
665  
666 =cut
667  
668 sub list_database_backups {
669  
670 0 ▶ my ($self, $params) = @_;
Subroutine list_database_backups: not called CC=1 SCAR=6.9
Pod documented
671 0 return $self->_do_method('list_database_backups', $params);
672 }
673  
674 =head2 generate_login_link
675  
676 This creates a login URL that can be used to access the Codeguard Dashboard for your User account.
677  
678 Required:
679  
680 None
681  
682 Optional:
683  
684 None
685  
686 =cut
687  
688 sub generate_login_link {
689  
690 0 ▶ my $self = shift;
Subroutine generate_login_link: not called CC=1 SCAR=6.9
Pod documented
691 0 return $self->_set_uri('list_websites');
692 }
693  
694 =head1 Accessors
695  
696 Basic accessor methods to retrieve the current settings
697  
698 =cut
699  
700 =head2 get_api_secret
701  
702 Returns the current value in $self->{api_secret}.
703  
704 =cut
705  
706 1 ▶sub get_api_secret { shift->{api_secret}; }
Subroutine get_api_secret: called CC=1 SCAR=0.0
Pod documented
707  
708 =head2 get_api_key
709  
710 Returns the current value in $self->{api_key}.
711  
712 =cut
713  
714 1 ▶sub get_api_key { shift->{api_key}; }
Subroutine get_api_key: called CC=1 SCAR=0.0
Pod documented
715  
716 =head2 get_access_secret
717  
718 Returns the current value in $self->{access_secret}.
719  
720 =cut
721  
722 1 ▶sub get_access_secret { shift->{access_secret}; }
Subroutine get_access_secret: called CC=1 SCAR=0.0
Pod documented
723  
724 =head2 get_access_token
725  
726 Returns the current value in $self->{access_token}.
727  
728 =cut
729  
730 1 ▶sub get_access_token { shift->{access_token}; }
Subroutine get_access_token: called CC=1 SCAR=0.0
Pod documented
731  
732 # Internal Methods
733  
734 sub _create_request {
735  
736 0 ▶ my ($self, $action, $params) = @_;
Subroutine _create_request: not called CC=1 SCAR=6.9
737 0 my $action_map = {
738 'create_website' => 'POST',
739 'list_websites' => 'GET',
740 'edit_website' => 'PUT',
741 'delete_website' => 'DELETE',
742 'list_website_rules' => 'GET',
743 'set_website_rules' => 'POST',
744 'create_database' => 'POST',
745 'list_databases' => 'GET',
746 'show_database' => 'GET',
747 'edit_database' => 'PUT',
748 'delete_database' => 'DELETE',
749 'create_website_backup' => 'POST',
750 'restore_website_backup' => 'POST',
751 'selective_restore_website_backup' => 'POST',
752 'download_website_backup' => 'GET',
753 'download_selective_website_backup' => 'POST',
754 'list_website_backups' => 'GET',
755 'browse_website_backup' => 'GET',
756 'list_website_database_backup_commits' => 'GET',
757 'create_database_backup' => 'POST',
758 'restore_database_backup' => 'POST',
759 'list_database_backups' => 'GET',
760 };
761 0 my $request = HTTP::Request->new( $action_map->{$action} );
762 0 $request->header('Content-Type' => 'application/json' );
763 0 $self->_set_uri($action, $request, $params);
764 0 $self->_set_content($request, $params);
765 0 return $request;
766 }
767  
768 sub _set_uri {
769  
770 0 ▶ my ($self, $action, $request, $params) = @_;
Subroutine _set_uri: not called CC=7 SCAR=40.3
771 0 my $base_url = $self->get_api_url();
772  
773 0 ▶ my $website_id = $params->{website_id} || '';
Condition0%0/2
$params->{'website_id'} || ''
l!l
00
MC/DC0%0/1
$params->{'website_id'} || ''
$params->{'website_id'}
Truth table0%0/2
A
A= $params->{'website_id'}
Aresult
11
00
774 0 ▶ my $database_id = $params->{database_id} || '';
Condition0%0/2
$params->{'database_id'} || ''
l!l
00
MC/DC0%0/1
$params->{'database_id'} || ''
$params->{'database_id'}
Truth table0%0/2
A
A= $params->{'database_id'}
Aresult
11
00
775 0 ▶ my $commit_id = $params->{commit_id} || '';
Condition0%0/2
$params->{'commit_id'} || ''
l!l
00
MC/DC0%0/1
$params->{'commit_id'} || ''
$params->{'commit_id'}
Truth table0%0/2
A
A= $params->{'commit_id'}
Aresult
11
00
776  
777 0 my $uri_map = {
778 'create_website' => '/websites',
779 'list_websites' => '/websites',
780 'edit_website' => "/websites/$website_id",
781 'delete_website' => "/websites/$website_id",
782 'list_website_rules' => "/websites/$website_id/rules",
783 'set_website_rules' => "/websites/$website_id/rules",
784 'create_database' => '/database_backups',
785 'list_databases' => '/database_backups',
786 'show_database' => "/database_backups/$database_id",
787 'edit_database' => "/database_backups/$database_id",
788 'delete_database' => "/database_backups/$database_id",
789 'create_website_backup' => "/websites/$website_id/request_backup",
790 'restore_website_backup' => "/websites/$website_id/commits/$commit_id/initiate_restore",
791 'selective_restore_website_backup' => "/websites/$website_id/commits/$commit_id/restore_selected",
792 'download_website_backup' => "/websites/$website_id/commits/$commit_id/download",
793 'download_selective_website_backup' => "/websites/$website_id/commits/$commit_id/download_selected",
794 'list_website_backups' => "/websites/$website_id/commits",
795 'browse_website_backup' => "/websites/$website_id/commits/$commit_id/browse",
796 'list_website_database_backup_commits' => "/websites/$website_id/commits/$commit_id/database_backup_commits",
797 'create_database_backup' => "/websites/$website_id/database_backups/$database_id/request_backup",
798 'restore_database_backup' => "/websites/$website_id/database_backups/$database_id/commits/$commit_id/initiate_restore",
799 'list_database_backups' => "/websites/$website_id/database_backups/$database_id/commits",
800 };
801  
802 0 ▶ my $method = ($request) ? $request->method : 'GET';
Branch: 1 branch
BranchTrueFalseTotal
$request ? : 0 0 0
803 my $oauth_params = {
804 # Include our parameters in the query if our method is GET
805 ($method eq 'GET' ? (extra_params => $params) : ()),
806 'consumer_key' => $self->{api_key},
807 'consumer_secret' => $self->{api_secret},
808 'token' => $self->{access_token},
809 'token_secret' => $self->{access_secret},
810 'signature_method' => 'HMAC-SHA1',
811 'timestamp' => time(),
812 'nonce' => _oauth_nonce(),
813 'request_method' => $method,
814 0 ▶ 'request_url' => $base_url.$uri_map->{$action},
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'GET' ? : 0 0 0
815 };
816  
817 0 my $oauth_req = Net::OAuth->request('protected resource')->new(%$oauth_params);
818 0 $oauth_req->sign;
819 0 ▶ return ($request) ? $request->uri($oauth_req->to_url) : $oauth_req->to_url;
Branch: 1 branch
BranchTrueFalseTotal
$request ? : 0 0 0
820 }
821  
822 sub _fetch_required_params {
823  
824 0 ▶ my ($self, $action, $params) = @_;
Subroutine _fetch_required_params: not called CC=9 SCAR=45.0
825 my $required_keys_map = {
826 0 create_website => { map { ($_ => 1) } qw(url hostname account provider) },
827 list_websites => { },
828 0 list_website_rules => { map { ($_ => 1) } qw(website_id) },
829 0 set_website_rules => { map { ($_ => 1) } qw(website_id exclude_rules) },
830 0 create_database => { map { ($_ => 1) } qw(server_address account password port database_name) },
831 list_databases => { },
832 0 show_database => { map { ($_ => 1) } qw(database_id) }, # Added in v0.03.
833 0 edit_database => { map { ($_ => 1) } qw(database_id) },
834 0 create_website_backup => { map { ($_ => 1) } qw(website_id) },
835 0 restore_website_backup => { map { ($_ => 1) } qw(website_id commit_id) },
836 0 selective_restore_website_backup => { map { ($_ => 1) } qw(website_id commit_id paths) },
837 0 download_website_backup => { map { ($_ => 1) } qw(website_id commit_id) },
838 0 download_selective_website_backup => { map { ($_ => 1) } qw(website_id commit_id paths) },
839 0 list_website_backups => { map { ($_ => 1) } qw(website_id) },
840 0 browse_website_backup => { map { ($_ => 1) } qw(website_id commit_id) },
841 0 list_website_database_backup_commits => { map { ($_ => 1) } qw(website_id commit_id) },
842 0 create_database_backup => { map { ($_ => 1) } qw(website_id database_id) },
843 0 restore_database_backup => { map { ($_ => 1) } qw(website_id database_id commit_id) },
844 0 list_database_backups => { map { ($_ => 1) } qw(website_id database_id) },
845 };
846  
847 # The 'edit_website', and 'delete_website' calls have the same set of required params as the 'list_website_rules' call
848 0 $required_keys_map->{edit_website} = $required_keys_map->{delete_website} = $required_keys_map->{list_website_rules};
849  
850 # The 'delete_database' call has the same set of required params as the 'edit_database' call
851 0 $required_keys_map->{delete_database} = $required_keys_map->{edit_database};
852  
853 # if action is 'create_website',
854 # then we check the $params
855 # and mark either 'password' or 'key' as the required param.
856 0 ▶ if ($action eq 'create_website') {
Branch: 2 branches
BranchTrueFalseTotal
if ($action eq 'create_website') { } 0 0 0
elsif ($action eq 'create_database' and (exists $params->{'authentication_mode'} and $params->{'authentication_mode'} eq 'ssh')) { } 0 0 0
857 0 ▶ if (exists $params->{key} and $params->{key}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $params->{'key'} and $params->{'key'}) { } 0 0 0
elsif (exists $params->{'password'} and $params->{'password'}) { } 0 0 0
Condition0%0/3
exists $params->{"key"} and $params->{"key"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $params->{"key"} and $params->{"key"}
exists $params->{"key"} $params->{"key"}
Truth table0%0/3
A and B
A= exists $params->{"key"}B= $params->{"key"}
ABresult
0X0
100
111
858 0 $required_keys_map->{create_website}->{key} = 1;
859 0 delete $params->{password};
860 ▶ } elsif (exists $params->{password} and $params->{password}) {
Condition0%0/3
exists $params->{"password"} and $params->{"password"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $params->{"password"} and $params->{"password"}
exists $params->{"password"} $params->{"password"}
Truth table0%0/3
A and B
A= exists $params->{"password"}B= $params->{"password"}
ABresult
0X0
100
111
861 0 $required_keys_map->{create_website}->{password} = 1;
862 } else {
863 # if neither key or password are present, then push a 'fake' value in, to indicate this.
864 0 $required_keys_map->{create_website}->{'Key or Password'} = 1;
865 }
866 ▶ } elsif ($action eq 'create_database' and (exists $params->{authentication_mode} and $params->{authentication_mode} eq 'ssh')) {
Condition0%0/6
$action eq "create_database" and (exists $params->{"authentication_mode"} and $params->{"authentication_mode"} eq "ssh")
!ll&&!rl&&r
000
exists $params->{"authentication_mode"} and $params->{"authentication_mode"} eq "ssh"
!ll&&!rl&&r
000
MC/DC0%0/3
$action eq "create_database" and (exists $params->{"authentication_mode"} and $params->{"authentication_mode"} eq "ssh")
$action eq "create_database" exists $params->{"authentication_mode"} $params->{"authentication_mode"} eq "ssh"
Truth table0%0/4
A and B and C
A= $action eq "create_database"B= exists $params->{"authentication_mode"}C= $params->{"authentication_mode"} eq "ssh"
ABCresult
0XX0
10X0
1100
1111
867 0 $required_keys_map->{create_database}->{server_account} = 1;
868 0 $required_keys_map->{create_database}->{server_password} = 1;
869 }
870  
871 0 return $required_keys_map->{$action};
872 }
873  
874 sub _fetch_optional_params {
875  
876 0 ▶ my ($self, $action) = @_;
Subroutine _fetch_optional_params: not called CC=1 SCAR=6.9
877 my $optional_keys_map = {
878 0 create_website => { map { ($_ => 1) } qw(port dir_path) },
879 0 create_database => { map { ($_ => 1) } qw(website_id authentication_mode) },
880 0 edit_website => { map { ($_ => 1) } qw(url monitor_frequency account password key dir_path hostname disabled) },
881 0 show_database => { map { ($_ => 1) } qw(website_id) }, # Added in v0.03.
882 0 edit_database => { map { ($_ => 1) } qw(server_address account password port database_name authentication_mode server_account server_password website_id disabled) },
883 0 browse_website_backup => { map { ($_ => 1) } qw (path) },
884 };
885 0 return $optional_keys_map->{$action};
886 }
887  
888 sub _oauth_nonce {
889  
890 0 ▶ my $nonce = '';
Subroutine _oauth_nonce: not called CC=2 SCAR=17.9
891 0 $nonce .= sprintf("%02x", int(rand(255))) for 1..16;
892 0 return $nonce;
893 }
894  
895 =head1 AUTHOR
896  
897 Rishwanth Yeddula, C<< <ryeddula at cpan.org> >>
898  
899 =head1 BUGS
900  
901 Please report any bugs or feature requests to C<bug-www-codeguard at rt.cpan.org>, or through
902 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Codeguard>. I will be notified, and then you'll
903 automatically be notified of progress on your bug as I make changes.
904  
905 =head1 SUPPORT
906  
907 You can find documentation for this module with the following perldoc commands.
908  
909 perldoc WWW::Codeguard
910 perldoc WWW::Codeguard::Partner
911 perldoc WWW::Codeguard::User
912  
913  
914 You can also look for information at:
915  
916 =over 4
917  
918 =item * RT: CPAN's request tracker (report bugs here)
919  
920 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Codeguard>
921  
922 =item * AnnoCPAN: Annotated CPAN documentation
923  
924 L<http://annocpan.org/dist/WWW-Codeguard>
925  
926 =item * CPAN Ratings
927  
928 L<http://cpanratings.perl.org/d/WWW-Codeguard>
929  
930 =item * Search CPAN
931  
932 L<http://search.cpan.org/dist/WWW-Codeguard/>
933  
934 =back
935  
936 =head1 ACKNOWLEDGMENTS
937  
938 Thanks to L<Hostgator.com|http://hostgator.com/> for funding the development of this module and providing test resources.
939  
940 =head1 LICENSE AND COPYRIGHT
941  
942 Copyright 2014 Rishwanth Yeddula.
943  
944 This program is free software; you can redistribute it and/or modify it
945 under the terms of the the Artistic License (2.0). You may obtain a
946 copy of the full license at:
947  
948 L<http://www.perlfoundation.org/artistic_license_2_0>
949  
950 Any use, modification, and distribution of the Standard or Modified
951 Versions is governed by this Artistic License. By using, modifying or
952 distributing the Package, you accept this license. Do not use, modify,
953 or distribute the Package, if you do not accept this license.
954  
955 If your Modified Version has been derived from a Modified Version made
956 by someone other than you, you are nevertheless required to ensure that
957 your Modified Version complies with the requirements of this license.
958  
959 This license does not grant you the right to use any trademark, service
960 mark, tradename, or logo of the Copyright Holder.
961  
962 This license includes the non-exclusive, worldwide, free-of-charge
963 patent license to make, have made, use, offer to sell, sell, import and
964 otherwise transfer the Package with respect to any patent claims
965 licensable by the Copyright Holder that are necessarily infringed by the
966 Package. If you institute patent litigation (including a cross-claim or
967 counterclaim) against any party alleging that the Package constitutes
968 direct or contributory patent infringement, then this Artistic License
969 to you shall terminate on the date that such litigation is filed.
970  
971 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
972 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
973 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
974 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
975 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
976 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
977 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
978 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
979  
980 =cut
981  
982 1 1;
« Codeguard.pm ↑ Summary Codeguard/Partner.pm »