Passed
Push — master ( bfa63a...41a424 )
by Artem
01:47
created

LKEClusterRepository   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 33
c 1
b 0
f 0
dl 0
loc 85
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteLKECluster() 0 3 1
A postLKEClusterNodeRecycle() 0 3 1
A getBaseUri() 0 3 1
A createLKECluster() 0 7 1
A getLKEClusterNode() 0 7 1
A getSupportedFields() 0 11 1
A postLKEClusterRecycle() 0 3 1
A putLKECluster() 0 7 1
A deleteLKEClusterNode() 0 3 1
A getLKEClusterKubeconfig() 0 7 1
A jsonToEntity() 0 3 1
A deleteLKEClusterKubeconfig() 0 3 1
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\LKE\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\LKE\LKECluster;
17
use Linode\LKE\LKEClusterRepositoryInterface;
18
use Linode\LKE\LKENodeStatus;
19
20
/**
21
 * @codeCoverageIgnore This class was autogenerated.
22
 */
23
class LKEClusterRepository extends AbstractRepository implements LKEClusterRepositoryInterface
24
{
25
    public function createLKECluster(array $parameters = []): LKECluster
26
    {
27
        $response = $this->client->post($this->getBaseUri(), $parameters);
28
        $contents = $response->getBody()->getContents();
29
        $json     = json_decode($contents, true);
30
31
        return new LKECluster($this->client, $json);
32
    }
33
34
    public function putLKECluster(int $clusterId, array $parameters = []): LKECluster
35
    {
36
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $clusterId), $parameters);
37
        $contents = $response->getBody()->getContents();
38
        $json     = json_decode($contents, true);
39
40
        return new LKECluster($this->client, $json);
41
    }
42
43
    public function deleteLKECluster(int $clusterId): void
44
    {
45
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $clusterId));
46
    }
47
48
    public function postLKEClusterRecycle(int $clusterId): void
49
    {
50
        $this->client->post(sprintf('%s/%s/recycle', $this->getBaseUri(), $clusterId));
51
    }
52
53
    public function getLKEClusterNode(int $clusterId, string $nodeId): LKENodeStatus
54
    {
55
        $response = $this->client->get(sprintf('%s/%s/nodes/%s', $this->getBaseUri(), $clusterId, $nodeId));
56
        $contents = $response->getBody()->getContents();
57
        $json     = json_decode($contents, true);
58
59
        return new LKENodeStatus($this->client, $json);
60
    }
61
62
    public function deleteLKEClusterNode(int $clusterId, string $nodeId): void
63
    {
64
        $this->client->delete(sprintf('%s/%s/nodes/%s', $this->getBaseUri(), $clusterId, $nodeId));
65
    }
66
67
    public function postLKEClusterNodeRecycle(int $clusterId, string $nodeId): void
68
    {
69
        $this->client->post(sprintf('%s/%s/nodes/%s/recycle', $this->getBaseUri(), $clusterId, $nodeId));
70
    }
71
72
    public function getLKEClusterKubeconfig(int $clusterId): string
73
    {
74
        $response = $this->client->get(sprintf('%s/%s/kubeconfig', $this->getBaseUri(), $clusterId));
75
        $contents = $response->getBody()->getContents();
76
        $json     = json_decode($contents, true);
77
78
        return $json['kubeconfig'];
79
    }
80
81
    public function deleteLKEClusterKubeconfig(int $clusterId): void
82
    {
83
        $this->client->delete(sprintf('%s/%s/kubeconfig', $this->getBaseUri(), $clusterId));
84
    }
85
86
    protected function getBaseUri(): string
87
    {
88
        return '/lke/clusters';
89
    }
90
91
    protected function getSupportedFields(): array
92
    {
93
        return [
94
            LKECluster::FIELD_ID,
95
            LKECluster::FIELD_LABEL,
96
            LKECluster::FIELD_REGION,
97
            LKECluster::FIELD_CREATED,
98
            LKECluster::FIELD_UPDATED,
99
            LKECluster::FIELD_K8S_VERSION,
100
            LKECluster::FIELD_TAGS,
101
            LKECluster::FIELD_CONTROL_PLANE,
102
        ];
103
    }
104
105
    protected function jsonToEntity(array $json): Entity
106
    {
107
        return new LKECluster($this->client, $json);
108
    }
109
}
110