| 1 | package Kubernetes::REST::HTTPTinyIO; | ||||||||||||||
| 2 | 3 | our $VERSION = '1.108'; | |||||||||||||
| 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 | 14 | ▶ | has timeout => (is => 'ro', default => sub { 310 }); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 35 | |||||||||||||||
| 36 | |||||||||||||||
| 37 | 1 | ▶ | has ua => (is => 'ro', lazy => 1, default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=28.5
| |||||||||||||||
| 38 | 1 | my $self = shift; | |||||||||||||
| 39 | 1 | require IO::Socket::SSL::Utils; | |||||||||||||
| 40 | |||||||||||||||
| 41 | 1 | my %options; | |||||||||||||
| 42 | 1 | ▶ | $options{ SSL_verify_mode } = SSL_VERIFY_PEER if ($self->ssl_verify_server); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | |||||||||||||||
| 44 | 1 | ▶ | 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 | 1 | ▶ | 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 | 1 | ▶ | 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 | 0 | $options{ SSL_ca_file } = $self->ssl_ca_file; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 1 | ▶ | return HTTP::Tiny->new( | ||||||||||||
|
Condition50%1/2
$Kubernetes::REST::VERSION // "dev"
MC/DC0%0/1
$Kubernetes::REST::VERSION // "dev"
$Kubernetes::REST::VERSION
Truth table50%1/2
A
A= $Kubernetes::REST::VERSION
| |||||||||||||||
| 63 | agent => 'Kubernetes::REST Perl Client ' . ($Kubernetes::REST::VERSION // 'dev'), | ||||||||||||||
| 64 | timeout => $self->timeout, | ||||||||||||||
| 65 | SSL_options => \%options, | ||||||||||||||
| 66 | ); | ||||||||||||||
| 67 | 3 | }); | |||||||||||||
| 68 | |||||||||||||||
| 69 | |||||||||||||||
| 70 | 8 | ▶ | sub call { | ||||||||||||
|
Subroutine
call: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 71 | 8 | my ($self, $req) = @_; | |||||||||||||
| 72 | |||||||||||||||
| 73 | |||||||||||||||
| 74 | 8 | ▶ | my $res = $self->ua->request( | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | $req->method, | ||||||||||||||
| 76 | $req->url, | ||||||||||||||
| 77 | { | ||||||||||||||
| 78 | headers => $req->headers, | ||||||||||||||
| 79 | (defined $req->content) ? (content => $req->content) : (), | ||||||||||||||
| 80 | } | ||||||||||||||
| 81 | ); | ||||||||||||||
| 82 | |||||||||||||||
| 83 | return Kubernetes::REST::HTTPResponse->new( | ||||||||||||||
| 84 | status => $res->{ status }, | ||||||||||||||
| 85 | 8 | ▶ | (defined $res->{ content })?( content => $res->{ content } ) : (), | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 86 | ); | ||||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | 2 | ▶ | sub call_streaming { | ||||||||||||
|
Subroutine
call_streaming: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 90 | 2 | my ($self, $req, $data_callback) = @_; | |||||||||||||
| 91 | |||||||||||||||
| 92 | |||||||||||||||
| 93 | 2 | my $res = $self->ua->request( | |||||||||||||
| 94 | $req->method, | ||||||||||||||
| 95 | $req->url, | ||||||||||||||
| 96 | { | ||||||||||||||
| 97 | headers => $req->headers, | ||||||||||||||
| 98 | data_callback => $data_callback, | ||||||||||||||
| 99 | } | ||||||||||||||
| 100 | ); | ||||||||||||||
| 101 | |||||||||||||||
| 102 | return Kubernetes::REST::HTTPResponse->new( | ||||||||||||||
| 103 | status => $res->{ status }, | ||||||||||||||
| 104 | 2 | ▶ | (defined $res->{ content })?( content => $res->{ content } ) : (), | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | ); | ||||||||||||||
| 106 | } | ||||||||||||||
| 107 | |||||||||||||||
| 108 | 3 | 1; | |||||||||||||
| 109 | |||||||||||||||
| 110 | __END__ | ||||||||||||||
| 111 | |||||||||||||||
| 112 | =pod | ||||||||||||||
| 113 | |||||||||||||||
| 114 | =encoding UTF-8 | ||||||||||||||
| 115 | |||||||||||||||
| 116 | =head1 NAME | ||||||||||||||
| 117 | |||||||||||||||
| 118 | Kubernetes::REST::HTTPTinyIO - HTTP client using HTTP::Tiny | ||||||||||||||
| 119 | |||||||||||||||
| 120 | =head1 VERSION | ||||||||||||||
| 121 | |||||||||||||||
| 122 | version 1.108 | ||||||||||||||
| 123 | |||||||||||||||
| 124 | =head1 SYNOPSIS | ||||||||||||||
| 125 | |||||||||||||||
| 126 | use Kubernetes::REST::HTTPTinyIO; | ||||||||||||||
| 127 | |||||||||||||||
| 128 | my $io = Kubernetes::REST::HTTPTinyIO->new( | ||||||||||||||
| 129 | ssl_verify_server => 1, | ||||||||||||||
| 130 | ssl_ca_file => '/path/to/ca.crt', | ||||||||||||||
| 131 | ); | ||||||||||||||
| 132 | |||||||||||||||
| 133 | =head1 DESCRIPTION | ||||||||||||||
| 134 | |||||||||||||||
| 135 | HTTP client implementation using L<HTTP::Tiny> for making Kubernetes API requests. Lighter alternative to L<Kubernetes::REST::LWPIO>. | ||||||||||||||
| 136 | |||||||||||||||
| 137 | Response bodies are returned as bytes - L<HTTP::Tiny> hands back the body unmodified and never decodes a charset. See L<Kubernetes::REST::Role::IO/Encoding contract>. | ||||||||||||||
| 138 | |||||||||||||||
| 139 | This backend does not implement C<call_duplex>: L<Kubernetes::REST> methods that | ||||||||||||||
| 140 | need full-duplex transport (C<port_forward>, C<exec>, C<attach>) croak against | ||||||||||||||
| 141 | it by design. Use L<Net::Async::Kubernetes> for those. | ||||||||||||||
| 142 | |||||||||||||||
| 143 | =head2 ssl_verify_server | ||||||||||||||
| 144 | |||||||||||||||
| 145 | Boolean. Whether to verify the server's SSL certificate. Defaults to true. | ||||||||||||||
| 146 | |||||||||||||||
| 147 | =head2 ssl_cert_file | ||||||||||||||
| 148 | |||||||||||||||
| 149 | Path to a client certificate file (PEM) for TLS client-certificate authentication. Ignored when C<ssl_cert_pem> is set. | ||||||||||||||
| 150 | |||||||||||||||
| 151 | =head2 ssl_cert_pem | ||||||||||||||
| 152 | |||||||||||||||
| 153 | Client certificate as a PEM string, for TLS client-certificate authentication. Takes precedence over C<ssl_cert_file>. | ||||||||||||||
| 154 | |||||||||||||||
| 155 | =head2 ssl_key_file | ||||||||||||||
| 156 | |||||||||||||||
| 157 | Path to the private key file (PEM) matching C<ssl_cert_file> or C<ssl_cert_pem>. Ignored when C<ssl_key_pem> is set. | ||||||||||||||
| 158 | |||||||||||||||
| 159 | =head2 ssl_key_pem | ||||||||||||||
| 160 | |||||||||||||||
| 161 | Private key as a PEM string, matching C<ssl_cert_file> or C<ssl_cert_pem>. Takes precedence over C<ssl_key_file>. | ||||||||||||||
| 162 | |||||||||||||||
| 163 | =head2 ssl_ca_file | ||||||||||||||
| 164 | |||||||||||||||
| 165 | Path to a CA certificate file (PEM) used to verify the server's certificate. Ignored when C<ssl_ca_pem> is set. | ||||||||||||||
| 166 | |||||||||||||||
| 167 | =head2 ssl_ca_pem | ||||||||||||||
| 168 | |||||||||||||||
| 169 | CA certificate as a PEM string, used to verify the server's certificate. Takes precedence over C<ssl_ca_file>. | ||||||||||||||
| 170 | |||||||||||||||
| 171 | =head2 timeout | ||||||||||||||
| 172 | |||||||||||||||
| 173 | Timeout in seconds for HTTP requests. Defaults to 310 (slightly more than the Kubernetes default watch timeout of 300s). | ||||||||||||||
| 174 | |||||||||||||||
| 175 | =head2 ua | ||||||||||||||
| 176 | |||||||||||||||
| 177 | The underlying L<HTTP::Tiny> instance. | ||||||||||||||
| 178 | |||||||||||||||
| 179 | =head2 call | ||||||||||||||
| 180 | |||||||||||||||
| 181 | my $response = $io->call($req); | ||||||||||||||
| 182 | |||||||||||||||
| 183 | Execute an HTTP request. Receives a fully prepared L<Kubernetes::REST::HTTPRequest> (URL, headers, content all set). Returns a L<Kubernetes::REST::HTTPResponse>. | ||||||||||||||
| 184 | |||||||||||||||
| 185 | =head2 call_streaming | ||||||||||||||
| 186 | |||||||||||||||
| 187 | my $response = $io->call_streaming($req, sub { my ($chunk) = @_; ... }); | ||||||||||||||
| 188 | |||||||||||||||
| 189 | Execute an HTTP request with streaming response. The C<$data_callback> is called with each chunk of data as it arrives. | ||||||||||||||
| 190 | |||||||||||||||
| 191 | Used internally by L<Kubernetes::REST/watch> and L<Kubernetes::REST/log> for the Watch and Pod Log APIs. | ||||||||||||||
| 192 | |||||||||||||||
| 193 | =head1 SEE ALSO | ||||||||||||||
| 194 | |||||||||||||||
| 195 | =over | ||||||||||||||
| 196 | |||||||||||||||
| 197 | =item * L<Kubernetes::REST> - Main API client | ||||||||||||||
| 198 | |||||||||||||||
| 199 | =item * L<Kubernetes::REST::Role::IO> - IO interface role | ||||||||||||||
| 200 | |||||||||||||||
| 201 | =item * L<Kubernetes::REST::LWPIO> - LWP::UserAgent backend (default) | ||||||||||||||
| 202 | |||||||||||||||
| 203 | =back | ||||||||||||||
| 204 | |||||||||||||||
| 205 | =head1 SUPPORT | ||||||||||||||
| 206 | |||||||||||||||
| 207 | =head2 Issues | ||||||||||||||
| 208 | |||||||||||||||
| 209 | Please report bugs and feature requests on GitHub at | ||||||||||||||
| 210 | L<https://github.com/pplu/kubernetes-rest/issues>. | ||||||||||||||
| 211 | |||||||||||||||
| 212 | =head2 IRC | ||||||||||||||
| 213 | |||||||||||||||
| 214 | Join C<#kubernetes> on C<irc.perl.org> or message Getty directly. | ||||||||||||||
| 215 | |||||||||||||||
| 216 | =head1 CONTRIBUTING | ||||||||||||||
| 217 | |||||||||||||||
| 218 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||
| 219 | |||||||||||||||
| 220 | =head1 AUTHORS | ||||||||||||||
| 221 | |||||||||||||||
| 222 | =over 4 | ||||||||||||||
| 223 | |||||||||||||||
| 224 | =item * | ||||||||||||||
| 225 | |||||||||||||||
| 226 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||
| 227 | |||||||||||||||
| 228 | =item * | ||||||||||||||
| 229 | |||||||||||||||
| 230 | Jose Luis Martinez Torres <jlmartin@cpan.org> | ||||||||||||||
| 231 | |||||||||||||||
| 232 | =back | ||||||||||||||
| 233 | |||||||||||||||
| 234 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 235 | |||||||||||||||
| 236 | This software is Copyright (c) 2019-2026 by Jose Luis Martinez Torres <jlmartin@cpan.org>. | ||||||||||||||
| 237 | |||||||||||||||
| 238 | This is free software, licensed under: | ||||||||||||||
| 239 | |||||||||||||||
| 240 | The Apache License, Version 2.0, January 2004 | ||||||||||||||
| 241 | |||||||||||||||
| 242 | =cut | ||||||||||||||