| 1 | package Net::Kubernetes::Role::APIAccess; | ||||||||||||||||||||||||||||||||
| 2 | 2 | $Net::Kubernetes::Role::APIAccess::VERSION = '0.05'; | |||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | require LWP::UserAgent; | |||||||||||||||||||||||||||||||
| 5 | 2 | require HTTP::Request; | |||||||||||||||||||||||||||||||
| 6 | 2 | require JSON; | |||||||||||||||||||||||||||||||
| 7 | 2 | require URI; | |||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | Net::Kubernetes::Role::APIAccess | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | version 0.05 | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 2 | has url => ( | |||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 23 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||||||||||
| 25 | default => 'http://localhost:8080', | ||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 2 | has base_path => ( | |||||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 30 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 31 | required => 1, | ||||||||||||||||||||||||||||||||
| 32 | default => '/api/v1beta3', | ||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 2 | has password => ( | |||||||||||||||||||||||||||||||
| 36 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 37 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 38 | required => 0, | ||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 2 | has username => ( | |||||||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 43 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 44 | required => 0, | ||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 2 | has ua => ( | |||||||||||||||||||||||||||||||
| 48 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 49 | isa => 'LWP::UserAgent', | ||||||||||||||||||||||||||||||||
| 50 | required => 1, | ||||||||||||||||||||||||||||||||
| 51 | builder => '_build_lwp_agent', | ||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 2 | has token => ( | |||||||||||||||||||||||||||||||
| 55 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 56 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 57 | required => 0 | ||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 2 | has 'json' => ( | |||||||||||||||||||||||||||||||
| 61 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 62 | isa => 'JSON', | ||||||||||||||||||||||||||||||||
| 63 | required => 1, | ||||||||||||||||||||||||||||||||
| 64 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 65 | builder => '_build_json', | ||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||
| 69 | 31 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.9
| |||||||||||||||||||||||||||||||||
| 70 | 31 | my $class = shift; | |||||||||||||||||||||||||||||||
| 71 | 31 | my(%input) = @_; | |||||||||||||||||||||||||||||||
| 72 | 31 | ▶ | if(ref($input{token})){ | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | if($input{token}->can('getlines')){ | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 74 | 1 | $input{token} = join('', $input{token}->getlines); | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | elsif (ref($input{token}) eq 'GLOB') { | ||||||||||||||||||||||||||||||||
| 77 | 0 | my $fh = $input{token}; | |||||||||||||||||||||||||||||||
| 78 | 0 | $input{token} = do{ local $/; <$fh>}; | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | ▶ | }elsif (exists $input{token} && -f $input{token}) { | |||||||||||||||||||||||||||||||
|
Condition100%3/3
exists $input{"token"} and -f $input{"token"}
MC/DC100%2/2
exists $input{"token"} and -f $input{"token"}
exists $input{"token"}
-f $input{"token"}
Truth table100%3/3
A and B
A= exists $input{"token"}B= -f $input{"token"}
| |||||||||||||||||||||||||||||||||
| 81 | 1 | open(my $fh, '<', $input{token}); | |||||||||||||||||||||||||||||||
| 82 | 1 | $input{token} = do{ local $/; <$fh>}; | |||||||||||||||||||||||||||||||
| 83 | 1 | close($fh); | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | 31 | return $class->$orig(%input); | |||||||||||||||||||||||||||||||
| 86 | 2 | }; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | sub path { | ||||||||||||||||||||||||||||||||
| 89 | 16 | ▶ | my($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 90 | 16 | return $self->url.$self->base_path; | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | sub _build_lwp_agent { | ||||||||||||||||||||||||||||||||
| 94 | 31 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_build_lwp_agent: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 95 | 31 | my $ua = LWP::UserAgent->new(agent=>'net-kubernetes-perl/0.01'); | |||||||||||||||||||||||||||||||
| 96 | 31 | $ua->ssl_opts(verify_hostname=>0); | |||||||||||||||||||||||||||||||
| 97 | 31 | return $ua; | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | sub _build_json { | ||||||||||||||||||||||||||||||||
| 101 | 10 | ▶ | return JSON->new->allow_blessed(1)->convert_blessed(1); | ||||||||||||||||||||||||||||||
|
Subroutine
_build_json: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | sub create_request { | ||||||||||||||||||||||||||||||||
| 105 | 17 | ▶ | my($self, @options) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
create_request: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 106 | 17 | my $req = HTTP::Request->new(@options); | |||||||||||||||||||||||||||||||
| 107 | 17 | ▶ | if ($self->username && $self->password) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$self->username and $self->password
MC/DC50%1/2
$self->username and $self->password
$self->username
$self->password
Truth table66%2/3
A and B
A= $self->usernameB= $self->password
| |||||||||||||||||||||||||||||||||
| 108 | 1 | $req->header(Authorization=>"Basic ".encode_base64($self->username.':'.$self->password)); | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | elsif($self->token){ | ||||||||||||||||||||||||||||||||
| 111 | 3 | $req->header(Authorization=>"Bearer ".$self->token); | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | 17 | return $req; | |||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 2 | return 42; | |||||||||||||||||||||||||||||||