|
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\Databases\Repository; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Databases\DatabaseBackup; |
|
15
|
|
|
use Linode\Databases\DatabaseCredentials; |
|
16
|
|
|
use Linode\Databases\DatabasePostgreSQL; |
|
17
|
|
|
use Linode\Databases\DatabasePostgreSQLRepositoryInterface; |
|
18
|
|
|
use Linode\Databases\DatabaseSSL; |
|
19
|
|
|
use Linode\Entity; |
|
20
|
|
|
use Linode\Internal\AbstractRepository; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
24
|
|
|
*/ |
|
25
|
|
|
class DatabasePostgreSQLRepository extends AbstractRepository implements DatabasePostgreSQLRepositoryInterface |
|
26
|
|
|
{ |
|
27
|
|
|
public function postDatabasesPostgreSQLInstances(array $parameters = []): DatabasePostgreSQL |
|
28
|
|
|
{ |
|
29
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
|
30
|
|
|
$contents = $response->getBody()->getContents(); |
|
31
|
|
|
$json = json_decode($contents, true); |
|
32
|
|
|
|
|
33
|
|
|
return new DatabasePostgreSQL($this->client, $json); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function putDatabasesPostgreSQLInstance(int $instanceId, array $parameters = []): DatabasePostgreSQL |
|
37
|
|
|
{ |
|
38
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $instanceId), $parameters); |
|
39
|
|
|
$contents = $response->getBody()->getContents(); |
|
40
|
|
|
$json = json_decode($contents, true); |
|
41
|
|
|
|
|
42
|
|
|
return new DatabasePostgreSQL($this->client, $json); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function deleteDatabasesPostgreSQLInstance(int $instanceId): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $instanceId)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getDatabasesPostgreSQLInstanceBackups(int $instanceId): array |
|
51
|
|
|
{ |
|
52
|
|
|
$response = $this->client->get(sprintf('%s/%s/backups', $this->getBaseUri(), $instanceId)); |
|
53
|
|
|
$contents = $response->getBody()->getContents(); |
|
54
|
|
|
$json = json_decode($contents, true); |
|
55
|
|
|
|
|
56
|
|
|
return array_map(fn ($data) => new DatabaseBackup($this->client, $data), $json['data']); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function postDatabasesPostgreSQLInstanceBackup(int $instanceId, array $parameters = []): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->client->post(sprintf('%s/%s/backups', $this->getBaseUri(), $instanceId), $parameters); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getDatabasesPostgreSQLInstanceBackup(int $instanceId, int $backupId): DatabaseBackup |
|
65
|
|
|
{ |
|
66
|
|
|
$response = $this->client->get(sprintf('%s/%s/backups/%s', $this->getBaseUri(), $instanceId, $backupId)); |
|
67
|
|
|
$contents = $response->getBody()->getContents(); |
|
68
|
|
|
$json = json_decode($contents, true); |
|
69
|
|
|
|
|
70
|
|
|
return new DatabaseBackup($this->client, $json); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function deleteDatabasePostgreSQLInstanceBackup(int $instanceId, int $backupId): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->client->delete(sprintf('%s/%s/backups/%s', $this->getBaseUri(), $instanceId, $backupId)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function postDatabasesPostgreSQLInstanceBackupRestore(int $instanceId, int $backupId): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->client->post(sprintf('%s/%s/backups/%s/restore', $this->getBaseUri(), $instanceId, $backupId)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getDatabasesPostgreSQLInstanceCredentials(int $instanceId): DatabaseCredentials |
|
84
|
|
|
{ |
|
85
|
|
|
$response = $this->client->get(sprintf('%s/%s/credentials', $this->getBaseUri(), $instanceId)); |
|
86
|
|
|
$contents = $response->getBody()->getContents(); |
|
87
|
|
|
$json = json_decode($contents, true); |
|
88
|
|
|
|
|
89
|
|
|
return new DatabaseCredentials($this->client, $json); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function postDatabasesPostgreSQLInstanceCredentialsReset(int $instanceId): void |
|
93
|
|
|
{ |
|
94
|
|
|
$this->client->post(sprintf('%s/%s/credentials/reset', $this->getBaseUri(), $instanceId)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function getDatabasesPostgreSQLInstanceSSL(int $instanceId): DatabaseSSL |
|
98
|
|
|
{ |
|
99
|
|
|
$response = $this->client->get(sprintf('%s/%s/ssl', $this->getBaseUri(), $instanceId)); |
|
100
|
|
|
$contents = $response->getBody()->getContents(); |
|
101
|
|
|
$json = json_decode($contents, true); |
|
102
|
|
|
|
|
103
|
|
|
return new DatabaseSSL($this->client, $json); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function postDatabasesPostgreSQLInstancePatch(int $instanceId): void |
|
107
|
|
|
{ |
|
108
|
|
|
$this->client->post(sprintf('%s/%s/patch', $this->getBaseUri(), $instanceId)); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
protected function getBaseUri(): string |
|
112
|
|
|
{ |
|
113
|
|
|
return 'beta/databases/postgresql/instances'; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
protected function getSupportedFields(): array |
|
117
|
|
|
{ |
|
118
|
|
|
return [ |
|
119
|
|
|
DatabasePostgreSQL::FIELD_ID, |
|
120
|
|
|
DatabasePostgreSQL::FIELD_LABEL, |
|
121
|
|
|
DatabasePostgreSQL::FIELD_REGION, |
|
122
|
|
|
DatabasePostgreSQL::FIELD_TYPE, |
|
123
|
|
|
DatabasePostgreSQL::FIELD_CLUSTER_SIZE, |
|
124
|
|
|
DatabasePostgreSQL::FIELD_ENGINE, |
|
125
|
|
|
DatabasePostgreSQL::FIELD_VERSION, |
|
126
|
|
|
DatabasePostgreSQL::FIELD_TOTAL_DISK_SIZE_GB, |
|
127
|
|
|
DatabasePostgreSQL::FIELD_USED_DISK_SIZE_GB, |
|
128
|
|
|
DatabasePostgreSQL::FIELD_PORT, |
|
129
|
|
|
DatabasePostgreSQL::FIELD_REPLICATION_TYPE, |
|
130
|
|
|
DatabasePostgreSQL::FIELD_STATUS, |
|
131
|
|
|
DatabasePostgreSQL::FIELD_REPLICATION_COMMIT_TYPE, |
|
132
|
|
|
DatabasePostgreSQL::FIELD_ENCRYPTED, |
|
133
|
|
|
DatabasePostgreSQL::FIELD_ALLOW_LIST, |
|
134
|
|
|
DatabasePostgreSQL::FIELD_HOSTS, |
|
135
|
|
|
DatabasePostgreSQL::FIELD_SSL_CONNECTION, |
|
136
|
|
|
DatabasePostgreSQL::FIELD_CREATED, |
|
137
|
|
|
DatabasePostgreSQL::FIELD_UPDATED, |
|
138
|
|
|
DatabasePostgreSQL::FIELD_UPDATES, |
|
139
|
|
|
]; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
protected function jsonToEntity(array $json): Entity |
|
143
|
|
|
{ |
|
144
|
|
|
return new DatabasePostgreSQL($this->client, $json); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|