line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
19765
|
use utf8; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
20
|
|
2
|
|
|
|
|
|
|
package Etcd3::Role::Actions; |
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
103
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
44
|
|
5
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
57
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
8
|
use Moo::Role; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
16
|
|
8
|
3
|
|
|
3
|
|
702
|
use JSON; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
17
|
|
9
|
3
|
|
|
3
|
|
325
|
use HTTP::Tiny; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
60
|
|
10
|
3
|
|
|
3
|
|
12
|
use MIME::Base64; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
184
|
|
11
|
3
|
|
|
3
|
|
11
|
use Types::Standard qw(InstanceOf); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
25
|
|
12
|
3
|
|
|
3
|
|
1185
|
use Data::Dumper; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
110
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
12
|
use namespace::clean; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
20
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=encoding utf8 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Etcd3::Role::Actions |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has _client => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
isa => InstanceOf ['Etcd3::Client'], |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 headers |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has headers => ( is => 'ro' ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 request |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has request => ( is => 'lazy', ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _build_request { |
44
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
45
|
0
|
|
|
|
|
|
my @response; |
46
|
|
|
|
|
|
|
my $request = "HTTP::Tiny"->new->post( |
47
|
|
|
|
|
|
|
$self->_client->api_path |
48
|
|
|
|
|
|
|
. $self->{endpoint} => { |
49
|
|
|
|
|
|
|
content => $self->{json_args}, |
50
|
0
|
|
|
|
|
|
headers => $self->headers |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
# print STDERR Dumper($self); |
54
|
0
|
|
|
|
|
|
return $request; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 get_value |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
returns single decoded value or the first. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub get_value { |
64
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
65
|
0
|
|
|
|
|
|
my $response = $self->request; |
66
|
0
|
|
|
|
|
|
my $content = from_json( $response->{content} ); |
67
|
|
|
|
|
|
|
# print STDERR Dumper($content); |
68
|
0
|
|
|
|
|
|
my $value = $content->{kvs}->[0]->{value}; |
69
|
0
|
0
|
|
|
|
|
$value or return; |
70
|
0
|
|
|
|
|
|
return decode_base64($value); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 all |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
returns list containing for example: |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
'mod_revision' => '3', |
79
|
|
|
|
|
|
|
'version' => '1', |
80
|
|
|
|
|
|
|
'value' => 'bar', |
81
|
|
|
|
|
|
|
'create_revision' => '3', |
82
|
|
|
|
|
|
|
'key' => 'foo0' |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
where key and value have been decoded for your pleasure. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub all { |
90
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
91
|
0
|
|
|
|
|
|
my $response = $self->request; |
92
|
0
|
|
|
|
|
|
my $content = from_json( $response->{content} ); |
93
|
0
|
|
|
|
|
|
my $kvs = $content->{kvs}; |
94
|
0
|
|
|
|
|
|
for my $row (@$kvs) { |
95
|
0
|
|
|
|
|
|
$row->{value} = decode_base64( $row->{value} ); |
96
|
0
|
|
|
|
|
|
$row->{key} = decode_base64( $row->{key} ); |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
return $kvs; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 authenticate |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
returns an Etcd3::Auth::Authenticate object |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub authenticate { |
108
|
0
|
|
|
0
|
1
|
|
my ( $self, $options ) = @_; |
109
|
0
|
0
|
|
|
|
|
return Etcd3::Auth::Authenticate->new( |
110
|
|
|
|
|
|
|
_client => $self, |
111
|
|
|
|
|
|
|
( $options ? %$options : () ), |
112
|
|
|
|
|
|
|
)->init; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|