Passed
Push — master ( 851c5d...3501a4 )
by Artem
01:43
created

LKENodePoolRepository::deleteLKENodePool()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
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\LinodeClient;
17
use Linode\LKE\LKENodePool;
18
use Linode\LKE\LKENodePoolRepositoryInterface;
19
20
/**
21
 * @codeCoverageIgnore This class was autogenerated.
22
 */
23
class LKENodePoolRepository extends AbstractRepository implements LKENodePoolRepositoryInterface
24
{
25
    /**
26
     * @param int $clusterId ID of the Kubernetes cluster to look up.
27
     */
28
    public function __construct(LinodeClient $client, protected int $clusterId)
29
    {
30
        parent::__construct($client);
31
    }
32
33
    public function postLKEClusterPools(array $parameters = []): LKENodePool
34
    {
35
        $response = $this->client->post($this->getBaseUri(), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new LKENodePool($this->client, $json);
40
    }
41
42
    public function putLKENodePool(int $poolId, array $parameters = []): LKENodePool
43
    {
44
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $poolId), $parameters);
45
        $contents = $response->getBody()->getContents();
46
        $json     = json_decode($contents, true);
47
48
        return new LKENodePool($this->client, $json);
49
    }
50
51
    public function deleteLKENodePool(int $poolId): void
52
    {
53
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $poolId));
54
    }
55
56
    public function postLKEClusterPoolRecycle(int $poolId): void
57
    {
58
        $this->client->post(sprintf('%s/%s/recycle', $this->getBaseUri(), $poolId));
59
    }
60
61
    public function getLKEClusterAPIEndpoints(): array
62
    {
63
        $response = $this->client->get(sprintf('/lke/clusters/%s/api-endpoints', $this->getBaseUri()));
64
        $contents = $response->getBody()->getContents();
65
        $json     = json_decode($contents, true);
66
67
        return array_map(static fn ($data) => $data['endpoint'], $json['data']);
68
    }
69
70
    public function getLKEClusterKubeconfig(): string
71
    {
72
        $response = $this->client->get(sprintf('/lke/clusters/%s/kubeconfig', $this->getBaseUri()));
73
        $contents = $response->getBody()->getContents();
74
        $json     = json_decode($contents, true);
75
76
        return $json['kubeconfig'];
77
    }
78
79
    protected function getBaseUri(): string
80
    {
81
        return sprintf('/lke/clusters/%s/pools', $this->clusterId);
82
    }
83
84
    protected function getSupportedFields(): array
85
    {
86
        return [
87
            LKENodePool::FIELD_ID,
88
            LKENodePool::FIELD_NODES,
89
        ];
90
    }
91
92
    protected function jsonToEntity(array $json): Entity
93
    {
94
        return new LKENodePool($this->client, $json);
95
    }
96
}
97