line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
18311
|
use utf8; |
|
5
|
|
|
|
|
59
|
|
|
5
|
|
|
|
|
23
|
|
2
|
|
|
|
|
|
|
package Etcd3; |
3
|
|
|
|
|
|
|
# ABSTRACT: [depricated] Please see Net::Etcd. |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
153
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
77
|
|
6
|
5
|
|
|
5
|
|
19
|
use warnings; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
94
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
2030
|
use Moo; |
|
5
|
|
|
|
|
50486
|
|
|
5
|
|
|
|
|
23
|
|
9
|
5
|
|
|
5
|
|
8266
|
use JSON; |
|
5
|
|
|
|
|
50288
|
|
|
5
|
|
|
|
|
28
|
|
10
|
5
|
|
|
5
|
|
2554
|
use MIME::Base64; |
|
5
|
|
|
|
|
2245
|
|
|
5
|
|
|
|
|
264
|
|
11
|
5
|
|
|
5
|
|
1573
|
use Etcd3::Auth; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
184
|
|
12
|
5
|
|
|
5
|
|
1975
|
use Etcd3::Config; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
129
|
|
13
|
5
|
|
|
5
|
|
1601
|
use Etcd3::Watch; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
160
|
|
14
|
5
|
|
|
5
|
|
1801
|
use Etcd3::Lease; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
136
|
|
15
|
5
|
|
|
5
|
|
1679
|
use Etcd3::User; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
169
|
|
16
|
5
|
|
|
5
|
|
35
|
use Types::Standard qw(Str Int Bool HashRef); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
50
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
with('Etcd3::KV'); |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
5
|
|
4095
|
use namespace::clean; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
24
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=encoding utf8 |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Etcd3 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '0.007'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Etcd v3.1.0 or greater is required. To use the v3 API make sure to set environment |
35
|
|
|
|
|
|
|
variable ETCDCTL_API=3. Precompiled binaries can be downloaded at https://github.com/coreos/etcd/releases. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$etcd = Etcd3->new(); # host: 127.0.0.1 port: 2379 |
38
|
|
|
|
|
|
|
$etcd = Etcd3->new({ host => $host, port => $port, ssl => 1 }); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# put key |
41
|
|
|
|
|
|
|
$result = $etcd->put({ key =>'foo1', value => 'bar' }); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# get single key |
44
|
|
|
|
|
|
|
$key = $etcd->range({ key =>'test0' }); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# return single key value or the first in a list. |
47
|
|
|
|
|
|
|
$key->get_value |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# get range of keys |
50
|
|
|
|
|
|
|
$range = $etcd->range({ key =>'test0', range_end => 'test100' }); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# return array { key => value } pairs from range request. |
53
|
|
|
|
|
|
|
my @users = $range->all |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# watch key range, streaming. |
56
|
|
|
|
|
|
|
$watch = $etcd->watch( { key => 'foo', range_end => 'fop'}, sub { |
57
|
|
|
|
|
|
|
my ($result) = @_; |
58
|
|
|
|
|
|
|
print STDERR Dumper($result); |
59
|
|
|
|
|
|
|
})->create; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# create/grant 20 second lease |
62
|
|
|
|
|
|
|
$etcd->lease( { ID => 7587821338341002662, TTL => 20 } )->grant; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# attach lease to put |
65
|
|
|
|
|
|
|
$etcd->put( { key => 'foo2', value => 'bar2', lease => 7587821338341002662 } ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This module has been superseded by L and will be removed from CPAN on June 29th 2017 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 ACCESSORS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 host |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has host => ( |
79
|
|
|
|
|
|
|
is => 'ro', |
80
|
|
|
|
|
|
|
isa => Str, |
81
|
|
|
|
|
|
|
default => '127.0.0.1' |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 port |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
has port => ( |
89
|
|
|
|
|
|
|
is => 'ro', |
90
|
|
|
|
|
|
|
isa => Int, |
91
|
|
|
|
|
|
|
default => '2379' |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 username |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
has name => ( |
99
|
|
|
|
|
|
|
is => 'ro', |
100
|
|
|
|
|
|
|
isa => Str |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 password |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
has password => ( |
108
|
|
|
|
|
|
|
is => 'ro', |
109
|
|
|
|
|
|
|
isa => Str |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 ssl |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
has ssl => ( |
117
|
|
|
|
|
|
|
is => 'ro', |
118
|
|
|
|
|
|
|
isa => Bool, |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 api_root |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
has api_root => ( is => 'lazy' ); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub _build_api_root { |
128
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
129
|
|
|
|
|
|
|
return |
130
|
0
|
0
|
|
|
|
|
( $self->ssl ? 'https' : 'http' ) . '://' |
131
|
|
|
|
|
|
|
. $self->host . ':' |
132
|
|
|
|
|
|
|
. $self->port; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 api_prefix |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
defaults to /v3alpha |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
has api_prefix => ( |
142
|
|
|
|
|
|
|
is => 'ro', |
143
|
|
|
|
|
|
|
isa => Str, |
144
|
|
|
|
|
|
|
default => '/v3alpha' |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 api_path |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
has api_path => ( is => 'lazy' ); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _build_api_path { |
154
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
155
|
0
|
|
|
|
|
|
return $self->api_root . $self->api_prefix; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 auth_token |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
has auth_token => ( is => 'lazy' ); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _build_auth_token { |
165
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
166
|
0
|
|
|
|
|
|
return Etcd3::Auth::Authenticate->new( |
167
|
|
|
|
|
|
|
etcd => $self, |
168
|
|
|
|
|
|
|
%$self |
169
|
|
|
|
|
|
|
)->token; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 PUBLIC METHODS |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 watch |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Returns a L object. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
$etcd->watch({ key =>'foo', range_end => 'fop' }) |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub watch { |
183
|
0
|
|
|
0
|
1
|
|
my ( $self, $options ) = @_; |
184
|
0
|
0
|
|
|
|
|
my $cb = pop if ref $_[-1] eq 'CODE'; |
185
|
0
|
0
|
|
|
|
|
return Etcd3::Watch->new( |
186
|
|
|
|
|
|
|
etcd => $self, |
187
|
|
|
|
|
|
|
cb => $cb, |
188
|
|
|
|
|
|
|
( $options ? %$options : () ), |
189
|
|
|
|
|
|
|
); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 role |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Returns a L object. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
$etcd->role({ role => 'foo' }); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub role { |
201
|
0
|
|
|
0
|
1
|
|
my ( $self, $options ) = @_; |
202
|
0
|
0
|
|
|
|
|
my $cb = pop if ref $_[-1] eq 'CODE'; |
203
|
0
|
0
|
|
|
|
|
return Etcd3::Auth::Role->new( |
204
|
|
|
|
|
|
|
etcd => $self, |
205
|
|
|
|
|
|
|
cb => $cb, |
206
|
|
|
|
|
|
|
( $options ? %$options : () ), |
207
|
|
|
|
|
|
|
); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 user_role |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Returns a L object. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
$etcd->user_role({ name => 'samba', role => 'foo' }); |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub user_role { |
219
|
0
|
|
|
0
|
1
|
|
my ( $self, $options ) = @_; |
220
|
0
|
0
|
|
|
|
|
my $cb = pop if ref $_[-1] eq 'CODE'; |
221
|
0
|
0
|
|
|
|
|
return Etcd3::User::Role->new( |
222
|
|
|
|
|
|
|
etcd => $self, |
223
|
|
|
|
|
|
|
cb => $cb, |
224
|
|
|
|
|
|
|
( $options ? %$options : () ), |
225
|
|
|
|
|
|
|
); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 auth |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Returns a L object. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub auth { |
235
|
0
|
|
|
0
|
1
|
|
my ( $self, $options ) = @_; |
236
|
0
|
0
|
|
|
|
|
my $cb = pop if ref $_[-1] eq 'CODE'; |
237
|
0
|
0
|
|
|
|
|
return Etcd3::Auth->new( |
238
|
|
|
|
|
|
|
etcd => $self, |
239
|
|
|
|
|
|
|
cb => $cb, |
240
|
|
|
|
|
|
|
( $options ? %$options : () ), |
241
|
|
|
|
|
|
|
); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 lease |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Returns a L object. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub lease { |
251
|
0
|
|
|
0
|
1
|
|
my ( $self, $options ) = @_; |
252
|
0
|
0
|
|
|
|
|
my $cb = pop if ref $_[-1] eq 'CODE'; |
253
|
0
|
0
|
|
|
|
|
return Etcd3::Lease->new( |
254
|
|
|
|
|
|
|
etcd => $self, |
255
|
|
|
|
|
|
|
cb => $cb, |
256
|
|
|
|
|
|
|
( $options ? %$options : () ), |
257
|
|
|
|
|
|
|
); |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head2 user |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Returns a L object. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub user { |
267
|
0
|
|
|
0
|
1
|
|
my ( $self, $options ) = @_; |
268
|
0
|
0
|
|
|
|
|
my $cb = pop if ref $_[-1] eq 'CODE'; |
269
|
0
|
0
|
|
|
|
|
return Etcd3::User->new( |
270
|
|
|
|
|
|
|
etcd => $self, |
271
|
|
|
|
|
|
|
cb => $cb, |
272
|
|
|
|
|
|
|
( $options ? %$options : () ), |
273
|
|
|
|
|
|
|
); |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head2 put |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Returns a L object. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=cut |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head2 range |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Returns a L object. |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=cut |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=head2 configuration |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
Initialize configuration checks to see it etcd is installed locally. |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=cut |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
sub configuration { |
295
|
0
|
|
|
0
|
1
|
|
Etcd3::Config->configuration; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
sub BUILD { |
299
|
0
|
|
|
0
|
0
|
|
my ( $self, $args ) = @_; |
300
|
0
|
0
|
|
|
|
|
if ( not -e $self->configuration->etcd ) { |
301
|
0
|
|
|
|
|
|
my $msg = "No etcd executable found\n"; |
302
|
0
|
|
|
|
|
|
$msg .= ">> Please install etcd - https://coreos.com/etcd/docs/latest/"; |
303
|
0
|
|
|
|
|
|
die $msg; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head1 AUTHOR |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
Sam Batschelet, |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
The L developers and community. |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head1 CAVEATS |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
The L v3 API is in heavy development and can change at anytime please see |
318
|
|
|
|
|
|
|
https://github.com/coreos/etcd/blob/master/Documentation/dev-guide/api_reference_v3.md |
319
|
|
|
|
|
|
|
for latest details. |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
Copyright 2017 Sam Batschelet (hexfusion). |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
326
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
327
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=cut |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
1; |