Client/Auth/v2.pm

filter: Statementstmt 100% 49 / 49 Branchbran 96.1% 25 / 26 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 6 totaltotal 93.2% 96 / 103 CC 19 SCAR 22.5
CC
19
Cov
99%
service
15.0
new
5.0
BEGIN
1.0
CRAP 9.5
↑ Summary Client/Auth/v3.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::v2;
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 13 ▶ my ($class, $endpoint, %args) = @_;
Subroutine new: called CC=5 SCAR=16.1
Pod undocumented
18  
19 13 ▶ die 'No OpenStack tenant name provided in "tenant"' unless defined $args{'tenant'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"tenant"} 1 12 13
20 12 ▶ die 'No OpenStack username provided in "username"' unless defined $args{'username'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"username"} 2 10 12
21 10 ▶ die 'No OpenStack password provided in "password"' unless defined $args{'password'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"password"} 2 8 10
22  
23 my $client = OpenStack::Client->new($endpoint,
24 'package_ua' => $args{'package_ua'},
25 'package_request' => $args{'package_request'},
26 8 'package_response' => $args{'package_response'}
27 );
28  
29 my $response = $client->call('POST' => '/tokens', {
30 'auth' => {
31 'tenantName' => $args{'tenant'},
32 'passwordCredentials' => {
33 'username' => $args{'username'},
34 8 'password' => $args{'password'}
35 }
36 }
37 });
38  
39 8 ▶ unless (defined $response->{'access'}->{'token'}->{'id'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response->{"access"}{"token"}{"id"}) 1 7 8
40 1 die 'No token found in response';
41 }
42  
43 return bless {
44 'package_ua' => $args{'package_ua'},
45 'package_request' => $args{'package_request'},
46 'package_response' => $args{'package_response'},
47 'response' => $response,
48 'clients' => {},
49 7 'services' => $response->{'access'}->{'serviceCatalog'}
50 }, $class;
51 }
52  
53 sub response ($) {
54 1 ▶ shift->{'response'};
Subroutine response: called CC=1 SCAR=0.0
Pod undocumented
55 }
56  
57 sub access ($) {
58 1 ▶ shift->{'response'}->{'access'};
Subroutine access: called CC=1 SCAR=0.0
Pod undocumented
59 }
60  
61 sub token ($) {
62 8 ▶ shift->{'response'}->{'access'}->{'token'}->{'id'};
Subroutine token: called CC=1 SCAR=0.0
Pod undocumented
63 }
64  
65 sub services ($) {
66 1 ▶ my ($self) = @_;
Subroutine services: called CC=1 SCAR=0.0
Pod undocumented
67  
68 my %types = map {
69 2 $_->{'type'} => 1
70 1 } @{$self->{'services'}};
71  
72 1 return sort keys %types;
73 }
74  
75 sub service ($$%) {
76 11 ▶ my ($self, $type, %opts) = @_;
Subroutine service: called CC=15 SCAR=27.1
Pod undocumented
77  
78 11 ▶ if (defined $self->{'clients'}->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"clients"}{$type}) 2 9 11
79 2 return $self->{'clients'}->{$type};
80 }
81  
82 9 ▶ if (defined $opts{'uri'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"uri"}) 1 8 9
83 return $self->{'clients'}->{$type} = OpenStack::Client->new($opts{'uri'},
84 'package_ua' => $self->{'package_ua'},
85 'package_request' => $self->{'package_request'},
86 1 'package_response' => $self->{'package_response'},
87 'token' => $self->token
88 );
89 }
90  
91 8 ▶ $opts{'endpoint'} ||= 'public';
Condition100%2/2
$opts{"endpoint"} ||= "public"
l!l
44
MC/DC100%1/1
$opts{"endpoint"} ||= "public"
$opts{"endpoint"}
Truth table100%2/2
A
A= $opts{"endpoint"}
Aresult
11
00
92  
93 8 ▶ if ($opts{'endpoint'} !~ /^(?:public|internal|admin)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"endpoint"} =~ /^(?:public|internal|admin)$/) 1 7 8
94 1 die 'Invalid endpoint type specified in "endpoint"';
95 }
96  
97 7 foreach my $service (@{$self->{'services'}}) {
98 10 ▶ next unless $type eq $service->{'type'};
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq $service->{"type"} 2 8 10
99  
100 8 my $uri;
101  
102 8 foreach my $endpoint (@{$service->{'endpoints'}}) {
103 8 ▶ next if defined $opts{'id'} && $endpoint->{'id'} ne $opts{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"id"} and $endpoint->{"id"} ne $opts{"id"} 1 7 8
Condition100%3/3
defined $opts{"id"} and $endpoint->{"id"} ne $opts{"id"}
!ll&&!rl&&r
611
MC/DC100%2/2
defined $opts{"id"} and $endpoint->{"id"} ne $opts{"id"}
defined $opts{"id"} $endpoint->{"id"} ne $opts{"id"}
Truth table100%3/3
A and B
A= defined $opts{"id"}B= $endpoint->{"id"} ne $opts{"id"}
ABresult
0X0
100
111
104 7 ▶ next if defined $opts{'region'} && $endpoint->{'region'} ne $opts{'region'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"region"} and $endpoint->{"region"} ne $opts{"region"} 1 6 7
Condition100%3/3
defined $opts{"region"} and $endpoint->{"region"} ne $opts{"region"}
!ll&&!rl&&r
511
MC/DC100%2/2
defined $opts{"region"} and $endpoint->{"region"} ne $opts{"region"}
defined $opts{"region"} $endpoint->{"region"} ne $opts{"region"}
Truth table100%3/3
A and B
A= defined $opts{"region"}B= $endpoint->{"region"} ne $opts{"region"}
ABresult
0X0
100
111
105  
106 6 ▶ if ($opts{'endpoint'} eq 'public') {
Branch: 3 branches
BranchTrueFalseTotal
if ($opts{'endpoint'} eq 'public') { } 4 2 6
elsif ($opts{'endpoint'} eq 'internal') { } 1 1 2
elsif ($opts{'endpoint'} eq 'admin') { } 1 0 1
107 4 $uri = $endpoint->{'publicURL'};
108 } elsif ($opts{'endpoint'} eq 'internal') {
109 1 $uri = $endpoint->{'internalURL'};
110 } elsif ($opts{'endpoint'} eq 'admin') {
111 1 $uri = $endpoint->{'adminURL'};
112 }
113  
114 return $self->{'clients'}->{$type} = OpenStack::Client->new($uri,
115 'package_ua' => $self->{'package_ua'},
116 'package_request' => $self->{'package_request'},
117 6 'package_response' => $self->{'package_response'},
118 'token' => $self->token
119 );
120 }
121 }
122  
123 1 die "No service type '$type' found";
124 }
125  
126 1 1;
↑ Summary Client/Auth/v3.pm »