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.

OpenStack::imagesV2()   A
last analyzed

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
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
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
     *         ['cachedToken']      = (array)             Cached token credential        [OPTIONAL]
36
     *
37
     * @param Builder $builder
38
     */
39
    public function __construct(array $options = [], Builder $builder = null)
40 1
    {
41
        if (!isset($options['identityService'])) {
42 1
            $options['identityService'] = $this->getDefaultIdentityService($options);
43 1
        }
44
45
        $this->builder = $builder ?: new Builder($options, 'OpenStack');
46
    }
47
48
    /**
49
     * @param array $options
50
     *
51
     * @return Service
52
     */
53 1
    private function getDefaultIdentityService(array $options): Service
54
    {
55 1
        if (!isset($options['authUrl'])) {
56 1
            throw new \InvalidArgumentException("'authUrl' is a required option");
57
        }
58
59
        $stack = HandlerStack::create();
60
61 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...
62
            && !empty($options['logger'])
63
            && !empty($options['messageFormatter'])
64
        ) {
65
            $stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter']));
66 1
        }
67
68 1
        $clientOptions = [
69 1
            'base_uri' => Utils::normalizeUrl($options['authUrl']),
70
            'handler'  => $stack,
71
        ];
72
73
        if (isset($options['requestOptions'])) {
74
            $clientOptions = array_merge($options['requestOptions'], $clientOptions);
75
        }
76
77
        return Service::factory(new Client($clientOptions));
78
    }
79 1
80
    /**
81 1
     * Creates a new Compute v2 service.
82 1
     *
83
     * @param array $options Options that will be used in configuring the service.
84
     *
85
     * @return \OpenStack\Compute\v2\Service
86
     */
87
    public function computeV2(array $options = []): \OpenStack\Compute\v2\Service
88
    {
89
        $defaults = ['catalogName' => 'nova', 'catalogType' => 'compute'];
90
        return $this->builder->createService('Compute\\v2', array_merge($defaults, $options));
91
    }
92 1
93
    /**
94 1
     * Creates a new Networking v2 service.
95 1
     *
96
     * @param array $options Options that will be used in configuring the service.
97
     *
98
     * @return \OpenStack\Networking\v2\Service
99
     */
100
    public function networkingV2(array $options = []): \OpenStack\Networking\v2\Service
101
    {
102
        $defaults = ['catalogName' => 'neutron', 'catalogType' => 'network'];
103
        return $this->builder->createService('Networking\\v2', array_merge($defaults, $options));
104
    }
105 1
106
    /**
107 1
     * Creates a new Networking v2 Layer 3 service.
108 1
     *
109
     * @param array $options Options that will be used in configuring the service.
110
     *
111
     * @return \OpenStack\Networking\v2\Extensions\Layer3\Service
112
     */
113
    public function networkingV2ExtLayer3(array $options = []): \OpenStack\Networking\v2\Extensions\Layer3\Service
114
    {
115
        $defaults = ['catalogName' => 'neutron', 'catalogType' => 'network'];
116
        return $this->builder->createService('Networking\\v2\\Extensions\\Layer3', array_merge($defaults, $options));
117
    }
118 1
119
    /**
120 1
     * Creates a new Networking v2 Layer 3 service.
121 1
     *
122
     * @param array $options Options that will be used in configuring the service.
123
     *
124
     * @return \OpenStack\Networking\v2\Extensions\SecurityGroups\Service
125
     */
126
    public function networkingV2ExtSecGroups(array $options = []): \OpenStack\Networking\v2\Extensions\SecurityGroups\Service
127
    {
128
        $defaults = ['catalogName' => 'neutron', 'catalogType' => 'network'];
129
        return $this->builder->createService('Networking\\v2\\Extensions\\SecurityGroups', array_merge($defaults, $options));
130
    }
131
132
    /**
133
     * Creates a new Identity v2 service.
134
     *
135
     * @param array $options Options that will be used in configuring the service.
136
     *
137
     * @return \OpenStack\Identity\v2\Service
138
     */
139
    public function identityV2(array $options = []): \OpenStack\Identity\v2\Service
140
    {
141
        $defaults = ['catalogName' => 'keystone', 'catalogType' => 'identity'];
142
        return $this->builder->createService('Identity\\v2', array_merge($defaults, $options));
143
    }
144
145
    /**
146
     * Creates a new Identity v3 service.
147
     *
148
     * @param array $options Options that will be used in configuring the service.
149
     *
150
     * @return \OpenStack\Identity\v3\Service
151
     */
152
    public function identityV3(array $options = []): \OpenStack\Identity\v3\Service
153
    {
154
        $defaults = ['catalogName' => 'keystone', 'catalogType' => 'identity'];
155
        return $this->builder->createService('Identity\\v3', array_merge($defaults, $options));
156
    }
157
158
    /**
159
     * Creates a new Object Store v1 service.
160
     *
161
     * @param array $options Options that will be used in configuring the service.
162
     *
163
     * @return \OpenStack\ObjectStore\v1\Service
164
     */
165
    public function objectStoreV1(array $options = []): \OpenStack\ObjectStore\v1\Service
166
    {
167
        $defaults = ['catalogName' => 'swift', 'catalogType' => 'object-store'];
168
        return $this->builder->createService('ObjectStore\\v1', array_merge($defaults, $options));
169
    }
170
171
    /**
172
     * Creates a new Block Storage v2 service.
173
     *
174
     * @param array $options Options that will be used in configuring the service.
175
     *
176
     * @return \OpenStack\BlockStorage\v2\Service
177
     */
178
    public function blockStorageV2(array $options = []): \OpenStack\BlockStorage\v2\Service
179
    {
180
        $defaults = ['catalogName' => 'cinderv2', 'catalogType' => 'volumev2'];
181
        return $this->builder->createService('BlockStorage\\v2', array_merge($defaults, $options));
182
    }
183
184
    /**
185
     * Creates a new Images v2 service.
186
     *
187
     * @param array $options Options that will be used in configuring the service.
188
     *
189
     * @return \OpenStack\Images\v2\Service
190
     */
191
    public function imagesV2(array $options = []): \OpenStack\Images\v2\Service
192
    {
193
        $defaults = ['catalogName' => 'glance', 'catalogType' => 'image'];
194
        return $this->builder->createService('Images\\v2', array_merge($defaults, $options));
195
    }
196
197
    /**
198
     * Creates a new Gnocchi Metric service v1
199
     *
200
     * @param array $options
201
     *
202
     * @return \OpenStack\Metric\v1\Gnocchi\Service
203
     */
204
    public function metricGnocchiV1(array $options = []): \OpenStack\Metric\v1\Gnocchi\Service
205
    {
206
        $defaults = ['catalogName' => 'gnocchi', 'catalogType' => 'metric'];
207
208
        return $this->builder->createService('Metric\\v1\\Gnocchi', array_merge($defaults, $options));
209
    }
210
}
211