Client/Auth/v3.pm

filter: Statementstmt 96.3% 52 / 54 Branchbran 85.7% 24 / 28 Conditioncond 69.2% 9 / 13 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 7 totaltotal 80.0% 96 / 120 CC 22 SCAR 22.6
CC
22
Cov
89%
service
14.8
new
9.0
body
2.0
CRAP 9.6
↑ Summary Client/Auth/v2.pm »
1 #
2 # Copyright (c) 2018 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 15 ▶ my ($class, $endpoint, %args) = @_;
Subroutine new: called CC=9 SCAR=22.0
Pod undocumented
18  
19 15 ▶ die 'No OpenStack tenant name provided in "tenant"' unless defined $args{'tenant'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"tenant"} 1 14 15
20 14 ▶ die 'No OpenStack username provided in "username"' unless defined $args{'username'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"username"} 1 13 14
21 13 ▶ die 'No OpenStack password provided in "password"' unless defined $args{'password'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"password"} 1 12 13
22  
23 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
24  
25 my $client = OpenStack::Client->new($endpoint,
26 'package_ua' => $args{'package_ua'},
27 'package_request' => $args{'package_request'},
28 12 'package_response' => $args{'package_response'}
29 );
30  
31 my %request = (
32 'auth' => {
33 'identity' => {
34 'methods' => [qw(password)],
35 'password' => {
36 'user' => {
37 'name' => $args{'username'},
38 'password' => $args{'password'},
39 'domain' => {
40 12 'name' => $args{'domain'}
41 }
42 }
43 }
44 }
45 }
46 );
47  
48 12 ▶ $request{'auth'}->{'scope'} = $args{'scope'} if defined $args{'scope'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"scope"} 0 12 12
49  
50 12 my $response = $client->request(
51 'method' => 'POST',
52 'path' => '/auth/tokens',
53 'body' => \%request
54 );
55  
56 12 my $body = $response->decode_json;
57  
58 12 ▶ unless (defined $response->header('X-Subject-Token')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response->header("X-Subject-Token")) 1 11 12
59 1 die 'No token found in response headers';
60 }
61  
62 11 ▶ unless (defined $body->{'token'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $body->{"token"}) 1 10 11
63 1 die 'No token found in response body';
64 }
65  
66 10 ▶ unless (defined $body->{'token'}->{'catalog'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $body->{"token"}{"catalog"}) 1 9 10
67 1 die 'No service catalog found in response body token';
68 }
69  
70 return bless {
71 'package_ua' => $args{'package_ua'},
72 'package_request' => $args{'package_request'},
73 'package_response' => $args{'package_response'},
74 'response' => $response,
75 'body' => $body,
76 'clients' => {},
77 9 'services' => $body->{'token'}->{'catalog'}
78 }, $class;
79 }
80  
81 sub body ($) {
82 0 ▶ shift->{'body'};
Subroutine body: not called CC=1 SCAR=6.9
Pod undocumented
83 }
84  
85 sub response ($) {
86 1 ▶ shift->{'response'};
Subroutine response: called CC=1 SCAR=0.0
Pod undocumented
87 }
88  
89 sub access ($) {
90 1 ▶ shift->{'body'}->{'access'};
Subroutine access: called CC=1 SCAR=0.0
Pod undocumented
91 }
92  
93 sub token ($) {
94 8 ▶ shift->{'response'}->header('X-Subject-Token');
Subroutine token: called CC=1 SCAR=0.0
Pod undocumented
95 }
96  
97 sub services ($) {
98 1 ▶ my ($self) = @_;
Subroutine services: called CC=1 SCAR=0.0
Pod undocumented
99  
100 my %types = map {
101 1 $_->{'type'} => 1
102 1 } @{$self->{'services'}};
103  
104 1 return sort keys %types;
105 }
106  
107 sub service ($$%) {
108 10 ▶ my ($self, $type, %opts) = @_;
Subroutine service: called CC=14 SCAR=27.0
Pod undocumented
109  
110 10 ▶ if (defined $self->{'clients'}->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"clients"}{$type}) 2 8 10
111 2 return $self->{'clients'}->{$type};
112 }
113  
114 8 ▶ if (defined $opts{'uri'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"uri"}) 1 7 8
115 return $self->{'clients'}->{$type} = OpenStack::Client->new($opts{'uri'},
116 'package_ua' => $self->{'package_ua'},
117 'package_request' => $self->{'package_request'},
118 1 'package_response' => $self->{'package_response'},
119 'token' => $self->token
120 );
121 }
122  
123 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
124  
125 7 ▶ if ($opts{'endpoint'} !~ /^(?:public|internal|admin)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"endpoint"} =~ /^(?:public|internal|admin)$/) 0 7 7
126 0 die 'Invalid endpoint type specified in "endpoint"';
127 }
128  
129 7 foreach my $service (@{$self->{'services'}}) {
130 7 ▶ next unless $type eq $service->{'type'};
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq $service->{"type"} 1 6 7
131  
132 6 foreach my $endpoint (@{$service->{'endpoints'}}) {
133 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
134 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
135 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
136  
137 return $self->{'clients'}->{$type} = OpenStack::Client->new($endpoint->{'url'},
138 'package_ua' => $self->{'package_ua'},
139 'package_request' => $self->{'package_request'},
140 6 'package_response' => $self->{'package_response'},
141 'token' => $self->token
142 );
143 }
144 }
145  
146 1 die "No service type '$type' found";
147 }
148  
149 1 1;
↑ Summary Client/Auth/v2.pm »