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 <http://opensource.org/licenses/MIT>. |
9
|
|
|
// |
10
|
|
|
// --------------------------------------------------------------------- |
11
|
|
|
|
12
|
|
|
namespace Linode\Internal\Managed; |
13
|
|
|
|
14
|
|
|
use Linode\Entity\Entity; |
15
|
|
|
use Linode\Entity\Managed\ManagedService; |
16
|
|
|
use Linode\Internal\AbstractRepository; |
17
|
|
|
use Linode\Repository\Managed\ManagedServiceRepositoryInterface; |
18
|
|
|
|
19
|
|
|
class ManagedServiceRepository extends AbstractRepository implements ManagedServiceRepositoryInterface |
20
|
|
|
{ |
21
|
1 |
|
public function create(array $parameters): ManagedService |
22
|
|
|
{ |
23
|
1 |
|
$this->checkParametersSupport($parameters); |
24
|
|
|
|
25
|
1 |
|
$response = $this->client->api($this->client::REQUEST_POST, $this->getBaseUri(), $parameters); |
26
|
1 |
|
$contents = $response->getBody()->getContents(); |
27
|
1 |
|
$json = json_decode($contents, true); |
28
|
|
|
|
29
|
1 |
|
return new ManagedService($this->client, $json); |
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
public function update(int $id, array $parameters): ManagedService |
33
|
|
|
{ |
34
|
1 |
|
$this->checkParametersSupport($parameters); |
35
|
|
|
|
36
|
1 |
|
$response = $this->client->api($this->client::REQUEST_PUT, sprintf('%s/%s', $this->getBaseUri(), $id), $parameters); |
37
|
1 |
|
$contents = $response->getBody()->getContents(); |
38
|
1 |
|
$json = json_decode($contents, true); |
39
|
|
|
|
40
|
1 |
|
return new ManagedService($this->client, $json); |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
public function delete(int $id): void |
44
|
|
|
{ |
45
|
1 |
|
$this->client->api($this->client::REQUEST_DELETE, sprintf('%s/%s', $this->getBaseUri(), $id)); |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
public function disable(int $id): ManagedService |
49
|
|
|
{ |
50
|
1 |
|
$response = $this->client->api($this->client::REQUEST_POST, sprintf('%s/%s/disable', $this->getBaseUri(), $id)); |
51
|
1 |
|
$contents = $response->getBody()->getContents(); |
52
|
1 |
|
$json = json_decode($contents, true); |
53
|
|
|
|
54
|
1 |
|
return new ManagedService($this->client, $json); |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
public function enable(int $id): ManagedService |
58
|
|
|
{ |
59
|
1 |
|
$response = $this->client->api($this->client::REQUEST_POST, sprintf('%s/%s/enable', $this->getBaseUri(), $id)); |
60
|
1 |
|
$contents = $response->getBody()->getContents(); |
61
|
1 |
|
$json = json_decode($contents, true); |
62
|
|
|
|
63
|
1 |
|
return new ManagedService($this->client, $json); |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function getSshKey(): string |
67
|
|
|
{ |
68
|
1 |
|
$response = $this->client->api($this->client::REQUEST_GET, '/managed/credentials/sshkey'); |
69
|
1 |
|
$contents = $response->getBody()->getContents(); |
70
|
1 |
|
$json = json_decode($contents, true); |
71
|
|
|
|
72
|
1 |
|
return $json['ssh_key']; |
73
|
|
|
} |
74
|
|
|
|
75
|
6 |
|
protected function getBaseUri(): string |
76
|
|
|
{ |
77
|
6 |
|
return '/managed/services'; |
78
|
|
|
} |
79
|
|
|
|
80
|
3 |
|
protected function getSupportedFields(): array |
81
|
|
|
{ |
82
|
3 |
|
return [ |
83
|
3 |
|
ManagedService::FIELD_ID, |
84
|
3 |
|
ManagedService::FIELD_STATUS, |
85
|
3 |
|
ManagedService::FIELD_SERVICE_TYPE, |
86
|
3 |
|
ManagedService::FIELD_LABEL, |
87
|
3 |
|
ManagedService::FIELD_ADDRESS, |
88
|
3 |
|
ManagedService::FIELD_CONSULTATION_GROUP, |
89
|
3 |
|
ManagedService::FIELD_TIMEOUT, |
90
|
3 |
|
ManagedService::FIELD_BODY, |
91
|
3 |
|
ManagedService::FIELD_NOTES, |
92
|
3 |
|
ManagedService::FIELD_REGION, |
93
|
3 |
|
ManagedService::FIELD_CREDENTIALS, |
94
|
3 |
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
protected function jsonToEntity(array $json): Entity |
98
|
|
|
{ |
99
|
1 |
|
return new ManagedService($this->client, $json); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|