| 1 | package Kubernetes::REST::HTTPTinyIO; | ||||||||||||||||||||
| 2 | 3 | our $VERSION = '1.110'; | |||||||||||||||||||
| 3 | # ABSTRACT: HTTP client using HTTP::Tiny | ||||||||||||||||||||
| 4 | 3 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use HTTP::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 3 | ▶ | use IO::Socket::SSL; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 3 | ▶ | use Kubernetes::REST::HTTPResponse; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use Types::Standard qw/Bool/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | with 'Kubernetes::REST::Role::IO'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 3 | has ssl_verify_server => (is => 'ro', isa => Bool, default => 1); | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 3 | has ssl_cert_file => (is => 'ro'); | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 3 | has ssl_cert_pem => (is => 'ro'); | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 3 | has ssl_key_file => (is => 'ro'); | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 3 | has ssl_key_pem => (is => 'ro'); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 3 | has ssl_ca_file => (is => 'ro'); | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 3 | has ssl_ca_pem => (is => 'ro'); | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 16 | ▶ | has timeout => (is => 'ro', default => sub { 310 }); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 4 | ▶ | has ua => (is => 'ro', lazy => 1, default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=25.7
| |||||||||||||||||||||
| 38 | 4 | my $self = shift; | |||||||||||||||||||
| 39 | 4 | require IO::Socket::SSL::Utils; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 4 | my %options; | |||||||||||||||||||
| 42 | 4 | ▶ | $options{ SSL_verify_mode } = $self->ssl_verify_server ? SSL_VERIFY_PEER : SSL_VERIFY_NONE; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 4 | ▶ | if (defined $self->ssl_cert_pem) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 45 | 0 | $options{ SSL_cert } = [ IO::Socket::SSL::Utils::PEM_string2cert($self->ssl_cert_pem) ]; | |||||||||||||||||||
| 46 | } elsif (defined $self->ssl_cert_file) { | ||||||||||||||||||||
| 47 | 0 | $options{ SSL_cert_file } = $self->ssl_cert_file; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 4 | ▶ | if (defined $self->ssl_key_pem) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 51 | 0 | $options{ SSL_key } = IO::Socket::SSL::Utils::PEM_string2key($self->ssl_key_pem); | |||||||||||||||||||
| 52 | } elsif (defined $self->ssl_key_file) { | ||||||||||||||||||||
| 53 | 0 | $options{ SSL_key_file } = $self->ssl_key_file; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 4 | ▶ | if (defined $self->ssl_ca_pem) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 57 | 0 | $options{ SSL_ca } = [ IO::Socket::SSL::Utils::PEM_string2cert($self->ssl_ca_pem) ]; | |||||||||||||||||||
| 58 | } elsif (defined $self->ssl_ca_file) { | ||||||||||||||||||||
| 59 | 1 | $options{ SSL_ca_file } = $self->ssl_ca_file; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 4 | ▶ | return HTTP::Tiny->new( | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$Kubernetes::REST::VERSION // "dev"
MC/DC100%1/1
$Kubernetes::REST::VERSION // "dev"
$Kubernetes::REST::VERSION
Truth table100%2/2
A
A= $Kubernetes::REST::VERSION
| |||||||||||||||||||||
| 63 | agent => 'Kubernetes::REST Perl Client ' . ($Kubernetes::REST::VERSION // 'dev'), | ||||||||||||||||||||
| 64 | timeout => $self->timeout, | ||||||||||||||||||||
| 65 | verify_SSL => $self->ssl_verify_server ? 1 : 0, | ||||||||||||||||||||
| 66 | SSL_options => \%options, | ||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||
| 68 | 3 | }); | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 11 | ▶ | sub call { | ||||||||||||||||||
|
Subroutine
call: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 72 | 11 | my ($self, $req) = @_; | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 11 | ▶ | my $res = $self->ua->request( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | $req->method, | ||||||||||||||||||||
| 77 | $req->url, | ||||||||||||||||||||
| 78 | { | ||||||||||||||||||||
| 79 | headers => $req->headers, | ||||||||||||||||||||
| 80 | (defined $req->content) ? (content => $req->content) : (), | ||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | return Kubernetes::REST::HTTPResponse->new( | ||||||||||||||||||||
| 85 | status => $res->{ status }, | ||||||||||||||||||||
| 86 | 11 | ▶ | (defined $res->{ content })?( content => $res->{ content } ) : (), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 8 | ▶ | sub call_streaming { | ||||||||||||||||||
|
Subroutine
call_streaming: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 91 | 8 | my ($self, $req, $data_callback) = @_; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | # HTTP::Tiny turns a die in data_callback into a 599; keep the original | ||||||||||||||||||||
| 95 | # exception and rethrow it unchanged after the request. | ||||||||||||||||||||
| 96 | 8 | my ( $failed, $error ); | |||||||||||||||||||
| 97 | my $res = $self->ua->request( | ||||||||||||||||||||
| 98 | $req->method, | ||||||||||||||||||||
| 99 | $req->url, | ||||||||||||||||||||
| 100 | { | ||||||||||||||||||||
| 101 | headers => $req->headers, | ||||||||||||||||||||
| 102 | 6 | ▶ | data_callback => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 103 | 6 | ▶ | return if $failed; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | 6 | ▶ | unless ( eval { $data_callback->(@_); 1 } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | 2 | ( $failed, $error ) = ( 1, $@ ); | |||||||||||||||||||
| 106 | 2 | die $error; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | }, | ||||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | 8 | ); | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 8 | ▶ | die $error if $failed; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | return Kubernetes::REST::HTTPResponse->new( | ||||||||||||||||||||
| 115 | status => $res->{ status }, | ||||||||||||||||||||
| 116 | 6 | ▶ | (defined $res->{ content })?( content => $res->{ content } ) : (), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 3 | 1; | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||