| 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
| |||||||||||||||||||||||||||||
| 20 | 13 | ▶ | die 'No OpenStack password provided in "password"' unless defined $args{'password'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 12 | ▶ | $args{'domain'} ||= 'default'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"domain"} ||= "default"
MC/DC0%0/1
$args{"domain"} ||= "default"
$args{"domain"}
Truth table50%1/2
A
A= $args{"domain"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 58 | 1 | die 'No token found in response headers'; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 11 | ▶ | unless (defined $body->{'token'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 1 | die 'No token found in response body'; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 10 | ▶ | unless (defined $body->{'token'}->{'catalog'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 110 | 2 | return $self->{'clients'}->{$type}; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 8 | ▶ | if (defined $opts{'uri'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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"
MC/DC100%1/1
$opts{"endpoint"} ||= "public"
$opts{"endpoint"}
Truth table100%2/2
A
A= $opts{"endpoint"}
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 7 | ▶ | if ($opts{'endpoint'} !~ /^(?:public|internal|admin)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 6 | foreach my $endpoint (@{$service->{'endpoints'}}) { | |||||||||||||||||||||||||||
| 132 | 9 | ▶ | next if defined $opts{'id'} && $endpoint->{'id'} ne $opts{'id'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opts{"id"} and $endpoint->{"id"} ne $opts{"id"}
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"}
| |||||||||||||||||||||||||||||
| 133 | 9 | ▶ | next if defined $opts{'region'} && $endpoint->{'region'} ne $opts{'region'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opts{"region"} and $endpoint->{"region"} ne $opts{"region"}
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"}
| |||||||||||||||||||||||||||||
| 134 | 9 | ▶ | next if defined $opts{'endpoint'} && $endpoint->{'interface'} ne $opts{'endpoint'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opts{"endpoint"} and $endpoint->{"interface"} ne $opts{"endpoint"}
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"}
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||