Client/Auth.pm

filter: Statementstmt 100% 107 / 107 Branchbran 83.3% 5 / 6 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 33 / 33 Podpod 100% 1 / 1 totaltotal 99.3% 149 / 150 CC 5 SCAR 4.3
CC
5
Cov
99%
new
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Client.pm ↑ Summary
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;
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 =encoding utf8
17  
18 =head1 NAME
19  
20 OpenStack::Client::Auth - OpenStack Keystone authentication and authorization
21  
22 =head1 SYNOPSIS
23  
24 use OpenStack::Client::Auth ();
25  
26 my $auth = OpenStack::Client::Auth->new('http://openstack.foo.bar:5000/v2.0',
27 'tenant' => $ENV{'OS_TENANT_NAME'},
28 'username' => $ENV{'OS_USERNAME'},
29 'password' => $ENV{'OS_PASSWORD'}
30 );
31  
32 my $glance = $auth->service('image',
33 'region' => $ENV{'OS_REGION_NAME'}
34 );
35  
36 =head1 DESCRIPTION
37  
38 C<OpenStack::Client::Auth> provides an interface for obtaining authorization
39 to access other OpenStack cloud services.
40  
41 =head1 AUTHORIZING WITH KEYSTONE
42  
43 =over
44  
45 =item C<OpenStack::Client::Auth-E<gt>new(I<$endpoint>, I<%args>)>
46  
47 Contact the OpenStack Keystone API at the address provided in I<$endpoint>, and
48 obtain an authorization token and set of endpoints for which the client is
49 allowed to access. Credentials are specified in I<%args>; the following named
50 values are required:
51  
52 =over
53  
54 =item * B<tenant>
55  
56 The OpenStack tenant (project) name
57  
58 =item * B<username>
59  
60 The OpenStack user name
61  
62 =item * B<password>
63  
64 The OpenStack password
65  
66 =item * B<version>
67  
68 The version of the Glance API to negotiate with. Default is C<2.0>, but
69 C<3> is also accepted.
70  
71 =item * B<scope>
72  
73 When negotiating with an Identity v3 endpoint, the information provided here
74 is passed in the B<scope> property of the B<auth> portion of the request body
75 submitted to the endpoint.
76  
77 =item * B<domain>
78  
79 When negotiating with an Identity v3 endpoint, the name of the domain to
80 authenticate to.
81  
82 =back
83  
84 When successful, this method will return an object containing the following:
85  
86 =over
87  
88 =item * response
89  
90 The full decoded JSON authorization response from Keystone
91  
92 =item * services
93  
94 A hash containing services the client has authorization to
95  
96 =item * clients
97  
98 An initially empty hash that would contain L<OpenStack::Client> objects obtained
99 for any requested OpenStack services
100  
101 =back
102  
103 =cut
104  
105 sub new ($$%) {
106 31 ▶ my ($class, $endpoint, %args) = @_;
Subroutine new: called CC=5 SCAR=16.1
Pod documented
107  
108 31 my %CLASSES = (
109 '2.0' => 'OpenStack::Client::Auth::v2',
110 '3' => 'OpenStack::Client::Auth::v3'
111 );
112  
113 31 ▶ unless (defined $endpoint) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $endpoint) 1 30 31
114 1 die 'No OpenStack authentication endpoint provided';
115 }
116  
117 30 ▶ $args{'version'} ||= '2.0';
Condition100%2/2
$args{"version"} ||= "2.0"
l!l
264
MC/DC100%1/1
$args{"version"} ||= "2.0"
$args{"version"}
Truth table100%2/2
A
A= $args{"version"}
Aresult
11
00
118  
119 30 ▶ unless (defined $CLASSES{$args{'version'}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $CLASSES{$args{"version"}}) 1 29 30
120 1 die "Unsupported Identity endpoint version $args{'version'}";
121 }
122  
123 29 local $@;
124  
125 1 ▶ eval qq{
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval qq[\n use $CLASSES{$args{"version"}} ();\n 1;\n ] or die $@ 0 29 29
126 use $CLASSES{$args{'version'}} ();
127 1;
128 } or die $@;
129  
130 29 return $CLASSES{$args{'version'}}->new($endpoint, %args);
131 }
132  
133 =back
134  
135 =head1 RETRIEVING RESPONSE
136  
137 =over
138  
139 =item C<$auth-E<gt>response()>
140  
141 Return the full decoded response from the Keystone API.
142  
143 =back
144  
145 =head1 ACCESSING AUTHORIZATION DATA
146  
147 =over
148  
149 =item C<$auth-E<gt>access()>
150  
151 Return the service access data stored in the current object.
152  
153 =back
154  
155 =head1 ACCESSING TOKEN DATA
156  
157 =over
158  
159 =item C<$auth-E<gt>token()>
160  
161 Return the authorization token data stored in the current object.
162  
163 =back
164  
165 =head1 OBTAINING LIST OF SERVICES AUTHORIZED
166  
167 =over
168  
169 =item C<$auth-E<gt>services()>
170  
171 Return a list of service types the OpenStack user is authorized to access.
172  
173 =back
174  
175 =head1 ACCESSING SERVICES AUTHORIZED
176  
177 =over
178  
179 =item C<$auth-E<gt>service(I<$type>, I<%opts>)>
180  
181 Obtain a client to the OpenStack service I<$type>, where I<$type> is usually
182 one of:
183  
184 =over
185  
186 =item * B<compute>
187  
188 =item * B<ec2>
189  
190 =item * B<identity>
191  
192 =item * B<image>
193  
194 =item * B<network>
195  
196 =item * B<volumev2>
197  
198 =back
199  
200 The following values may be specified in I<%opts> to help locate the most
201 appropriate endpoint for a given service:
202  
203 =over
204  
205 =item * B<uri>
206  
207 When specified, use a specific URI to gain access to a named service endpoint.
208 This might be useful for non-production development or testing scenarios.
209  
210 =item * B<id>
211  
212 When specified, attempt to obtain a client for the very endpoint indicated by
213 that identifier.
214  
215 =item * B<region>
216  
217 When specified, attempt to obtain a client for the endpoint for that region.
218 When not specified, the a client for the first endpoint found for service
219 I<$type> is returned instead.
220  
221 =item * B<endpoint>
222  
223 When specified and set to one of 'public', 'internal' or 'admin', return a
224 client for the corresponding public, internal or admin endpoint. The default
225 endpoint is the public endpoint.
226  
227 =back
228  
229 =back
230  
231 =head1 AUTHOR
232  
233 Written by Alexandra Hrefna Hilmisdóttir <xan@cpanel.net>
234  
235 =head1 COPYRIGHT
236  
237 Copyright (c) 2018 cPanel, L.L.C. Released under the terms of the MIT license.
238 See LICENSE for further details.
239  
240 =cut
241  
242 1 1;
« Client.pm ↑ Summary