NodeBalancerConfigRepository::getSupportedFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

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