| 1 | 9 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Net::Etcd::Role::Actions; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use AE; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Types::Standard qw(InstanceOf); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use AnyEvent::HTTP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | Net::Etcd::Role::Actions | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | our $VERSION = '0.022'; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | has etcd => ( | |||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | isa => InstanceOf ['Net::Etcd'], | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =head2 json_args | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | arguments that will be sent to the api | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | has json_args => ( is => 'lazy', ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub _build_json_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_json_args: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $args; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | for my $key ( keys %{$self} ) { | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | unless ( $key =~ /(?:etcd|cb|cv|hold|json_args|endpoint)$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $args->{$key} = $self->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return to_json($args); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | =head2 cb | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | AnyEvent callback must be a CodeRef | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | has cb => ( | ||||||||||||||||||||||||||||||||||||||||||
| 60 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | isa => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | die "$_[0] is not a CodeRef!" if ( $_[0] && ref( $_[0] ) ne 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[0] and ref $_[0] ne "CODE"
MC/DC0%0/2
$_[0] and ref $_[0] ne "CODE"
$_[0]
ref $_[0] ne "CODE"
Truth table0%0/3
A and B
A= $_[0]B= ref $_[0] ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 9 | ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =head2 cv | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 9 | has cv => ( is => 'ro', ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | =head2 init | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $init = $self->json_args; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $init or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | =head2 headers | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 9 | has headers => ( | |||||||||||||||||||||||||||||||||||||||||
| 88 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
| 89 | clearer => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub _build_headers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_headers: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $headers; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $token = $self->etcd->auth_token; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $headers->{'Content-Type'} = 'application/json'; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | unless ( $self->endpoint =~ m/authenticate/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $headers->{'Authorization'} = $token if $token; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | return $headers; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 9 | has tls_ctx => ( is => 'lazy', ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub _build_tls_ctx { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_tls_ctx: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $ca_file = $self->etcd->ca_file; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $key_file = $self->etcd->key_file; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $cert_file = $self->etcd->cert_file; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $cacert = $self->etcd->cacert; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $tls; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | $tls->{ca_file} = $ca_file if $ca_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $tls->{key_file} = $key_file if $key_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $tls->{cert_file} = $cert_file if $cert_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $tls->{cacert} = $cacert if $cacert; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ( $ca_file || $key_file || $cert_file ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$ca_file or $key_file or $cert_file
$ca_file or $key_file
MC/DC0%0/3
$ca_file or $key_file or $cert_file
$ca_file
$key_file
$cert_file
Truth table0%0/4
A or B or C
A= $ca_fileB= $key_fileC= $cert_file
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $tls->{verify} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return $tls; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return 'low'; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | =head2 hold | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | When set will not fire request. | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 9 | has hold => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | =head2 response | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 9 | has response => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | =head2 retry_auth | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | When set will retry authentication request and update token | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 9 | has retry_auth => ( | |||||||||||||||||||||||||||||||||||||||||
| 145 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 146 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =head2 request | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 9 | has request => ( is => 'lazy', ); | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub _build_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_request: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ( $self->{retry_auth} > 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | confess | |||||||||||||||||||||||||||||||||||||||||
| 159 | "Error: Unable to authenticate, check your username and password"; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $self->{retry_auth} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $cb = $self->cb; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $cv = $self->cv ? $self->cv : AE::cv; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $cv->begin; | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | http_request( | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 'POST', | ||||||||||||||||||||||||||||||||||||||||||
| 170 | $self->etcd->api_path . $self->{endpoint}, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | headers => $self->headers, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | body => $self->json_args, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | tls_ctx => $self->tls_ctx, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | on_header => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my ($headers) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $self->{response}{headers} = $headers; | |||||||||||||||||||||||||||||||||||||||||
| 177 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | want_body_handle => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my ( $handle, $hdr ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | my $json_reader = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my ( $handle, $json ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | return unless $json; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $self->{response}{content} = JSON::encode_json($json); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $cb->( $json, $hdr ) if $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my $status = $hdr->{Status}; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $self->check_hdr($status); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $cv->send; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my $chunk_reader = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my ( $handle, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | return unless $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | #read chunk size | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | $line =~ /^([0-9a-fA-F]+)/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | or die 'bad chunk (incorrect length) -[' . $line . ']-'; | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $len = hex $1; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | #read chunk | ||||||||||||||||||||||||||||||||||||||||||
| 200 | $handle->push_read( | ||||||||||||||||||||||||||||||||||||||||||
| 201 | chunk => $len, | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my ( $handle, $chunk ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 204 | $handle->push_read( | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | line => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | length $_[1] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | and die 'bad chunk (missing last empty line)'; | ||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $self->{response}{content} = $chunk; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | $cb->( $chunk, $hdr ) if $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $status = $hdr->{Status}; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $self->check_hdr($status); | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $cv->send; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ( ( $hdr->{'transfer-encoding'} || '' ) =~ /\bchunked\b/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$hdr->{'transfer-encoding'} || ''
MC/DC0%0/1
$hdr->{'transfer-encoding'} || ''
$hdr->{'transfer-encoding'}
Truth table0%0/2
A
A= $hdr->{'transfer-encoding'}
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | $handle->on_read( | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | sub { $handle->push_read( line => $chunk_reader ) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | $handle->on_read( | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub { $handle->push_read( json => $json_reader ) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | $handle->on_eof( sub { $handle->destroy; $cv->end } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | $handle->on_error( sub { $handle->destroy; $cv->end } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $cv->recv; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $self->clear_headers; | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ( defined $self->{retry_auth} && $self->{retry_auth} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"retry_auth"} and $self->{"retry_auth"}
MC/DC0%0/2
defined $self->{"retry_auth"} and $self->{"retry_auth"}
defined $self->{"retry_auth"}
$self->{"retry_auth"}
Truth table0%0/3
A and B
A= defined $self->{"retry_auth"}B= $self->{"retry_auth"}
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $auth = $self->etcd->auth()->authenticate; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if ( $auth->{response}{success} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $self->{retry_auth} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $self->request; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | =head2 get_value | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | returns single decoded value or the first. | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub get_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_value: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my $response = $self->response; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | eval { $content = from_json( $response->{content} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | return if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | #print STDERR Dumper($content); | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my $value = $content->{kvs}->[0]->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | $value or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | return decode_base64($value); | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | =head2 all | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | returns list containing for example: | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 'mod_revision' => '3', | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 'version' => '1', | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 'value' => 'bar', | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 'create_revision' => '3', | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 'key' => 'foo0' | ||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | where key and value have been decoded for your pleasure. | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | sub all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $response = $self->response; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | eval { $content = from_json( $response->{content} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | return if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $kvs = $content->{kvs}; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | for my $row (@$kvs) { | |||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | $row->{value} = decode_base64( $row->{value} ); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $row->{key} = decode_base64( $row->{key} ); | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | return $kvs; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | =head2 is_success | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | Success is returned if the response is a 200 | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | sub is_success { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_success: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $response = $self->response; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ( defined $response->{success} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | return $response->{success}; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | =head2 content | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | returns JSON decoded content hash | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | sub content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $response = $self->response; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | eval { $content = from_json( $response->{content} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | return if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | return $content if $content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | =head2 check_hdr | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | check response header then define success and retry_auth. | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | sub check_hdr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_hdr: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my ( $self, $status ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | my $success = $status == 200 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $self->{response}{success} = $success; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | $self->{retry_auth}++ if $status == 401; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||