| 1 | package cPanel::APIClient::TransportBase::HTTPBase; | ||||||||||
| 2 | |||||||||||
| 3 | # Copyright 2020 cPanel, L. L. C. | ||||||||||
| 4 | # All rights reserved. | ||||||||||
| 5 | # http://cpanel.net | ||||||||||
| 6 | # | ||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under the | ||||||||||
| 8 | # same terms as Perl itself. See L<perlartistic>. | ||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | ▶ | use parent qw( cPanel::APIClient::Transport ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 2 | my @_REQUIRED = ('hostname'); | |||||||||
| 16 | |||||||||||
| 17 | 8 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||
| 18 | 8 | my ( $class, $authn, %opts ) = @_; | |||||||||
| 19 | |||||||||||
| 20 | 8 | ▶ | if ( $authn->isa('cPanel::APIClient::Authn::Username') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 0 | die("HTTP-based transport $class doesn’t work with Username authentication."); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 8 | my @missing = grep { !defined $opts{$_} } @_REQUIRED; | |||||||||
| 25 | 8 | ▶ | die( __PACKAGE__ . ": Missing @missing" ) if @missing; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | return bless { | ||||||||||
| 28 | authn => $authn, | ||||||||||
| 29 | 8 | hostname => $opts{'hostname'}, | |||||||||
| 30 | }, $class; | ||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 9 | ▶ | sub _get_url_base { | ||||||||
|
Subroutine
_get_url_base: called CC=2 SCAR=7.0
| |||||||||||
| 34 | 9 | my ( $self, $service_obj ) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 9 | my $url = "https://" . $self->{'hostname'}; | |||||||||
| 37 | 9 | ▶ | if ( my $port = $service_obj->get_https_port() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 9 | $url .= ":$port"; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 9 | return $url; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 16 | ▶ | sub _needs_session { | ||||||||
|
Subroutine
_needs_session: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 16 | my ($self) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 16 | return $self->{'authn'}->needs_session(); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 8 | ▶ | sub _assemble_request_pieces { | ||||||||
|
Subroutine
_assemble_request_pieces: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 8 | my ( $self, $service_obj, $request_obj ) = @_; | |||||||||
| 52 | |||||||||||
| 53 | 8 | my $method = $request_obj->get_http_method(); | |||||||||
| 54 | |||||||||||
| 55 | my @headers = ( | ||||||||||
| 56 | 8 | $self->{'authn'}->get_http_headers_for_service($service_obj), | |||||||||
| 57 | $request_obj->get_http_headers(), | ||||||||||
| 58 | ); | ||||||||||
| 59 | |||||||||||
| 60 | 8 | my $payload = $request_obj->get_http_payload(); | |||||||||
| 61 | |||||||||||
| 62 | 8 | my $url = $self->_get_url_base($service_obj); | |||||||||
| 63 | 8 | $url .= $self->{'authn'}->get_url_path_prefix(); | |||||||||
| 64 | 8 | $url .= $request_obj->get_http_url_path(); | |||||||||
| 65 | |||||||||||
| 66 | 8 | return ( $method, $url, \@headers, $payload ); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 2 | 1; | |||||||||