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
Push — master ( 4ba218...ab686e )
by Jamie
04:16
created

OpenStack::identityV2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
ccs 3
cts 3
cp 1
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php declare (strict_types=1);
2
3
namespace OpenStack;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\HandlerStack;
7
use OpenCloud\Common\Service\Builder;
8
use OpenCloud\Common\Transport\Utils;
9
use OpenStack\Identity\v3\Service;
10
11
/**
12
 * This class is the primary entry point for working with the SDK. It allows for the easy creation
13
 * of OpenStack services.
14
 *
15
 * @package OpenStack
16
 */
17
class OpenStack
18
{
19
    /** @var Builder */
20
    private $builder;
21
22
    /**
23
     * @param array $options User-defined options
24
     *
25
     * $options['username']   = (string) Your OpenStack username        [REQUIRED]
26
     *         ['password']   = (string) Your OpenStack password        [REQUIRED]
27
     *         ['tenantId']   = (string) Your tenant ID                 [REQUIRED if tenantName omitted]
28 7
     *         ['tenantName'] = (string) Your tenant name               [REQUIRED if tenantId omitted]
29
     *         ['authUrl']    = (string) The Keystone URL               [REQUIRED]
30 7
     *         ['debug']      = (bool)   Whether to enable HTTP logging [OPTIONAL]
31 7
     */
32
    public function __construct(array $options = [], Builder $builder = null)
33
    {
34
        if (!isset($options['identityService'])) {
35
            $options['identityService'] = $this->getDefaultIdentityService($options);
36
        }
37
38
        $this->builder = $builder ?: new Builder($options, 'OpenStack');
39
    }
40 1
41
    /**
42 1
     * @param array $options
43 1
     *
44
     * @return Service
45
     */
46
    private function getDefaultIdentityService(array $options): Service
47
    {
48
        if (!isset($options['authUrl'])) {
49
            throw new \InvalidArgumentException("'authUrl' is a required option");
50
        }
51
52
        return Service::factory(new Client([
53 1
            'base_uri' => Utils::normalizeUrl($options['authUrl']),
54
            'handler'  => HandlerStack::create(),
55 1
        ]));
56 1
    }
57
58
    /**
59
     * Creates a new Compute v2 service.
60
     *
61
     * @param array $options Options that will be used in configuring the service.
62
     *
63
     * @return \OpenStack\Compute\v2\Service
64
     */
65
    public function computeV2(array $options = []): \OpenStack\Compute\v2\Service
66 1
    {
67
        $defaults = ['catalogName' => 'nova', 'catalogType' => 'compute'];
68 1
        return $this->builder->createService('Compute', 2, array_merge($defaults, $options));
69 1
    }
70
71
    /**
72
     * Creates a new Networking v2 service.
73
     *
74
     * @param array $options Options that will be used in configuring the service.
75
     *
76
     * @return \OpenStack\Networking\v2\Service
77
     */
78
    public function networkingV2(array $options = []): \OpenStack\Networking\v2\Service
79 1
    {
80
        $defaults = ['catalogName' => 'neutron', 'catalogType' => 'network'];
81 1
        return $this->builder->createService('Networking', 2, array_merge($defaults, $options));
82 1
    }
83
84
    /**
85
     * Creates a new Identity v2 service.
86
     *
87
     * @param array $options Options that will be used in configuring the service.
88
     *
89
     * @return \OpenStack\Identity\v2\Service
90
     */
91
    public function identityV2(array $options = []): \OpenStack\Identity\v2\Service
92 1
    {
93
        $defaults = ['catalogName' => false, 'catalogType' => false];
94 1
        return $this->builder->createService('Identity', 2, array_merge($defaults, $options));
95 1
    }
96
97
    /**
98
     * Creates a new Identity v3 service.
99
     *
100
     * @param array $options Options that will be used in configuring the service.
101
     *
102
     * @return \OpenStack\Identity\v3\Service
103
     */
104
    public function identityV3(array $options = []): \OpenStack\Identity\v3\Service
105 1
    {
106
        $defaults = ['catalogName' => false, 'catalogType' => false];
107 1
        return $this->builder->createService('Identity', 3, array_merge($defaults, $options));
108 1
    }
109
110
    /**
111
     * Creates a new Object Store v1 service.
112
     *
113
     * @param array $options Options that will be used in configuring the service.
114
     *
115
     * @return \OpenStack\ObjectStore\v1\Service
116
     */
117
    public function objectStoreV1(array $options = []): \OpenStack\ObjectStore\v1\Service
118 1
    {
119
        $defaults = ['catalogName' => 'swift', 'catalogType' => 'object-store'];
120 1
        return $this->builder->createService('ObjectStore', 1, array_merge($defaults, $options));
121 1
    }
122
123
    /**
124
     * Creates a new Block Storage v2 service.
125
     *
126
     * @param array $options Options that will be used in configuring the service.
127
     *
128
     * @return \OpenStack\BlockStorage\v2\Service
129
     */
130
    public function blockStorageV2(array $options = []): \OpenStack\BlockStorage\v2\Service
131
    {
132
        $defaults = ['catalogName' => 'cinderv2', 'catalogType' => 'volumev2'];
133
        return $this->builder->createService('BlockStorage', 2, array_merge($defaults, $options));
134
    }
135
136
    /**
137
     * Creates a new Images v2 service.
138
     *
139
     * @param array $options Options that will be used in configuring the service.
140
     *
141
     * @return \OpenStack\Images\v2\Service
142
     */
143
    public function imagesV2(array $options = []): \OpenStack\Images\v2\Service
144
    {
145
        $defaults = ['catalogName' => 'glance', 'catalogType' => 'image'];
146
        return $this->builder->createService('Images', 2, array_merge($defaults, $options));
147
    }
148
}
149