line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ceph::RadosGW::Admin; |
2
|
|
|
|
|
|
|
$Ceph::RadosGW::Admin::VERSION = '0.2'; |
3
|
2
|
|
|
2
|
|
143698
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
71
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
48
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
652
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
39951
|
|
|
2
|
|
|
|
|
47
|
|
7
|
2
|
|
|
2
|
|
1071
|
use Ceph::RadosGW::Admin::HTTPRequest; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
128
|
|
8
|
2
|
|
|
2
|
|
1732
|
use JSON; |
|
2
|
|
|
|
|
19453
|
|
|
2
|
|
|
|
|
12
|
|
9
|
2
|
|
|
2
|
|
275
|
use Moose; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
20
|
|
10
|
2
|
|
|
2
|
|
11114
|
use URI; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
37
|
|
11
|
2
|
|
|
2
|
|
8
|
use URI::QueryParam; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
32
|
|
12
|
2
|
|
|
2
|
|
1127
|
use Ceph::RadosGW::Admin::User; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1242
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Ceph::RadosGW::Admin - Bindings for the rados gateway admin api. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
version 0.2 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $admin = Ceph::RadosGW::Admin->new( |
26
|
|
|
|
|
|
|
access_key => 'not really secret', |
27
|
|
|
|
|
|
|
secret_key => 'actually secret', |
28
|
|
|
|
|
|
|
url => 'https://your.rados.gateway.com/', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $user = $admin->create_user( |
32
|
|
|
|
|
|
|
uid => 'myusername', |
33
|
|
|
|
|
|
|
display_name => 'my user name', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# they're really evil, suspending them should be enough |
37
|
|
|
|
|
|
|
$user->suspended(1); |
38
|
|
|
|
|
|
|
$user->save; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# nah, they're really evil |
41
|
|
|
|
|
|
|
$user->delete; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $otheruser = $admin->get_user(uid => 'other'); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my @keys = $otheruser->keys(); |
46
|
|
|
|
|
|
|
my @keys_plus_one = $otheruser->create_key(); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$otheruser->delete_key(access_key => $keys[0]->{access_key}); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my @buckets = $otheruser->get_bucket_info(); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This module provides an interface to the |
56
|
|
|
|
|
|
|
L<Admin OPs|http://docs.ceph.com/docs/master/radosgw/adminops/> interface of a |
57
|
|
|
|
|
|
|
ceph rados gateway. It is at this time incomplete, with only the parts needed |
58
|
|
|
|
|
|
|
by the authors implemented. Patches for the rest of the functionality are |
59
|
|
|
|
|
|
|
encouraged. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has secret_key => ( is => 'ro', required => 1 ); |
64
|
|
|
|
|
|
|
has access_key => ( is => 'ro', required => 1 ); |
65
|
|
|
|
|
|
|
has url => ( is => 'ro', required => 1 ); |
66
|
|
|
|
|
|
|
has useragent => ( |
67
|
|
|
|
|
|
|
is => 'ro', |
68
|
|
|
|
|
|
|
builder => 'build_useragent', |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 METHODS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 get_user |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Returns a L<Ceph::RadosGW::Admin::User> object representing the given C<uid>. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Dies if the user does not exist. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Example: |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $user = $admin->get_user(uid => 'someuserhere'); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_user { |
87
|
20
|
|
|
20
|
1
|
18922
|
my ($self, %args) = @_; |
88
|
|
|
|
|
|
|
|
89
|
20
|
|
|
|
|
80
|
my %user_data = $self->_request(GET => 'user', %args); |
90
|
|
|
|
|
|
|
|
91
|
17
|
|
|
|
|
163
|
return Ceph::RadosGW::Admin::User->new( |
92
|
|
|
|
|
|
|
%user_data, |
93
|
|
|
|
|
|
|
_client => $self |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 create_user |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Makes a new user on the rados gateway, and returns a |
100
|
|
|
|
|
|
|
L<Ceph::RadosGW::Admin::User> object representing that user. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Dies on failure. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Example: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $new_user = $admin->create_user( |
107
|
|
|
|
|
|
|
uid => 'username', |
108
|
|
|
|
|
|
|
display_name => 'Our New User', |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub create_user { |
114
|
8
|
|
|
8
|
1
|
1013
|
my ($self, %args) = @_; |
115
|
|
|
|
|
|
|
|
116
|
8
|
|
|
|
|
47
|
my %user_data = $self->_request(PUT => 'user', %args); |
117
|
|
|
|
|
|
|
|
118
|
8
|
|
|
|
|
63
|
return Ceph::RadosGW::Admin::User->new( |
119
|
|
|
|
|
|
|
%user_data, |
120
|
|
|
|
|
|
|
_client => $self |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub build_useragent { |
125
|
15
|
|
|
15
|
0
|
87982
|
require LWP::UserAgent; |
126
|
15
|
|
|
|
|
109
|
return LWP::UserAgent->new; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _debug { |
130
|
47
|
50
|
|
47
|
|
148
|
if ($ENV{DEBUG_CEPH_CALLS}) { |
131
|
0
|
|
|
|
|
0
|
require Data::Dumper; |
132
|
0
|
|
|
|
|
0
|
warn Data::Dumper::Dumper(@_); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _request { |
137
|
47
|
|
|
47
|
|
126
|
my ($self, $method, $path, %args) = @_; |
138
|
|
|
|
|
|
|
|
139
|
47
|
|
|
|
|
67
|
my $content = ''; |
140
|
|
|
|
|
|
|
|
141
|
47
|
|
|
|
|
122
|
my $query_string = _make_query(%args, format => 'json'); |
142
|
|
|
|
|
|
|
|
143
|
47
|
|
|
|
|
2000
|
my $request_builder = Ceph::RadosGW::Admin::HTTPRequest->new( |
144
|
|
|
|
|
|
|
method => $method, |
145
|
|
|
|
|
|
|
path => "admin/$path?$query_string", |
146
|
|
|
|
|
|
|
content => '', |
147
|
|
|
|
|
|
|
url => $self->url, |
148
|
|
|
|
|
|
|
access_key => $self->access_key, |
149
|
|
|
|
|
|
|
secret_key => $self->secret_key, |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
|
152
|
47
|
|
|
|
|
162
|
my $req = $request_builder->http_request(); |
153
|
|
|
|
|
|
|
|
154
|
47
|
|
|
|
|
1533
|
my $res = $self->useragent->request($req); |
155
|
|
|
|
|
|
|
|
156
|
47
|
|
|
|
|
46567
|
_debug($res); |
157
|
|
|
|
|
|
|
|
158
|
47
|
100
|
|
|
|
161
|
unless ($res->is_success) { |
159
|
3
|
|
|
|
|
28
|
die sprintf("%s - %s (%s)", $res->status_line, $res->content, $req->as_string); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
44
|
100
|
|
|
|
404
|
if ($res->content) { |
163
|
29
|
|
|
|
|
289
|
my $data = eval { |
164
|
29
|
|
|
|
|
59
|
JSON::decode_json($res->content); |
165
|
|
|
|
|
|
|
}; |
166
|
|
|
|
|
|
|
|
167
|
29
|
50
|
|
|
|
623
|
if (my $e = $@) { |
168
|
0
|
|
|
|
|
0
|
die "Could not deserialize server response: $e\nContent: " . $res->content . "\n"; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
29
|
100
|
|
|
|
97
|
if (ref($data) eq 'HASH') { |
|
|
50
|
|
|
|
|
|
172
|
27
|
|
|
|
|
1346
|
return %$data; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
elsif (ref($data) eq 'ARRAY') { |
175
|
2
|
|
|
|
|
89
|
return @$data; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
else { |
178
|
0
|
|
|
|
|
0
|
die "Didn't get an array or hash reference\n"; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
} else { |
181
|
15
|
|
|
|
|
721
|
return; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _make_query { |
186
|
47
|
|
|
47
|
|
95
|
my %args = @_; |
187
|
|
|
|
|
|
|
|
188
|
47
|
|
|
|
|
53
|
my %fixed; |
189
|
47
|
|
|
|
|
165
|
while (my ($key, $val) = each %args) { |
190
|
110
|
|
|
|
|
148
|
$key =~ s/_/-/g; |
191
|
110
|
|
|
|
|
281
|
$fixed{$key} = $val; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
47
|
|
|
|
|
200
|
my $u = URI->new("", "http"); |
195
|
|
|
|
|
|
|
|
196
|
47
|
|
|
|
|
7998
|
foreach my $key (sort keys %fixed) { |
197
|
110
|
|
|
|
|
6023
|
$u->query_param($key, $fixed{$key}); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
47
|
|
|
|
|
4963
|
return $u->query; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 TODO |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=over 2 |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
The docs are pretty middling at the moment. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
This module has only been tested against the Dumpling release of ceph. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=back |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 AUTHORS |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Chris Reinhardt |
223
|
|
|
|
|
|
|
crein@cpan.org |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Mark Ng |
226
|
|
|
|
|
|
|
cpan@markng.co.uk |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 COPYRIGHT |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
This program is free software; you can redistribute |
231
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
The full text of the license can be found in the |
234
|
|
|
|
|
|
|
LICENSE file included with this module. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 SEE ALSO |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
perl(1), L<Admin OPs API|http://docs.ceph.com/docs/master/radosgw/adminops/> |
239
|
|
|
|
|
|
|
L<Ceph|http://www.ceph.com/> |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
1; |
245
|
|
|
|
|
|
|
__END__ |