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