Client/Auth/v3.pm

filter: Statementstmt 96.2% 51 / 53 Branchbran 84.6% 22 / 26 Conditioncond 69.2% 9 / 13 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 7 totaltotal 79.4% 93 / 117 CC 21 SCAR 22.4
CC
21
Cov
89%
service
14.8
new
8.0
body
2.0
CRAP 9.4
« Client/Auth/v2.pm ↑ Summary Client/Response.pm »
1 #
2 # Copyright (c) 2019 cPanel, L.L.C.
3 # All rights reserved.
4 # http://cpanel.net/
5 #
6 # Distributed under the terms of the MIT license. See the LICENSE file for
7 # further details.
8 #
9 package OpenStack::Client::Auth::v3;
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use OpenStack::Client ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub new ($$%) {
17 14 ▶ my ($class, $endpoint, %args) = @_;
Subroutine new: called CC=8 SCAR=20.8
Pod undocumented
18  
19 14 ▶ die 'No OpenStack username provided in "username"' unless defined $args{'username'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"username"} 1 13 14
20 13 ▶ die 'No OpenStack password provided in "password"' unless defined $args{'password'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"password"} 1 12 13
21  
22 12 ▶ $args{'domain'} ||= 'default';
Condition50%1/2
$args{"domain"} ||= "default"
l!l
012
MC/DC0%0/1
$args{"domain"} ||= "default"
$args{"domain"}
Truth table50%1/2
A
A= $args{"domain"}
Aresult
11
00
23  
24 my $client = OpenStack::Client->new($endpoint,
25 'package_ua' => $args{'package_ua'},
26 'package_request' => $args{'package_request'},
27 12 'package_response' => $args{'package_response'}
28 );
29  
30 my %request = (
31 'auth' => {
32 'identity' => {
33 'methods' => [qw(password)],
34 'password' => {
35 'user' => {
36 'name' => $args{'username'},
37 'password' => $args{'password'},
38 'domain' => {
39 12 'name' => $args{'domain'}
40 }
41 }
42 }
43 }
44 }
45 );
46  
47 12 ▶ $request{'auth'}->{'scope'} = $args{'scope'} if defined $args{'scope'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"scope"} 0 12 12
48  
49 12 my $response = $client->request(
50 'method' => 'POST',
51 'path' => '/auth/tokens',
52 'body' => \%request
53 );
54  
55 12 my $body = $response->decode_json;
56  
57 12 ▶ unless (defined $response->header('X-Subject-Token')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response->header("X-Subject-Token")) 1 11 12
58 1 die 'No token found in response headers';
59 }
60  
61 11 ▶ unless (defined $body->{'token'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $body->{"token"}) 1 10 11
62 1 die 'No token found in response body';
63 }
64  
65 10 ▶ unless (defined $body->{'token'}->{'catalog'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $body->{"token"}{"catalog"}) 1 9 10
66 1 die 'No service catalog found in response body token';
67 }
68  
69 return bless {
70 'package_ua' => $args{'package_ua'},
71 'package_request' => $args{'package_request'},
72 'package_response' => $args{'package_response'},
73 'response' => $response,
74 'body' => $body,
75 'clients' => {},
76 9 'services' => $body->{'token'}->{'catalog'}
77 }, $class;
78 }
79  
80 sub body ($) {
81 0 ▶ shift->{'body'};
Subroutine body: not called CC=1 SCAR=6.9
Pod undocumented
82 }
83  
84 sub response ($) {
85 1 ▶ shift->{'response'};
Subroutine response: called CC=1 SCAR=0.0
Pod undocumented
86 }
87  
88 sub access ($) {
89 1 ▶ shift->{'body'}->{'access'};
Subroutine access: called CC=1 SCAR=0.0
Pod undocumented
90 }
91  
92 sub token ($) {
93 8 ▶ shift->{'response'}->header('X-Subject-Token');
Subroutine token: called CC=1 SCAR=0.0
Pod undocumented
94 }
95  
96 sub services ($) {
97 1 ▶ my ($self) = @_;
Subroutine services: called CC=1 SCAR=0.0
Pod undocumented
98  
99 my %types = map {
100 1 $_->{'type'} => 1
101 1 } @{$self->{'services'}};
102  
103 1 return sort keys %types;
104 }
105  
106 sub service ($$%) {
107 10 ▶ my ($self, $type, %opts) = @_;
Subroutine service: called CC=14 SCAR=27.0
Pod undocumented
108  
109 10 ▶ if (defined $self->{'clients'}->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"clients"}{$type}) 2 8 10
110 2 return $self->{'clients'}->{$type};
111 }
112  
113 8 ▶ if (defined $opts{'uri'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"uri"}) 1 7 8
114 return $self->{'clients'}->{$type} = OpenStack::Client->new($opts{'uri'},
115 'package_ua' => $self->{'package_ua'},
116 'package_request' => $self->{'package_request'},
117 1 'package_response' => $self->{'package_response'},
118 'token' => $self->token
119 );
120 }
121  
122 7 ▶ $opts{'endpoint'} ||= 'public';
Condition100%2/2
$opts{"endpoint"} ||= "public"
l!l
34
MC/DC100%1/1
$opts{"endpoint"} ||= "public"
$opts{"endpoint"}
Truth table100%2/2
A
A= $opts{"endpoint"}
Aresult
11
00
123  
124 7 ▶ if ($opts{'endpoint'} !~ /^(?:public|internal|admin)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"endpoint"} =~ /^(?:public|internal|admin)$/) 0 7 7
125 0 die 'Invalid endpoint type specified in "endpoint"';
126 }
127  
128 7 foreach my $service (@{$self->{'services'}}) {
129 7 ▶ next unless $type eq $service->{'type'};
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq $service->{"type"} 1 6 7
130  
131 6 foreach my $endpoint (@{$service->{'endpoints'}}) {
132 9 ▶ next if defined $opts{'id'} && $endpoint->{'id'} ne $opts{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"id"} and $endpoint->{"id"} ne $opts{"id"} 0 9 9
Condition66%2/3
defined $opts{"id"} and $endpoint->{"id"} ne $opts{"id"}
!ll&&!rl&&r
810
MC/DC0%0/2
defined $opts{"id"} and $endpoint->{"id"} ne $opts{"id"}
defined $opts{"id"} $endpoint->{"id"} ne $opts{"id"}
Truth table66%2/3
A and B
A= defined $opts{"id"}B= $endpoint->{"id"} ne $opts{"id"}
ABresult
0X0
100
111
133 9 ▶ next if defined $opts{'region'} && $endpoint->{'region'} ne $opts{'region'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"region"} and $endpoint->{"region"} ne $opts{"region"} 0 9 9
Condition66%2/3
defined $opts{"region"} and $endpoint->{"region"} ne $opts{"region"}
!ll&&!rl&&r
810
MC/DC0%0/2
defined $opts{"region"} and $endpoint->{"region"} ne $opts{"region"}
defined $opts{"region"} $endpoint->{"region"} ne $opts{"region"}
Truth table66%2/3
A and B
A= defined $opts{"region"}B= $endpoint->{"region"} ne $opts{"region"}
ABresult
0X0
100
111
134 9 ▶ next if defined $opts{'endpoint'} && $endpoint->{'interface'} ne $opts{'endpoint'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"endpoint"} and $endpoint->{"interface"} ne $opts{"endpoint"} 3 6 9
Condition66%2/3
defined $opts{"endpoint"} and $endpoint->{"interface"} ne $opts{"endpoint"}
!ll&&!rl&&r
063
MC/DC50%1/2
defined $opts{"endpoint"} and $endpoint->{"interface"} ne $opts{"endpoint"}
defined $opts{"endpoint"} $endpoint->{"interface"} ne $opts{"endpoint"}
Truth table66%2/3
A and B
A= defined $opts{"endpoint"}B= $endpoint->{"interface"} ne $opts{"endpoint"}
ABresult
0X0
100
111
135  
136 return $self->{'clients'}->{$type} = OpenStack::Client->new($endpoint->{'url'},
137 'package_ua' => $self->{'package_ua'},
138 'package_request' => $self->{'package_request'},
139 6 'package_response' => $self->{'package_response'},
140 'token' => $self->token
141 );
142 }
143 }
144  
145 1 die "No service type '$type' found";
146 }
147  
148 1 1;
« Client/Auth/v2.pm ↑ Summary Client/Response.pm »