line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
12
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use OpenStack::Client (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
713
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new ($$%) { |
17
|
13
|
|
|
13
|
0
|
53
|
my ($class, $endpoint, %args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
13
|
100
|
|
|
|
41
|
die 'No OpenStack tenant name provided in "tenant"' unless defined $args{'tenant'}; |
20
|
12
|
100
|
|
|
|
46
|
die 'No OpenStack username provided in "username"' unless defined $args{'username'}; |
21
|
10
|
100
|
|
|
|
43
|
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
|
|
|
|
|
28
|
'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
|
|
|
|
|
47
|
'password' => $args{'password'} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
}); |
38
|
|
|
|
|
|
|
|
39
|
8
|
100
|
|
|
|
37
|
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
|
|
|
|
|
66
|
'services' => $response->{'access'}->{'serviceCatalog'} |
50
|
|
|
|
|
|
|
}, $class; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub response ($) { |
54
|
1
|
|
|
1
|
0
|
1270
|
shift->{'response'}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub access ($) { |
58
|
1
|
|
|
1
|
0
|
2002
|
shift->{'response'}->{'access'}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub token ($) { |
62
|
8
|
|
|
8
|
0
|
1835
|
shift->{'response'}->{'access'}->{'token'}->{'id'}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub services ($) { |
66
|
1
|
|
|
1
|
0
|
603
|
my ($self) = @_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my %types = map { |
69
|
2
|
|
|
|
|
8
|
$_->{'type'} => 1 |
70
|
1
|
|
|
|
|
3
|
} @{$self->{'services'}}; |
|
1
|
|
|
|
|
4
|
|
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
8
|
return sort keys %types; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub service ($$%) { |
76
|
11
|
|
|
11
|
0
|
1948
|
my ($self, $type, %opts) = @_; |
77
|
|
|
|
|
|
|
|
78
|
11
|
100
|
|
|
|
35
|
if (defined $self->{'clients'}->{$type}) { |
79
|
2
|
|
|
|
|
6
|
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
|
|
|
|
|
4
|
'package_response' => $self->{'package_response'}, |
87
|
|
|
|
|
|
|
'token' => $self->token |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
8
|
|
100
|
|
|
28
|
$opts{'endpoint'} ||= 'public'; |
92
|
|
|
|
|
|
|
|
93
|
8
|
100
|
|
|
|
36
|
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
|
|
|
|
|
17
|
|
98
|
10
|
100
|
|
|
|
25
|
next unless $type eq $service->{'type'}; |
99
|
|
|
|
|
|
|
|
100
|
8
|
|
|
|
|
14
|
my $uri; |
101
|
|
|
|
|
|
|
|
102
|
8
|
|
|
|
|
12
|
foreach my $endpoint (@{$service->{'endpoints'}}) { |
|
8
|
|
|
|
|
14
|
|
103
|
8
|
100
|
100
|
|
|
27
|
next if defined $opts{'id'} && $endpoint->{'id'} ne $opts{'id'}; |
104
|
7
|
100
|
100
|
|
|
21
|
next if defined $opts{'region'} && $endpoint->{'region'} ne $opts{'region'}; |
105
|
|
|
|
|
|
|
|
106
|
6
|
100
|
|
|
|
21
|
if ($opts{'endpoint'} eq 'public') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
107
|
4
|
|
|
|
|
7
|
$uri = $endpoint->{'publicURL'}; |
108
|
|
|
|
|
|
|
} elsif ($opts{'endpoint'} eq 'internal') { |
109
|
1
|
|
|
|
|
3
|
$uri = $endpoint->{'internalURL'}; |
110
|
|
|
|
|
|
|
} elsif ($opts{'endpoint'} eq 'admin') { |
111
|
1
|
|
|
|
|
3
|
$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
|
|
|
|
|
18
|
'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; |