| 1 | package Kubernetes::REST::HTTPRequest; | ||||||||||
| 2 | 39 | our $VERSION = '1.108'; | |||||||||
| 3 | # ABSTRACT: HTTP request object | ||||||||||
| 4 | 39 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 39 | ▶ | use Types::Standard qw/Str HashRef/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | |||||||||||
| 8 | 39 | has server => (is => 'ro'); | |||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | 39 | has credentials => (is => 'ro'); | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | sub authenticate { | ||||||||
|
Subroutine
authenticate: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 15 | 2 | my $self = shift; | |||||||||
| 16 | 2 | my $auth = $self->credentials; | |||||||||
| 17 | 2 | ▶ | if (defined $auth) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 1 | $self->headers->{ Authorization } = 'Bearer ' . $auth->token; | |||||||||
| 19 | } | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | 39 | has uri => (is => 'rw', isa => Str); | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 39 | has method => (is => 'rw', isa => Str); | |||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | has url => (is => 'rw', isa => Str, lazy => 1, default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||
| 30 | 1 | my $self = shift; | |||||||||
| 31 | 1 | ▶ | return $self->server->endpoint . $self->uri if $self->server; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | return ''; | |||||||||
| 33 | 39 | }); | |||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | has headers => (is => 'rw', isa => HashRef, default => sub { {} }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | 39 | has parameters => (is => 'rw', isa => HashRef); | |||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | 39 | has content => (is => 'rw', isa => Str); | |||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | 39 | 1; | |||||||||
| 46 | |||||||||||
| 47 | __END__ | ||||||||||
| 48 | |||||||||||
| 49 | =pod | ||||||||||
| 50 | |||||||||||
| 51 | =encoding UTF-8 | ||||||||||
| 52 | |||||||||||
| 53 | =head1 NAME | ||||||||||
| 54 | |||||||||||
| 55 | Kubernetes::REST::HTTPRequest - HTTP request object | ||||||||||
| 56 | |||||||||||
| 57 | =head1 VERSION | ||||||||||
| 58 | |||||||||||
| 59 | version 1.108 | ||||||||||
| 60 | |||||||||||
| 61 | =head1 SYNOPSIS | ||||||||||
| 62 | |||||||||||
| 63 | use Kubernetes::REST::HTTPRequest; | ||||||||||
| 64 | |||||||||||
| 65 | my $req = Kubernetes::REST::HTTPRequest->new( | ||||||||||
| 66 | method => 'GET', | ||||||||||
| 67 | url => 'https://kubernetes.local:6443/api/v1/pods', | ||||||||||
| 68 | headers => { 'Authorization' => 'Bearer token' }, | ||||||||||
| 69 | ); | ||||||||||
| 70 | |||||||||||
| 71 | =head1 DESCRIPTION | ||||||||||
| 72 | |||||||||||
| 73 | Internal HTTP request object used by L<Kubernetes::REST>. | ||||||||||
| 74 | |||||||||||
| 75 | =head2 server | ||||||||||
| 76 | |||||||||||
| 77 | Optional. L<Kubernetes::REST::Server> instance for building the full URL. | ||||||||||
| 78 | |||||||||||
| 79 | =head2 credentials | ||||||||||
| 80 | |||||||||||
| 81 | Optional. Credentials for authentication: a L<Kubernetes::REST::AuthToken>, a | ||||||||||
| 82 | L<Kubernetes::REST::AuthTokenFile>, or any other object with a C<token()> | ||||||||||
| 83 | method. | ||||||||||
| 84 | |||||||||||
| 85 | =head2 authenticate | ||||||||||
| 86 | |||||||||||
| 87 | Add authentication header from the C<credentials> attribute. | ||||||||||
| 88 | |||||||||||
| 89 | =head2 uri | ||||||||||
| 90 | |||||||||||
| 91 | The URI path (e.g., C</api/v1/pods>). | ||||||||||
| 92 | |||||||||||
| 93 | =head2 method | ||||||||||
| 94 | |||||||||||
| 95 | The HTTP method (GET, POST, PUT, DELETE, PATCH, etc.). | ||||||||||
| 96 | |||||||||||
| 97 | =head2 url | ||||||||||
| 98 | |||||||||||
| 99 | The complete URL. If not provided, constructed from C<server> and C<uri>. | ||||||||||
| 100 | |||||||||||
| 101 | =head2 headers | ||||||||||
| 102 | |||||||||||
| 103 | Hashref of HTTP headers. | ||||||||||
| 104 | |||||||||||
| 105 | =head2 parameters | ||||||||||
| 106 | |||||||||||
| 107 | Hashref of query parameters. | ||||||||||
| 108 | |||||||||||
| 109 | =head2 content | ||||||||||
| 110 | |||||||||||
| 111 | The request body content (typically JSON). L<Kubernetes::REST> sets this as | ||||||||||
| 112 | already UTF-8-encoded bytes; treat it as opaque and send it on the wire | ||||||||||
| 113 | unchanged. See L<Kubernetes::REST::Role::IO/Encoding contract>. | ||||||||||
| 114 | |||||||||||
| 115 | =head1 SEE ALSO | ||||||||||
| 116 | |||||||||||
| 117 | =over | ||||||||||
| 118 | |||||||||||
| 119 | =item * L<Kubernetes::REST> - Main API client | ||||||||||
| 120 | |||||||||||
| 121 | =item * L<Kubernetes::REST::HTTPResponse> - Response object | ||||||||||
| 122 | |||||||||||
| 123 | =item * L<Kubernetes::REST::Role::IO> - IO interface | ||||||||||
| 124 | |||||||||||
| 125 | =back | ||||||||||
| 126 | |||||||||||
| 127 | =head1 SUPPORT | ||||||||||
| 128 | |||||||||||
| 129 | =head2 Issues | ||||||||||
| 130 | |||||||||||
| 131 | Please report bugs and feature requests on GitHub at | ||||||||||
| 132 | L<https://github.com/pplu/kubernetes-rest/issues>. | ||||||||||
| 133 | |||||||||||
| 134 | =head2 IRC | ||||||||||
| 135 | |||||||||||
| 136 | Join C<#kubernetes> on C<irc.perl.org> or message Getty directly. | ||||||||||
| 137 | |||||||||||
| 138 | =head1 CONTRIBUTING | ||||||||||
| 139 | |||||||||||
| 140 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||
| 141 | |||||||||||
| 142 | =head1 AUTHORS | ||||||||||
| 143 | |||||||||||
| 144 | =over 4 | ||||||||||
| 145 | |||||||||||
| 146 | =item * | ||||||||||
| 147 | |||||||||||
| 148 | Torsten Raudssus <getty@cpan.org> | ||||||||||
| 149 | |||||||||||
| 150 | =item * | ||||||||||
| 151 | |||||||||||
| 152 | Jose Luis Martinez Torres <jlmartin@cpan.org> | ||||||||||
| 153 | |||||||||||
| 154 | =back | ||||||||||
| 155 | |||||||||||
| 156 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 157 | |||||||||||
| 158 | This software is Copyright (c) 2019-2026 by Jose Luis Martinez Torres <jlmartin@cpan.org>. | ||||||||||
| 159 | |||||||||||
| 160 | This is free software, licensed under: | ||||||||||
| 161 | |||||||||||
| 162 | The Apache License, Version 2.0, January 2004 | ||||||||||
| 163 | |||||||||||
| 164 | =cut | ||||||||||