File Coverage

blib/lib/WWW/Codeguard/User.pm
Criterion Covered Total %
statement 36 158 22.7
branch 2 26 7.6
condition 0 18 0.0
subroutine 13 45 28.8
pod 31 32 96.8
total 82 279 29.3


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