1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
4
|
|
|
// |
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
6
|
|
|
// |
7
|
|
|
// You should have received a copy of the MIT License along with |
8
|
|
|
// this file. If not, see <https://opensource.org/licenses/MIT>. |
9
|
|
|
// |
10
|
|
|
// --------------------------------------------------------------------- |
11
|
|
|
|
12
|
|
|
namespace Linode\NodeBalancers\Repository; |
13
|
|
|
|
14
|
|
|
use Linode\Entity; |
15
|
|
|
use Linode\Internal\AbstractRepository; |
16
|
|
|
use Linode\Networking\Firewall; |
17
|
|
|
use Linode\NodeBalancers\NodeBalancer; |
18
|
|
|
use Linode\NodeBalancers\NodeBalancerRepositoryInterface; |
19
|
|
|
use Linode\NodeBalancers\NodeBalancerStats; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
23
|
|
|
*/ |
24
|
|
|
class NodeBalancerRepository extends AbstractRepository implements NodeBalancerRepositoryInterface |
25
|
|
|
{ |
26
|
|
|
public function createNodeBalancer(array $parameters = []): NodeBalancer |
27
|
|
|
{ |
28
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
29
|
|
|
$contents = $response->getBody()->getContents(); |
30
|
|
|
$json = json_decode($contents, true); |
31
|
|
|
|
32
|
|
|
return new NodeBalancer($this->client, $json); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function updateNodeBalancer(int $nodeBalancerId, array $parameters = []): NodeBalancer |
36
|
|
|
{ |
37
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $nodeBalancerId), $parameters); |
38
|
|
|
$contents = $response->getBody()->getContents(); |
39
|
|
|
$json = json_decode($contents, true); |
40
|
|
|
|
41
|
|
|
return new NodeBalancer($this->client, $json); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function deleteNodeBalancer(int $nodeBalancerId): void |
45
|
|
|
{ |
46
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $nodeBalancerId)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getNodeBalancerStats(int $nodeBalancerId): NodeBalancerStats |
50
|
|
|
{ |
51
|
|
|
$response = $this->client->get(sprintf('%s/%s/stats', $this->getBaseUri(), $nodeBalancerId)); |
52
|
|
|
$contents = $response->getBody()->getContents(); |
53
|
|
|
$json = json_decode($contents, true); |
54
|
|
|
|
55
|
|
|
return new NodeBalancerStats($this->client, $json); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getNodeBalancerFirewalls(int $nodeBalancerId): array |
59
|
|
|
{ |
60
|
|
|
$response = $this->client->get(sprintf('%s/%s/firewalls', $this->getBaseUri(), $nodeBalancerId)); |
61
|
|
|
$contents = $response->getBody()->getContents(); |
62
|
|
|
$json = json_decode($contents, true); |
63
|
|
|
|
64
|
|
|
return array_map(fn ($data) => new Firewall($this->client, $data), $json['data']); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function getBaseUri(): string |
68
|
|
|
{ |
69
|
|
|
return '/nodebalancers'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function getSupportedFields(): array |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
NodeBalancer::FIELD_ID, |
76
|
|
|
NodeBalancer::FIELD_LABEL, |
77
|
|
|
NodeBalancer::FIELD_REGION, |
78
|
|
|
NodeBalancer::FIELD_HOSTNAME, |
79
|
|
|
NodeBalancer::FIELD_IPV4, |
80
|
|
|
NodeBalancer::FIELD_IPV6, |
81
|
|
|
NodeBalancer::FIELD_CLIENT_CONN_THROTTLE, |
82
|
|
|
NodeBalancer::FIELD_CREATED, |
83
|
|
|
NodeBalancer::FIELD_UPDATED, |
84
|
|
|
NodeBalancer::FIELD_TAGS, |
85
|
|
|
NodeBalancer::FIELD_TRANSFER, |
86
|
|
|
]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function jsonToEntity(array $json): Entity |
90
|
|
|
{ |
91
|
|
|
return new NodeBalancer($this->client, $json); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|