1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenStack\Identity\v3\Models; |
4
|
|
|
|
5
|
|
|
use OpenStack\Common\Resource\AbstractResource; |
6
|
|
|
use OpenStack\Common\Resource\Creatable; |
7
|
|
|
use OpenStack\Common\Resource\Deletable; |
8
|
|
|
use OpenStack\Common\Resource\Listable; |
9
|
|
|
use OpenStack\Common\Resource\Retrievable; |
10
|
|
|
use OpenStack\Common\Resource\Updateable; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @property \OpenStack\Identity\v3\Api $api |
14
|
|
|
*/ |
15
|
|
|
class Service extends AbstractResource implements Creatable, Listable, Retrievable, Updateable, Deletable |
16
|
|
|
{ |
17
|
|
|
/** @var string */ |
18
|
|
|
public $id; |
19
|
|
|
|
20
|
|
|
/** @var string */ |
21
|
|
|
public $name; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
public $type; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
public $description; |
28
|
|
|
|
29
|
|
|
/** @var []Endpoint */ |
30
|
|
|
public $endpoints; |
31
|
|
|
|
32
|
|
|
/** @var array */ |
33
|
|
|
public $links; |
34
|
|
|
|
35
|
|
|
protected $resourceKey = 'service'; |
36
|
|
|
protected $resourcesKey = 'services'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritDoc} |
40
|
|
|
* |
41
|
|
|
* @param array $data {@see \OpenStack\Identity\v3\Api::postServices} |
42
|
|
|
*/ |
43
|
1 |
|
public function create(array $data) |
44
|
|
|
{ |
45
|
1 |
|
$response = $this->execute($this->api->postServices(), $data); |
46
|
1 |
|
return $this->populateFromResponse($response); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritDoc} |
51
|
|
|
*/ |
52
|
1 |
|
public function retrieve() |
53
|
|
|
{ |
54
|
1 |
|
$response = $this->executeWithState($this->api->getService()); |
55
|
1 |
|
return $this->populateFromResponse($response); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritDoc} |
60
|
|
|
*/ |
61
|
1 |
|
public function update() |
62
|
|
|
{ |
63
|
1 |
|
$response = $this->executeWithState($this->api->patchService()); |
64
|
1 |
|
return $this->populateFromResponse($response); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritDoc} |
69
|
|
|
*/ |
70
|
1 |
|
public function delete() |
71
|
|
|
{ |
72
|
1 |
|
$this->executeWithState($this->api->deleteService()); |
73
|
1 |
|
} |
74
|
|
|
|
75
|
4 |
|
private function nameMatches($value) |
76
|
|
|
{ |
77
|
4 |
|
return $this->name && $this->name == $value; |
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
private function typeMatches($value) |
81
|
|
|
{ |
82
|
2 |
|
return $this->type && $this->type = $value; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Retrieve the base URL for a service. |
87
|
|
|
* |
88
|
|
|
* @param string $name The name of the service as it appears in the catalog. |
89
|
|
|
* @param string $type The type of the service as it appears in the catalog. |
90
|
|
|
* @param string $region The region of the service as it appears in the catalog. |
91
|
|
|
* @param string $interface The interface of the service as it appears in the catalog. |
92
|
|
|
* |
93
|
|
|
* @return string|false |
94
|
|
|
*/ |
95
|
4 |
|
public function getUrl($name, $type, $region, $interface) |
96
|
|
|
{ |
97
|
4 |
|
if (!$this->nameMatches($name) || !$this->typeMatches($type)) { |
98
|
2 |
|
return false; |
99
|
|
|
} |
100
|
|
|
|
101
|
2 |
|
foreach ($this->endpoints as $endpoint) { |
102
|
2 |
|
if ($endpoint->regionMatches($region) && $endpoint->interfaceMatches($interface)) { |
103
|
2 |
|
return $endpoint->url; |
104
|
|
|
} |
105
|
1 |
|
} |
106
|
|
|
|
107
|
1 |
|
return false; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|