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\LinodeClient; |
17
|
|
|
use Linode\NodeBalancers\NodeBalancer; |
18
|
|
|
use Linode\NodeBalancers\NodeBalancerConfig; |
19
|
|
|
use Linode\NodeBalancers\NodeBalancerConfigRepositoryInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
23
|
|
|
*/ |
24
|
|
|
class NodeBalancerConfigRepository extends AbstractRepository implements NodeBalancerConfigRepositoryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param int $nodeBalancerId The ID of the NodeBalancer to access. |
28
|
|
|
*/ |
29
|
|
|
public function __construct(LinodeClient $client, protected int $nodeBalancerId) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($client); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function createNodeBalancerConfig(array $parameters = []): NodeBalancerConfig |
35
|
|
|
{ |
36
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
37
|
|
|
$contents = $response->getBody()->getContents(); |
38
|
|
|
$json = json_decode($contents, true); |
39
|
|
|
|
40
|
|
|
return new NodeBalancerConfig($this->client, $json); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function updateNodeBalancerConfig(int $configId, array $parameters = []): NodeBalancerConfig |
44
|
|
|
{ |
45
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $configId), $parameters); |
46
|
|
|
$contents = $response->getBody()->getContents(); |
47
|
|
|
$json = json_decode($contents, true); |
48
|
|
|
|
49
|
|
|
return new NodeBalancerConfig($this->client, $json); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function deleteNodeBalancerConfig(int $configId): void |
53
|
|
|
{ |
54
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $configId)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function rebuildNodeBalancerConfig(int $configId, array $parameters = []): NodeBalancer |
58
|
|
|
{ |
59
|
|
|
$response = $this->client->post(sprintf('%s/%s/rebuild', $this->getBaseUri(), $configId), $parameters); |
60
|
|
|
$contents = $response->getBody()->getContents(); |
61
|
|
|
$json = json_decode($contents, true); |
62
|
|
|
|
63
|
|
|
return new NodeBalancer($this->client, $json); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function getBaseUri(): string |
67
|
|
|
{ |
68
|
|
|
return sprintf('/nodebalancers/%s/configs', $this->nodeBalancerId); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function getSupportedFields(): array |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
NodeBalancerConfig::FIELD_ID, |
75
|
|
|
NodeBalancerConfig::FIELD_PORT, |
76
|
|
|
NodeBalancerConfig::FIELD_PROTOCOL, |
77
|
|
|
NodeBalancerConfig::FIELD_ALGORITHM, |
78
|
|
|
NodeBalancerConfig::FIELD_STICKINESS, |
79
|
|
|
NodeBalancerConfig::FIELD_CHECK, |
80
|
|
|
NodeBalancerConfig::FIELD_CHECK_INTERVAL, |
81
|
|
|
NodeBalancerConfig::FIELD_CHECK_TIMEOUT, |
82
|
|
|
NodeBalancerConfig::FIELD_CHECK_ATTEMPTS, |
83
|
|
|
NodeBalancerConfig::FIELD_CHECK_PATH, |
84
|
|
|
NodeBalancerConfig::FIELD_CHECK_BODY, |
85
|
|
|
NodeBalancerConfig::FIELD_CHECK_PASSIVE, |
86
|
|
|
NodeBalancerConfig::FIELD_CIPHER_SUITE, |
87
|
|
|
NodeBalancerConfig::FIELD_SSL_COMMONNAME, |
88
|
|
|
NodeBalancerConfig::FIELD_SSL_FINGERPRINT, |
89
|
|
|
NodeBalancerConfig::FIELD_SSL_CERT, |
90
|
|
|
NodeBalancerConfig::FIELD_SSL_KEY, |
91
|
|
|
NodeBalancerConfig::FIELD_NODES_STATUS, |
92
|
|
|
NodeBalancerConfig::FIELD_NODEBALANCER_ID, |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
protected function jsonToEntity(array $json): Entity |
97
|
|
|
{ |
98
|
|
|
return new NodeBalancerConfig($this->client, $json); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|