GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#174)
by Ha
01:37
created

OpenStack::identityV3()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace OpenStack;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\HandlerStack;
7
use GuzzleHttp\Middleware as GuzzleMiddleware;
8
use OpenStack\Common\Service\Builder;
9
use OpenStack\Common\Transport\Utils;
10
use OpenStack\Identity\v3\Service;
11
12
/**
13
 * This class is the primary entry point for working with the SDK. It allows for the easy creation
14
 * of OpenStack services.
15
 *
16
 * @package OpenStack
17
 */
18
class OpenStack
19
{
20
    /** @var Builder */
21
    private $builder;
22
23
    /**
24
     * @param array    $options User-defined options
25
     *
26
     * $options['username']         = (string)            Your OpenStack username        [REQUIRED]
27
     *         ['password']         = (string)            Your OpenStack password        [REQUIRED]
28 7
     *         ['tenantId']         = (string)            Your tenant ID                 [REQUIRED if tenantName omitted]
29
     *         ['tenantName']       = (string)            Your tenant name               [REQUIRED if tenantId omitted]
30 7
     *         ['authUrl']          = (string)            The Keystone URL               [REQUIRED]
31 7
     *         ['debugLog']         = (bool)              Whether to enable HTTP logging [OPTIONAL]
32
     *         ['logger']           = (LoggerInterface)   Must set if debugLog is true   [OPTIONAL]
33
     *         ['messageFormatter'] = (MessageFormatter)  Must set if debugLog is true   [OPTIONAL]
34
     *         ['requestOptions']   = (array)             Guzzle Http request options    [OPTIONAL]
35
     *
36
     * @param Builder $builder
37
     */
38
    public function __construct(array $options = [], Builder $builder = null)
39
    {
40 1
        if (!isset($options['identityService'])) {
41
            $options['identityService'] = $this->getDefaultIdentityService($options);
42 1
        }
43 1
44
        $this->builder = $builder ?: new Builder($options, 'OpenStack');
45
    }
46
47
    /**
48
     * @param array $options
49
     *
50
     * @return Service
51
     */
52
    private function getDefaultIdentityService(array $options): Service
53 1
    {
54
        if (!isset($options['authUrl'])) {
55 1
            throw new \InvalidArgumentException("'authUrl' is a required option");
56 1
        }
57
58
        $stack = HandlerStack::create();
59
60 View Code Duplication
        if (!empty($options['debugLog'])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
            && !empty($options['logger'])
62
            && !empty($options['messageFormatter'])
63
        ) {
64
            $stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter']));
65
        }
66 1
67
        $clientOptions = [
68 1
            'base_uri' => Utils::normalizeUrl($options['authUrl']),
69 1
            'handler'  => $stack
70
        ];
71
72
        return Service::factory(new Client($clientOptions));
73
    }
74
75
    /**
76
     * Creates a new Compute v2 service.
77
     *
78
     * @param array $options Options that will be used in configuring the service.
79 1
     *
80
     * @return \OpenStack\Compute\v2\Service
81 1
     */
82 1
    public function computeV2(array $options = []): \OpenStack\Compute\v2\Service
83
    {
84
        $defaults = ['catalogName' => 'nova', 'catalogType' => 'compute'];
85
        return $this->builder->createService('Compute\\v2', array_merge($defaults, $options));
86
    }
87
88
    /**
89
     * Creates a new Networking v2 service.
90
     *
91
     * @param array $options Options that will be used in configuring the service.
92 1
     *
93
     * @return \OpenStack\Networking\v2\Service
94 1
     */
95 1
    public function networkingV2(array $options = []): \OpenStack\Networking\v2\Service
96
    {
97
        $defaults = ['catalogName' => 'neutron', 'catalogType' => 'network'];
98
        return $this->builder->createService('Networking\\v2', array_merge($defaults, $options));
99
    }
100
101
    /**
102
     * Creates a new Networking v2 Layer 3 service.
103
     *
104
     * @param array $options Options that will be used in configuring the service.
105 1
     *
106
     * @return \OpenStack\Networking\v2\Extensions\Layer3\Service
107 1
     */
108 1
    public function networkingV2ExtLayer3(array $options = []): \OpenStack\Networking\v2\Extensions\Layer3\Service
109
    {
110
        $defaults = ['catalogName' => 'neutron', 'catalogType' => 'network'];
111
        return $this->builder->createService('Networking\\v2\\Extensions\\Layer3', array_merge($defaults, $options));
112
    }
113
114
    /**
115
     * Creates a new Networking v2 Layer 3 service.
116
     *
117
     * @param array $options Options that will be used in configuring the service.
118 1
     *
119
     * @return \OpenStack\Networking\v2\Extensions\SecurityGroups\Service
120 1
     */
121 1
    public function networkingV2ExtSecGroups(array $options = []): \OpenStack\Networking\v2\Extensions\SecurityGroups\Service
122
    {
123
        $defaults = ['catalogName' => 'neutron', 'catalogType' => 'network'];
124
        return $this->builder->createService('Networking\\v2\\Extensions\\SecurityGroups', array_merge($defaults, $options));
125
    }
126
127
    /**
128
     * Creates a new Identity v2 service.
129
     *
130
     * @param array $options Options that will be used in configuring the service.
131
     *
132
     * @return \OpenStack\Identity\v2\Service
133
     */
134
    public function identityV2(array $options = []): \OpenStack\Identity\v2\Service
135
    {
136
        $defaults = ['catalogName' => 'keystone', 'catalogType' => 'identity'];
137
        return $this->builder->createService('Identity\\v2', array_merge($defaults, $options));
138
    }
139
140
    /**
141
     * Creates a new Identity v3 service.
142
     *
143
     * @param array $options Options that will be used in configuring the service.
144
     *
145
     * @return \OpenStack\Identity\v3\Service
146
     */
147
    public function identityV3(array $options = []): \OpenStack\Identity\v3\Service
148
    {
149
        $defaults = ['catalogName' => 'keystone', 'catalogType' => 'identity'];
150
        return $this->builder->createService('Identity\\v3', array_merge($defaults, $options));
151
    }
152
153
    /**
154
     * Creates a new Object Store v1 service.
155
     *
156
     * @param array $options Options that will be used in configuring the service.
157
     *
158
     * @return \OpenStack\ObjectStore\v1\Service
159
     */
160
    public function objectStoreV1(array $options = []): \OpenStack\ObjectStore\v1\Service
161
    {
162
        $defaults = ['catalogName' => 'swift', 'catalogType' => 'object-store'];
163
        return $this->builder->createService('ObjectStore\\v1', array_merge($defaults, $options));
164
    }
165
166
    /**
167
     * Creates a new Block Storage v2 service.
168
     *
169
     * @param array $options Options that will be used in configuring the service.
170
     *
171
     * @return \OpenStack\BlockStorage\v2\Service
172
     */
173
    public function blockStorageV2(array $options = []): \OpenStack\BlockStorage\v2\Service
174
    {
175
        $defaults = ['catalogName' => 'cinderv2', 'catalogType' => 'volumev2'];
176
        return $this->builder->createService('BlockStorage\\v2', array_merge($defaults, $options));
177
    }
178
179
    /**
180
     * Creates a new Images v2 service.
181
     *
182
     * @param array $options Options that will be used in configuring the service.
183
     *
184
     * @return \OpenStack\Images\v2\Service
185
     */
186
    public function imagesV2(array $options = []): \OpenStack\Images\v2\Service
187
    {
188
        $defaults = ['catalogName' => 'glance', 'catalogType' => 'image'];
189
        return $this->builder->createService('Images\\v2', array_merge($defaults, $options));
190
    }
191
192
    /**
193
     * Creates a new Gnocchi Metric service v1
194
     *
195
     * @param array $options
196
     *
197
     * @return \OpenStack\Metric\v1\Gnocchi\Service
198
     */
199
    public function metricGnocchiV1(array $options = []): \OpenStack\Metric\v1\Gnocchi\Service
200
    {
201
        $defaults = ['catalogName' => 'gnocchi', 'catalogType' => 'metric'];
202
203
        return $this->builder->createService('Metric\\v1\\Gnocchi', array_merge($defaults, $options));
204
    }
205
}
206