| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::Codeguard::User; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 4 | 1 |  |  | 1 |  | 5 | use warnings FATAL => 'all', NONFATAL => 'uninitialized'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 44 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 5 | use parent qw(WWW::Codeguard); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 1 |  |  | 1 |  | 57 | use JSON qw(); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 19 |  | 
| 9 | 1 |  |  | 1 |  | 403 | use Net::OAuth; | 
|  | 1 |  |  |  |  | 780 |  | 
|  | 1 |  |  |  |  | 39 |  | 
| 10 | 1 |  |  | 1 |  | 10 | use LWP::UserAgent; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 11 | 1 |  |  | 1 |  | 8 | use HTTP::Request; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 2388 |  | 
| 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 | 8 | my $class = shift; | 
| 41 | 2 |  |  |  |  | 5 | my $self = {}; | 
| 42 | 2 |  |  |  |  | 6 | bless $self, $class; | 
| 43 | 2 |  |  |  |  | 9 | $self->_initialize(@_); | 
| 44 | 2 |  |  |  |  | 7 | return $self; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub _initialize { | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 2 |  |  | 2 |  | 7 | my ($self, $api_url, $opts) = @_; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 2 |  |  |  |  | 13 | $self->{api_url} = $api_url; | 
| 52 | 2 |  |  |  |  | 6 | foreach my $key (qw(api_secret api_key access_secret access_token)) { | 
| 53 | 8 | 50 |  |  |  | 31 | $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 |  |  |  | 15 | verify_hostname => (exists $opts->{verify_hostname}? $opts->{verify_hostname} : 1), | 
| 62 |  |  |  |  |  |  | }, | 
| 63 |  |  |  |  |  |  | ); | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 2 |  |  |  |  | 558 | 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 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | =cut | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | sub edit_website { | 
| 188 |  |  |  |  |  |  |  | 
| 189 | 0 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 190 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 210 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 230 |  |  |  |  |  |  | my $real_params = { | 
| 231 | 0 | 0 |  |  |  | 0 | UNIVERSAL::isa($params, 'HASH') ? ( website_id => $params->{website_id} ) : (), | 
| 232 |  |  |  |  |  |  | }; | 
| 233 |  |  |  |  |  |  |  | 
| 234 | 0 |  |  |  |  | 0 | $real_params->{disabled} = JSON::false; | 
| 235 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 255 | 0 | 0 |  |  |  | 0 | $self->_sanitize_params('edit_website', $params) or | 
| 256 |  |  |  |  |  |  | $self->_error('Failed to sanitize params: "'.$self->get_error.'" - The parameters passed in were: '."\n".$self->_stringify_hash($params), 1); | 
| 257 | 0 |  |  |  |  | 0 | $params->{disabled} = JSON::true; | 
| 258 | 0 |  |  |  |  | 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: 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 297 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 317 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 337 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 366 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 386 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 406 |  |  |  |  |  |  | my $real_params = { | 
| 407 | 0 | 0 |  |  |  | 0 | UNIVERSAL::isa($params, 'HASH') ? ( database_id => $params->{database_id} ) : (), | 
| 408 |  |  |  |  |  |  | }; | 
| 409 |  |  |  |  |  |  |  | 
| 410 | 0 |  |  |  |  | 0 | $real_params->{disabled} = JSON::false; | 
| 411 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 431 |  |  |  |  |  |  | my $real_params = { | 
| 432 | 0 | 0 |  |  |  | 0 | UNIVERSAL::isa($params, 'HASH') ? ( database_id => $params->{database_id} ) : (), | 
| 433 |  |  |  |  |  |  | }; | 
| 434 |  |  |  |  |  |  |  | 
| 435 | 0 |  |  |  |  | 0 | $real_params->{disabled} = JSON::true; | 
| 436 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 456 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 477 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 499 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 520 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 542 | 0 |  |  |  |  | 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 562 | 0 |  |  |  |  | 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 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 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 584 | 0 |  |  |  |  | 0 | return $self->_do_method('browse_website_backup', $params); | 
| 585 |  |  |  |  |  |  | } | 
| 586 |  |  |  |  |  |  |  | 
| 587 |  |  |  |  |  |  | =head2 create_database_backup | 
| 588 |  |  |  |  |  |  |  | 
| 589 |  |  |  |  |  |  | Will initiate an on-demand backup for a Database. | 
| 590 |  |  |  |  |  |  |  | 
| 591 |  |  |  |  |  |  | Required: | 
| 592 |  |  |  |  |  |  |  | 
| 593 |  |  |  |  |  |  | website_id  - Id of the Website associated with the database to create a backup for. | 
| 594 |  |  |  |  |  |  | database_id - Id of the Database to create a backup for. | 
| 595 |  |  |  |  |  |  |  | 
| 596 |  |  |  |  |  |  | Optional: | 
| 597 |  |  |  |  |  |  |  | 
| 598 |  |  |  |  |  |  | None | 
| 599 |  |  |  |  |  |  |  | 
| 600 |  |  |  |  |  |  | =cut | 
| 601 |  |  |  |  |  |  |  | 
| 602 |  |  |  |  |  |  | sub create_database_backup { | 
| 603 |  |  |  |  |  |  |  | 
| 604 | 0 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 605 | 0 |  |  |  |  | 0 | return $self->_do_method('create_database_backup', $params); | 
| 606 |  |  |  |  |  |  | } | 
| 607 |  |  |  |  |  |  |  | 
| 608 |  |  |  |  |  |  | =head2 restore_database_backup | 
| 609 |  |  |  |  |  |  |  | 
| 610 |  |  |  |  |  |  | Will initiate a full restore for a Database. | 
| 611 |  |  |  |  |  |  |  | 
| 612 |  |  |  |  |  |  | Required: | 
| 613 |  |  |  |  |  |  |  | 
| 614 |  |  |  |  |  |  | website_id  - Id of the Website associated with the database to restore. | 
| 615 |  |  |  |  |  |  | database_id - Id of the Database to restore a backup for. | 
| 616 |  |  |  |  |  |  | commit_id   - The commit to restore the database from. | 
| 617 |  |  |  |  |  |  |  | 
| 618 |  |  |  |  |  |  | Optional: | 
| 619 |  |  |  |  |  |  |  | 
| 620 |  |  |  |  |  |  | None | 
| 621 |  |  |  |  |  |  |  | 
| 622 |  |  |  |  |  |  | =cut | 
| 623 |  |  |  |  |  |  |  | 
| 624 |  |  |  |  |  |  | sub restore_database_backup { | 
| 625 |  |  |  |  |  |  |  | 
| 626 | 0 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 627 | 0 |  |  |  |  | 0 | return $self->_do_method('restore_database_backup', $params); | 
| 628 |  |  |  |  |  |  | } | 
| 629 |  |  |  |  |  |  |  | 
| 630 |  |  |  |  |  |  | =head2 list_database_backups | 
| 631 |  |  |  |  |  |  |  | 
| 632 |  |  |  |  |  |  | List all the bacukps for a Database. | 
| 633 |  |  |  |  |  |  |  | 
| 634 |  |  |  |  |  |  | Required: | 
| 635 |  |  |  |  |  |  |  | 
| 636 |  |  |  |  |  |  | website_id  - Id of the Website associated with the requested database. | 
| 637 |  |  |  |  |  |  | database_id - Id of the Database to list the backups for. | 
| 638 |  |  |  |  |  |  |  | 
| 639 |  |  |  |  |  |  | Optional: | 
| 640 |  |  |  |  |  |  |  | 
| 641 |  |  |  |  |  |  | None | 
| 642 |  |  |  |  |  |  |  | 
| 643 |  |  |  |  |  |  | =cut | 
| 644 |  |  |  |  |  |  |  | 
| 645 |  |  |  |  |  |  | sub list_database_backups { | 
| 646 |  |  |  |  |  |  |  | 
| 647 | 0 |  |  | 0 | 1 | 0 | my ($self, $params) = @_; | 
| 648 | 0 |  |  |  |  | 0 | return $self->_do_method('list_database_backups', $params); | 
| 649 |  |  |  |  |  |  | } | 
| 650 |  |  |  |  |  |  |  | 
| 651 |  |  |  |  |  |  | =head2 generate_login_link | 
| 652 |  |  |  |  |  |  |  | 
| 653 |  |  |  |  |  |  | This creates a login URL that can be used to access the Codeguard Dashboard for your User account. | 
| 654 |  |  |  |  |  |  |  | 
| 655 |  |  |  |  |  |  | Required: | 
| 656 |  |  |  |  |  |  |  | 
| 657 |  |  |  |  |  |  | None | 
| 658 |  |  |  |  |  |  |  | 
| 659 |  |  |  |  |  |  | Optional: | 
| 660 |  |  |  |  |  |  |  | 
| 661 |  |  |  |  |  |  | None | 
| 662 |  |  |  |  |  |  |  | 
| 663 |  |  |  |  |  |  | =cut | 
| 664 |  |  |  |  |  |  |  | 
| 665 |  |  |  |  |  |  | sub generate_login_link { | 
| 666 |  |  |  |  |  |  |  | 
| 667 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 668 | 0 |  |  |  |  | 0 | return $self->_set_uri('list_websites'); | 
| 669 |  |  |  |  |  |  | } | 
| 670 |  |  |  |  |  |  |  | 
| 671 |  |  |  |  |  |  | =head1 Accessors | 
| 672 |  |  |  |  |  |  |  | 
| 673 |  |  |  |  |  |  | Basic accessor methods to retrieve the current settings | 
| 674 |  |  |  |  |  |  |  | 
| 675 |  |  |  |  |  |  | =cut | 
| 676 |  |  |  |  |  |  |  | 
| 677 |  |  |  |  |  |  | =head2 get_api_secret | 
| 678 |  |  |  |  |  |  |  | 
| 679 |  |  |  |  |  |  | Returns the current value in $self->{api_secret}. | 
| 680 |  |  |  |  |  |  |  | 
| 681 |  |  |  |  |  |  | =cut | 
| 682 |  |  |  |  |  |  |  | 
| 683 | 1 |  |  | 1 | 1 | 6 | sub get_api_secret { shift->{api_secret}; } | 
| 684 |  |  |  |  |  |  |  | 
| 685 |  |  |  |  |  |  | =head2 get_api_key | 
| 686 |  |  |  |  |  |  |  | 
| 687 |  |  |  |  |  |  | Returns the current value in $self->{api_key}. | 
| 688 |  |  |  |  |  |  |  | 
| 689 |  |  |  |  |  |  | =cut | 
| 690 |  |  |  |  |  |  |  | 
| 691 | 1 |  |  | 1 | 1 | 7 | sub get_api_key { shift->{api_key}; } | 
| 692 |  |  |  |  |  |  |  | 
| 693 |  |  |  |  |  |  | =head2 get_access_secret | 
| 694 |  |  |  |  |  |  |  | 
| 695 |  |  |  |  |  |  | Returns the current value in $self->{access_secret}. | 
| 696 |  |  |  |  |  |  |  | 
| 697 |  |  |  |  |  |  | =cut | 
| 698 |  |  |  |  |  |  |  | 
| 699 | 1 |  |  | 1 | 1 | 6 | sub get_access_secret { shift->{access_secret}; } | 
| 700 |  |  |  |  |  |  |  | 
| 701 |  |  |  |  |  |  | =head2 get_access_token | 
| 702 |  |  |  |  |  |  |  | 
| 703 |  |  |  |  |  |  | Returns the current value in $self->{access_token}. | 
| 704 |  |  |  |  |  |  |  | 
| 705 |  |  |  |  |  |  | =cut | 
| 706 |  |  |  |  |  |  |  | 
| 707 | 1 |  |  | 1 | 1 | 10 | sub get_access_token { shift->{access_token}; } | 
| 708 |  |  |  |  |  |  |  | 
| 709 |  |  |  |  |  |  | # Internal Methods | 
| 710 |  |  |  |  |  |  |  | 
| 711 |  |  |  |  |  |  | sub _create_request { | 
| 712 |  |  |  |  |  |  |  | 
| 713 | 0 |  |  | 0 |  |  | my ($self, $action, $params) = @_; | 
| 714 | 0 |  |  |  |  |  | my $action_map = { | 
| 715 |  |  |  |  |  |  | 'create_website'                    => 'POST', | 
| 716 |  |  |  |  |  |  | 'list_websites'                     => 'GET', | 
| 717 |  |  |  |  |  |  | 'edit_website'                      => 'PUT', | 
| 718 |  |  |  |  |  |  | 'delete_website'                    => 'DELETE', | 
| 719 |  |  |  |  |  |  | 'list_website_rules'                => 'GET', | 
| 720 |  |  |  |  |  |  | 'set_website_rules'                 => 'POST', | 
| 721 |  |  |  |  |  |  | 'create_database'                   => 'POST', | 
| 722 |  |  |  |  |  |  | 'list_databases'                    => 'GET', | 
| 723 |  |  |  |  |  |  | 'show_database'                     => 'GET', | 
| 724 |  |  |  |  |  |  | 'edit_database'                     => 'PUT', | 
| 725 |  |  |  |  |  |  | 'delete_database'                   => 'DELETE', | 
| 726 |  |  |  |  |  |  | 'create_website_backup'             => 'POST', | 
| 727 |  |  |  |  |  |  | 'restore_website_backup'            => 'POST', | 
| 728 |  |  |  |  |  |  | 'selective_restore_website_backup'  => 'POST', | 
| 729 |  |  |  |  |  |  | 'download_website_backup'           => 'GET', | 
| 730 |  |  |  |  |  |  | 'download_selective_website_backup' => 'POST', | 
| 731 |  |  |  |  |  |  | 'list_website_backups'              => 'GET', | 
| 732 |  |  |  |  |  |  | 'browse_website_backup'             => 'GET', | 
| 733 |  |  |  |  |  |  | 'create_database_backup'            => 'POST', | 
| 734 |  |  |  |  |  |  | 'restore_database_backup'           => 'POST', | 
| 735 |  |  |  |  |  |  | 'list_database_backups'             => 'GET', | 
| 736 |  |  |  |  |  |  | }; | 
| 737 | 0 |  |  |  |  |  | my $request = HTTP::Request->new( $action_map->{$action} ); | 
| 738 | 0 |  |  |  |  |  | $request->header('Content-Type' => 'application/json' ); | 
| 739 | 0 |  |  |  |  |  | $self->_set_uri($action, $request, $params); | 
| 740 | 0 |  |  |  |  |  | $self->_set_content($request, $params); | 
| 741 | 0 |  |  |  |  |  | return $request; | 
| 742 |  |  |  |  |  |  | } | 
| 743 |  |  |  |  |  |  |  | 
| 744 |  |  |  |  |  |  | sub _set_uri { | 
| 745 |  |  |  |  |  |  |  | 
| 746 | 0 |  |  | 0 |  |  | my ($self, $action, $request, $params) = @_; | 
| 747 | 0 |  |  |  |  |  | my $base_url = $self->get_api_url(); | 
| 748 |  |  |  |  |  |  |  | 
| 749 | 0 |  | 0 |  |  |  | my $website_id  = delete $params->{website_id}  || ''; | 
| 750 | 0 |  | 0 |  |  |  | my $database_id = delete $params->{database_id} || ''; | 
| 751 | 0 |  | 0 |  |  |  | my $commit_id   = delete $params->{commit_id}   || ''; | 
| 752 |  |  |  |  |  |  |  | 
| 753 | 0 |  |  |  |  |  | my $uri_map  = { | 
| 754 |  |  |  |  |  |  | 'create_website'                    => '/websites', | 
| 755 |  |  |  |  |  |  | 'list_websites'                     => '/websites', | 
| 756 |  |  |  |  |  |  | 'edit_website'                      => "/websites/$website_id", | 
| 757 |  |  |  |  |  |  | 'delete_website'                    => "/websites/$website_id", | 
| 758 |  |  |  |  |  |  | 'list_website_rules'                => "/websites/$website_id/rules", | 
| 759 |  |  |  |  |  |  | 'set_website_rules'                 => "/websites/$website_id/rules", | 
| 760 |  |  |  |  |  |  | 'create_database'                   => '/database_backups', | 
| 761 |  |  |  |  |  |  | 'list_databases'                    => '/database_backups', | 
| 762 |  |  |  |  |  |  | 'show_database'                     => "/database_backups/$database_id", | 
| 763 |  |  |  |  |  |  | 'edit_database'                     => "/database_backups/$database_id", | 
| 764 |  |  |  |  |  |  | 'delete_database'                   => "/database_backups/$database_id", | 
| 765 |  |  |  |  |  |  | 'create_website_backup'             => "/websites/$website_id/request_backup", | 
| 766 |  |  |  |  |  |  | 'restore_website_backup'            => "/websites/$website_id/commits/$commit_id/initiate_restore", | 
| 767 |  |  |  |  |  |  | 'selective_restore_website_backup'  => "/websites/$website_id/commits/$commit_id/restore_selected", | 
| 768 |  |  |  |  |  |  | 'download_website_backup'           => "/websites/$website_id/commits/$commit_id/download", | 
| 769 |  |  |  |  |  |  | 'download_selective_website_backup' => "/websites/$website_id/commits/$commit_id/download_selected", | 
| 770 |  |  |  |  |  |  | 'list_website_backups'              => "/websites/$website_id/commits", | 
| 771 |  |  |  |  |  |  | 'browse_website_backup'             => "/websites/$website_id/commits/$commit_id/browse", | 
| 772 |  |  |  |  |  |  | 'create_database_backup'            => "/websites/$website_id/database_backups/$database_id/request_backup", | 
| 773 |  |  |  |  |  |  | 'restore_database_backup'           => "/websites/$website_id/database_backups/$database_id/commits/$commit_id/initiate_restore", | 
| 774 |  |  |  |  |  |  | 'list_database_backups'             => "/websites/$website_id/database_backups/$database_id/commits", | 
| 775 |  |  |  |  |  |  | }; | 
| 776 |  |  |  |  |  |  |  | 
| 777 | 0 | 0 |  |  |  |  | my $method = ($request) ? $request->method : 'GET'; | 
| 778 |  |  |  |  |  |  | my $oauth_params = { | 
| 779 |  |  |  |  |  |  | # Include our parameters in the query if our method is GET | 
| 780 |  |  |  |  |  |  | ($method eq 'GET' ? (extra_params => $params) : ()), | 
| 781 |  |  |  |  |  |  | 'consumer_key'     => $self->{api_key}, | 
| 782 |  |  |  |  |  |  | 'consumer_secret'  => $self->{api_secret}, | 
| 783 |  |  |  |  |  |  | 'token'            => $self->{access_token}, | 
| 784 |  |  |  |  |  |  | 'token_secret'     => $self->{access_secret}, | 
| 785 |  |  |  |  |  |  | 'signature_method' => 'HMAC-SHA1', | 
| 786 |  |  |  |  |  |  | 'timestamp'        => time(), | 
| 787 |  |  |  |  |  |  | 'nonce'            => _oauth_nonce(), | 
| 788 |  |  |  |  |  |  | 'request_method'   => $method, | 
| 789 | 0 | 0 |  |  |  |  | 'request_url'      => $base_url.$uri_map->{$action}, | 
| 790 |  |  |  |  |  |  | }; | 
| 791 |  |  |  |  |  |  |  | 
| 792 | 0 |  |  |  |  |  | my $oauth_req = Net::OAuth->request('protected resource')->new(%$oauth_params); | 
| 793 | 0 |  |  |  |  |  | $oauth_req->sign; | 
| 794 | 0 | 0 |  |  |  |  | return ($request) ? $request->uri($oauth_req->to_url) : $oauth_req->to_url; | 
| 795 |  |  |  |  |  |  | } | 
| 796 |  |  |  |  |  |  |  | 
| 797 |  |  |  |  |  |  | sub _fetch_required_params { | 
| 798 |  |  |  |  |  |  |  | 
| 799 | 0 |  |  | 0 |  |  | my ($self, $action, $params) = @_; | 
| 800 |  |  |  |  |  |  | my $required_keys_map = { | 
| 801 | 0 |  |  |  |  |  | create_website                    => { map { ($_ => 1) } qw(url hostname account provider) }, | 
| 802 |  |  |  |  |  |  | list_websites                     => { }, | 
| 803 | 0 |  |  |  |  |  | list_website_rules                => { map { ($_ => 1) } qw(website_id) }, | 
| 804 | 0 |  |  |  |  |  | set_website_rules                 => { map { ($_ => 1) } qw(website_id exclude_rules) }, | 
| 805 | 0 |  |  |  |  |  | create_database                   => { map { ($_ => 1) } qw(server_address account password port database_name) }, | 
| 806 |  |  |  |  |  |  | list_databases                    => { }, | 
| 807 | 0 |  |  |  |  |  | show_database                     => { map { ($_ => 1) } qw(database_id) }, # Added in v0.03. | 
| 808 | 0 |  |  |  |  |  | edit_database                     => { map { ($_ => 1) } qw(database_id) }, | 
| 809 | 0 |  |  |  |  |  | create_website_backup             => { map { ($_ => 1) } qw(website_id) }, | 
| 810 | 0 |  |  |  |  |  | restore_website_backup            => { map { ($_ => 1) } qw(website_id commit_id) }, | 
| 811 | 0 |  |  |  |  |  | selective_restore_website_backup  => { map { ($_ => 1) } qw(website_id commit_id paths) }, | 
| 812 | 0 |  |  |  |  |  | download_website_backup           => { map { ($_ => 1) } qw(website_id commit_id) }, | 
| 813 | 0 |  |  |  |  |  | download_selective_website_backup => { map { ($_ => 1) } qw(website_id commit_id paths) }, | 
| 814 | 0 |  |  |  |  |  | list_website_backups              => { map { ($_ => 1) } qw(website_id) }, | 
| 815 | 0 |  |  |  |  |  | browse_website_backup             => { map { ($_ => 1) } qw(website_id commit_id) }, | 
| 816 | 0 |  |  |  |  |  | create_database_backup            => { map { ($_ => 1) } qw(website_id database_id) }, | 
| 817 | 0 |  |  |  |  |  | restore_database_backup           => { map { ($_ => 1) } qw(website_id database_id commit_id) }, | 
| 818 | 0 |  |  |  |  |  | list_database_backups             => { map { ($_ => 1) } qw(website_id database_id) }, | 
|  | 0 |  |  |  |  |  |  | 
| 819 |  |  |  |  |  |  | }; | 
| 820 |  |  |  |  |  |  |  | 
| 821 |  |  |  |  |  |  | # The 'edit_website', and 'delete_website' calls have the same set of required params as the 'list_website_rules' call | 
| 822 | 0 |  |  |  |  |  | $required_keys_map->{edit_website} = $required_keys_map->{delete_website} = $required_keys_map->{list_website_rules}; | 
| 823 |  |  |  |  |  |  |  | 
| 824 |  |  |  |  |  |  | # The 'delete_database' call has the same set of required params as the 'edit_database' call | 
| 825 | 0 |  |  |  |  |  | $required_keys_map->{delete_database} = $required_keys_map->{edit_database}; | 
| 826 |  |  |  |  |  |  |  | 
| 827 |  |  |  |  |  |  | # if action is 'create_website', | 
| 828 |  |  |  |  |  |  | # then we check the $params | 
| 829 |  |  |  |  |  |  | # and mark either 'password' or 'key' as the required param. | 
| 830 | 0 | 0 | 0 |  |  |  | if ($action eq 'create_website') { | 
|  |  | 0 | 0 |  |  |  |  | 
| 831 | 0 | 0 | 0 |  |  |  | if (exists $params->{key} and $params->{key}) { | 
|  |  | 0 | 0 |  |  |  |  | 
| 832 | 0 |  |  |  |  |  | $required_keys_map->{create_website}->{key} = 1; | 
| 833 | 0 |  |  |  |  |  | delete $params->{password}; | 
| 834 |  |  |  |  |  |  | } elsif (exists $params->{password} and $params->{password}) { | 
| 835 | 0 |  |  |  |  |  | $required_keys_map->{create_website}->{password} = 1; | 
| 836 |  |  |  |  |  |  | } else { | 
| 837 |  |  |  |  |  |  | # if neither key or password are present, then push a 'fake' value in, to indicate this. | 
| 838 | 0 |  |  |  |  |  | $required_keys_map->{create_website}->{'Key or Password'} = 1; | 
| 839 |  |  |  |  |  |  | } | 
| 840 |  |  |  |  |  |  | } elsif ($action eq 'create_database' and (exists $params->{authentication_mode} and $params->{authentication_mode} eq 'ssh')) { | 
| 841 | 0 |  |  |  |  |  | $required_keys_map->{create_database}->{server_account}  = 1; | 
| 842 | 0 |  |  |  |  |  | $required_keys_map->{create_database}->{server_password} = 1; | 
| 843 |  |  |  |  |  |  | } | 
| 844 |  |  |  |  |  |  |  | 
| 845 | 0 |  |  |  |  |  | return $required_keys_map->{$action}; | 
| 846 |  |  |  |  |  |  | } | 
| 847 |  |  |  |  |  |  |  | 
| 848 |  |  |  |  |  |  | sub _fetch_optional_params { | 
| 849 |  |  |  |  |  |  |  | 
| 850 | 0 |  |  | 0 |  |  | my ($self, $action) = @_; | 
| 851 |  |  |  |  |  |  | my $optional_keys_map = { | 
| 852 | 0 |  |  |  |  |  | create_website        => { map { ($_ => 1) } qw(port dir_path) }, | 
| 853 | 0 |  |  |  |  |  | create_database       => { map { ($_ => 1) } qw(website_id authentication_mode) }, | 
| 854 | 0 |  |  |  |  |  | edit_website          => { map { ($_ => 1) } qw(url monitor_frequency account password key dir_path hostname disabled) }, | 
| 855 | 0 |  |  |  |  |  | show_database         => { map { ($_ => 1) } qw(website_id) }, # Added in v0.03. | 
| 856 | 0 |  |  |  |  |  | edit_database         => { map { ($_ => 1) } qw(server_address account password port database_name authentication_mode server_account server_password website_id disabled) }, | 
| 857 | 0 |  |  |  |  |  | browse_website_backup => { map { ($_ => 1) } qw (path) }, | 
|  | 0 |  |  |  |  |  |  | 
| 858 |  |  |  |  |  |  | }; | 
| 859 | 0 |  |  |  |  |  | return $optional_keys_map->{$action}; | 
| 860 |  |  |  |  |  |  | } | 
| 861 |  |  |  |  |  |  |  | 
| 862 |  |  |  |  |  |  | sub _oauth_nonce { | 
| 863 |  |  |  |  |  |  |  | 
| 864 | 0 |  |  | 0 |  |  | my $nonce = ''; | 
| 865 | 0 |  |  |  |  |  | $nonce .= sprintf("%02x", int(rand(255))) for 1..16; | 
| 866 | 0 |  |  |  |  |  | return $nonce; | 
| 867 |  |  |  |  |  |  | } | 
| 868 |  |  |  |  |  |  |  | 
| 869 |  |  |  |  |  |  | =head1 AUTHOR | 
| 870 |  |  |  |  |  |  |  | 
| 871 |  |  |  |  |  |  | Rishwanth Yeddula, C<<  >> | 
| 872 |  |  |  |  |  |  |  | 
| 873 |  |  |  |  |  |  | =head1 BUGS | 
| 874 |  |  |  |  |  |  |  | 
| 875 |  |  |  |  |  |  | Please report any bugs or feature requests to C, or through | 
| 876 |  |  |  |  |  |  | the web interface at L.  I will be notified, and then you'll | 
| 877 |  |  |  |  |  |  | automatically be notified of progress on your bug as I make changes. | 
| 878 |  |  |  |  |  |  |  | 
| 879 |  |  |  |  |  |  | =head1 SUPPORT | 
| 880 |  |  |  |  |  |  |  | 
| 881 |  |  |  |  |  |  | You can find documentation for this module with the following perldoc commands. | 
| 882 |  |  |  |  |  |  |  | 
| 883 |  |  |  |  |  |  | perldoc WWW::Codeguard | 
| 884 |  |  |  |  |  |  | perldoc WWW::Codeguard::Partner | 
| 885 |  |  |  |  |  |  | perldoc WWW::Codeguard::User | 
| 886 |  |  |  |  |  |  |  | 
| 887 |  |  |  |  |  |  |  | 
| 888 |  |  |  |  |  |  | You can also look for information at: | 
| 889 |  |  |  |  |  |  |  | 
| 890 |  |  |  |  |  |  | =over 4 | 
| 891 |  |  |  |  |  |  |  | 
| 892 |  |  |  |  |  |  | =item * RT: CPAN's request tracker (report bugs here) | 
| 893 |  |  |  |  |  |  |  | 
| 894 |  |  |  |  |  |  | L | 
| 895 |  |  |  |  |  |  |  | 
| 896 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 897 |  |  |  |  |  |  |  | 
| 898 |  |  |  |  |  |  | L | 
| 899 |  |  |  |  |  |  |  | 
| 900 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 901 |  |  |  |  |  |  |  | 
| 902 |  |  |  |  |  |  | L | 
| 903 |  |  |  |  |  |  |  | 
| 904 |  |  |  |  |  |  | =item * Search CPAN | 
| 905 |  |  |  |  |  |  |  | 
| 906 |  |  |  |  |  |  | L | 
| 907 |  |  |  |  |  |  |  | 
| 908 |  |  |  |  |  |  | =back | 
| 909 |  |  |  |  |  |  |  | 
| 910 |  |  |  |  |  |  | =head1 ACKNOWLEDGMENTS | 
| 911 |  |  |  |  |  |  |  | 
| 912 |  |  |  |  |  |  | Thanks to L for funding the development of this module and providing test resources. | 
| 913 |  |  |  |  |  |  |  | 
| 914 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 915 |  |  |  |  |  |  |  | 
| 916 |  |  |  |  |  |  | Copyright 2014 Rishwanth Yeddula. | 
| 917 |  |  |  |  |  |  |  | 
| 918 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 919 |  |  |  |  |  |  | under the terms of the the Artistic License (2.0). You may obtain a | 
| 920 |  |  |  |  |  |  | copy of the full license at: | 
| 921 |  |  |  |  |  |  |  | 
| 922 |  |  |  |  |  |  | L | 
| 923 |  |  |  |  |  |  |  | 
| 924 |  |  |  |  |  |  | Any use, modification, and distribution of the Standard or Modified | 
| 925 |  |  |  |  |  |  | Versions is governed by this Artistic License. By using, modifying or | 
| 926 |  |  |  |  |  |  | distributing the Package, you accept this license. Do not use, modify, | 
| 927 |  |  |  |  |  |  | or distribute the Package, if you do not accept this license. | 
| 928 |  |  |  |  |  |  |  | 
| 929 |  |  |  |  |  |  | If your Modified Version has been derived from a Modified Version made | 
| 930 |  |  |  |  |  |  | by someone other than you, you are nevertheless required to ensure that | 
| 931 |  |  |  |  |  |  | your Modified Version complies with the requirements of this license. | 
| 932 |  |  |  |  |  |  |  | 
| 933 |  |  |  |  |  |  | This license does not grant you the right to use any trademark, service | 
| 934 |  |  |  |  |  |  | mark, tradename, or logo of the Copyright Holder. | 
| 935 |  |  |  |  |  |  |  | 
| 936 |  |  |  |  |  |  | This license includes the non-exclusive, worldwide, free-of-charge | 
| 937 |  |  |  |  |  |  | patent license to make, have made, use, offer to sell, sell, import and | 
| 938 |  |  |  |  |  |  | otherwise transfer the Package with respect to any patent claims | 
| 939 |  |  |  |  |  |  | licensable by the Copyright Holder that are necessarily infringed by the | 
| 940 |  |  |  |  |  |  | Package. If you institute patent litigation (including a cross-claim or | 
| 941 |  |  |  |  |  |  | counterclaim) against any party alleging that the Package constitutes | 
| 942 |  |  |  |  |  |  | direct or contributory patent infringement, then this Artistic License | 
| 943 |  |  |  |  |  |  | to you shall terminate on the date that such litigation is filed. | 
| 944 |  |  |  |  |  |  |  | 
| 945 |  |  |  |  |  |  | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | 
| 946 |  |  |  |  |  |  | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | 
| 947 |  |  |  |  |  |  | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | 
| 948 |  |  |  |  |  |  | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | 
| 949 |  |  |  |  |  |  | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | 
| 950 |  |  |  |  |  |  | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | 
| 951 |  |  |  |  |  |  | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | 
| 952 |  |  |  |  |  |  | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 953 |  |  |  |  |  |  |  | 
| 954 |  |  |  |  |  |  | =cut | 
| 955 |  |  |  |  |  |  |  | 
| 956 |  |  |  |  |  |  | 1; |