blib/lib/Kubernetes/REST/HTTPTinyIO.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 84 CC 4 SCAR 17.0
CC
4
Cov
0%
call
12.0
call_streaming
6.0
BEGIN
2.0
CRAP 5.5
1 package Kubernetes::REST::HTTPTinyIO;
2 our $VERSION = '1.109';
3 # ABSTRACT: HTTP client using HTTP::Tiny
4 use Moo;
5 use HTTP::Tiny;
6 use IO::Socket::SSL;
7 use Kubernetes::REST::HTTPResponse;
8 use Types::Standard qw/Bool/;
9  
10 with 'Kubernetes::REST::Role::IO';
11  
12  
13 has ssl_verify_server => (is => 'ro', isa => Bool, default => 1);
14  
15  
16 has ssl_cert_file => (is => 'ro');
17  
18  
19 has ssl_cert_pem => (is => 'ro');
20  
21  
22 has ssl_key_file => (is => 'ro');
23  
24  
25 has ssl_key_pem => (is => 'ro');
26  
27  
28 has ssl_ca_file => (is => 'ro');
29  
30  
31 has ssl_ca_pem => (is => 'ro');
32  
33  
34 has timeout => (is => 'ro', default => sub { 310 });
35  
36  
37 has ua => (is => 'ro', lazy => 1, default => sub {
38 my $self = shift;
39 require IO::Socket::SSL::Utils;
40  
41 my %options;
42 $options{ SSL_verify_mode } = SSL_VERIFY_PEER if ($self->ssl_verify_server);
43  
44 if (defined $self->ssl_cert_pem) {
45 $options{ SSL_cert } = [ IO::Socket::SSL::Utils::PEM_string2cert($self->ssl_cert_pem) ];
46 } elsif (defined $self->ssl_cert_file) {
47 $options{ SSL_cert_file } = $self->ssl_cert_file;
48 }
49  
50 if (defined $self->ssl_key_pem) {
51 $options{ SSL_key } = IO::Socket::SSL::Utils::PEM_string2key($self->ssl_key_pem);
52 } elsif (defined $self->ssl_key_file) {
53 $options{ SSL_key_file } = $self->ssl_key_file;
54 }
55  
56 if (defined $self->ssl_ca_pem) {
57 $options{ SSL_ca } = [ IO::Socket::SSL::Utils::PEM_string2cert($self->ssl_ca_pem) ];
58 } elsif (defined $self->ssl_ca_file) {
59 $options{ SSL_ca_file } = $self->ssl_ca_file;
60 }
61  
62 return HTTP::Tiny->new(
63 agent => 'Kubernetes::REST Perl Client ' . ($Kubernetes::REST::VERSION // 'dev'),
64 timeout => $self->timeout,
65 SSL_options => \%options,
66 );
67 });
68  
69  
70 sub call {
71 my ($self, $req) = @_;
72  
73  
74 my $res = $self->ua->request(
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 (defined $res->{ content })?( content => $res->{ content } ) : (),
86 );
87 }
88  
89 sub call_streaming {
90 my ($self, $req, $data_callback) = @_;
91  
92  
93 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 (defined $res->{ content })?( content => $res->{ content } ) : (),
105 );
106 }
107  
108 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.109
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