| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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::v2; |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use OpenStack::Client (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
761
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new ($$%) { |
|
17
|
14
|
|
|
14
|
0
|
56
|
my ($class, $endpoint, %args) = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
14
|
100
|
|
|
|
56
|
die 'No OpenStack tenant name provided in "tenant"' unless defined $args{'tenant'}; |
|
20
|
12
|
100
|
|
|
|
45
|
die 'No OpenStack username provided in "username"' unless defined $args{'username'}; |
|
21
|
10
|
100
|
|
|
|
42
|
die 'No OpenStack password provided in "password"' unless defined $args{'password'}; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $client = OpenStack::Client->new($endpoint, |
|
24
|
|
|
|
|
|
|
'package_ua' => $args{'package_ua'}, |
|
25
|
|
|
|
|
|
|
'package_request' => $args{'package_request'}, |
|
26
|
8
|
|
|
|
|
31
|
'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
|
|
|
|
|
42
|
'password' => $args{'password'} |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
}); |
|
38
|
|
|
|
|
|
|
|
|
39
|
8
|
100
|
|
|
|
36
|
unless (defined $response->{'access'}->{'token'}->{'id'}) { |
|
40
|
1
|
|
|
|
|
14
|
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
|
|
|
|
|
64
|
'services' => $response->{'access'}->{'serviceCatalog'} |
|
50
|
|
|
|
|
|
|
}, $class; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub response ($) { |
|
54
|
1
|
|
|
1
|
0
|
1246
|
shift->{'response'}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub access ($) { |
|
58
|
1
|
|
|
1
|
0
|
2039
|
shift->{'response'}->{'access'}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub token ($) { |
|
62
|
8
|
|
|
8
|
0
|
1825
|
shift->{'response'}->{'access'}->{'token'}->{'id'}; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub services ($) { |
|
66
|
1
|
|
|
1
|
0
|
614
|
my ($self) = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my %types = map { |
|
69
|
2
|
|
|
|
|
7
|
$_->{'type'} => 1 |
|
70
|
1
|
|
|
|
|
2
|
} @{$self->{'services'}}; |
|
|
1
|
|
|
|
|
3
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
7
|
return sort keys %types; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub service ($$%) { |
|
76
|
11
|
|
|
11
|
0
|
1971
|
my ($self, $type, %opts) = @_; |
|
77
|
|
|
|
|
|
|
|
|
78
|
11
|
100
|
|
|
|
35
|
if (defined $self->{'clients'}->{$type}) { |
|
79
|
2
|
|
|
|
|
7
|
return $self->{'clients'}->{$type}; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
9
|
100
|
|
|
|
23
|
if (defined $opts{'uri'}) { |
|
83
|
|
|
|
|
|
|
return $self->{'clients'}->{$type} = OpenStack::Client->new($opts{'uri'}, |
|
84
|
|
|
|
|
|
|
'package_ua' => $self->{'package_ua'}, |
|
85
|
|
|
|
|
|
|
'package_request' => $self->{'package_request'}, |
|
86
|
1
|
|
|
|
|
3
|
'package_response' => $self->{'package_response'}, |
|
87
|
|
|
|
|
|
|
'token' => $self->token |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
8
|
|
100
|
|
|
26
|
$opts{'endpoint'} ||= 'public'; |
|
92
|
|
|
|
|
|
|
|
|
93
|
8
|
100
|
|
|
|
38
|
if ($opts{'endpoint'} !~ /^(?:public|internal|admin)$/) { |
|
94
|
1
|
|
|
|
|
10
|
die 'Invalid endpoint type specified in "endpoint"'; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
7
|
|
|
|
|
13
|
foreach my $service (@{$self->{'services'}}) { |
|
|
7
|
|
|
|
|
16
|
|
|
98
|
10
|
100
|
|
|
|
22
|
next unless $type eq $service->{'type'}; |
|
99
|
|
|
|
|
|
|
|
|
100
|
8
|
|
|
|
|
16
|
my $uri; |
|
101
|
|
|
|
|
|
|
|
|
102
|
8
|
|
|
|
|
9
|
foreach my $endpoint (@{$service->{'endpoints'}}) { |
|
|
8
|
|
|
|
|
16
|
|
|
103
|
8
|
100
|
100
|
|
|
23
|
next if defined $opts{'id'} && $endpoint->{'id'} ne $opts{'id'}; |
|
104
|
7
|
100
|
100
|
|
|
23
|
next if defined $opts{'region'} && $endpoint->{'region'} ne $opts{'region'}; |
|
105
|
|
|
|
|
|
|
|
|
106
|
6
|
100
|
|
|
|
17
|
if ($opts{'endpoint'} eq 'public') { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
107
|
4
|
|
|
|
|
9
|
$uri = $endpoint->{'publicURL'}; |
|
108
|
|
|
|
|
|
|
} elsif ($opts{'endpoint'} eq 'internal') { |
|
109
|
1
|
|
|
|
|
2
|
$uri = $endpoint->{'internalURL'}; |
|
110
|
|
|
|
|
|
|
} elsif ($opts{'endpoint'} eq 'admin') { |
|
111
|
1
|
|
|
|
|
6
|
$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
|
|
|
|
|
16
|
'package_response' => $self->{'package_response'}, |
|
118
|
|
|
|
|
|
|
'token' => $self->token |
|
119
|
|
|
|
|
|
|
); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
11
|
die "No service type '$type' found"; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |