Passed
Push — master ( 41a424...f04d85 )
by Artem
01:57
created

LKEClusterRepository::getLKEClusterDashboard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 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 getLKEClusterDashboard(int $clusterId): string
49
    {
50
        $response = $this->client->get(sprintf('%s/%s/dashboard', $this->getBaseUri(), $clusterId));
51
        $contents = $response->getBody()->getContents();
52
        $json     = json_decode($contents, true);
53
54
        return $json['url'];
55
    }
56
57
    public function postLKEClusterRecycle(int $clusterId): void
58
    {
59
        $this->client->post(sprintf('%s/%s/recycle', $this->getBaseUri(), $clusterId));
60
    }
61
62
    public function getLKEClusterNode(int $clusterId, string $nodeId): LKENodeStatus
63
    {
64
        $response = $this->client->get(sprintf('%s/%s/nodes/%s', $this->getBaseUri(), $clusterId, $nodeId));
65
        $contents = $response->getBody()->getContents();
66
        $json     = json_decode($contents, true);
67
68
        return new LKENodeStatus($this->client, $json);
69
    }
70
71
    public function deleteLKEClusterNode(int $clusterId, string $nodeId): void
72
    {
73
        $this->client->delete(sprintf('%s/%s/nodes/%s', $this->getBaseUri(), $clusterId, $nodeId));
74
    }
75
76
    public function postLKEClusterNodeRecycle(int $clusterId, string $nodeId): void
77
    {
78
        $this->client->post(sprintf('%s/%s/nodes/%s/recycle', $this->getBaseUri(), $clusterId, $nodeId));
79
    }
80
81
    public function getLKEClusterKubeconfig(int $clusterId): string
82
    {
83
        $response = $this->client->get(sprintf('%s/%s/kubeconfig', $this->getBaseUri(), $clusterId));
84
        $contents = $response->getBody()->getContents();
85
        $json     = json_decode($contents, true);
86
87
        return $json['kubeconfig'];
88
    }
89
90
    public function deleteLKEClusterKubeconfig(int $clusterId): void
91
    {
92
        $this->client->delete(sprintf('%s/%s/kubeconfig', $this->getBaseUri(), $clusterId));
93
    }
94
95
    protected function getBaseUri(): string
96
    {
97
        return '/lke/clusters';
98
    }
99
100
    protected function getSupportedFields(): array
101
    {
102
        return [
103
            LKECluster::FIELD_ID,
104
            LKECluster::FIELD_LABEL,
105
            LKECluster::FIELD_REGION,
106
            LKECluster::FIELD_CREATED,
107
            LKECluster::FIELD_UPDATED,
108
            LKECluster::FIELD_K8S_VERSION,
109
            LKECluster::FIELD_TAGS,
110
            LKECluster::FIELD_CONTROL_PLANE,
111
        ];
112
    }
113
114
    protected function jsonToEntity(array $json): Entity
115
    {
116
        return new LKECluster($this->client, $json);
117
    }
118
}
119