|
5 | 5 | use Cyberfusion\ClusterApi\Enums\TimeUnit;
|
6 | 6 | use Cyberfusion\ClusterApi\Exceptions\RequestException;
|
7 | 7 | use Cyberfusion\ClusterApi\Models\Cluster;
|
| 8 | +use Cyberfusion\ClusterApi\Models\ClusterCommonProperties; |
8 | 9 | use Cyberfusion\ClusterApi\Models\UnixUsersHomeDirectoryUsage;
|
9 | 10 | use Cyberfusion\ClusterApi\Request;
|
10 | 11 | use Cyberfusion\ClusterApi\Response;
|
@@ -62,6 +63,182 @@ public function get(int $id): Response
|
62 | 63 | ]);
|
63 | 64 | }
|
64 | 65 |
|
| 66 | + /** |
| 67 | + * @throws RequestException |
| 68 | + */ |
| 69 | + public function create(Cluster $cluster): Response |
| 70 | + { |
| 71 | + $this->validateRequired($cluster, 'create', [ |
| 72 | + 'groups', |
| 73 | + 'unix_user_home_directory', |
| 74 | + 'php_versions', |
| 75 | + 'mariadb_version', |
| 76 | + 'nodejs_version', |
| 77 | + 'postgresql_version', |
| 78 | + 'mariadb_cluster_name', |
| 79 | + 'custom_php_modules_names', |
| 80 | + 'php_settings', |
| 81 | + 'php_ioncube_enabled', |
| 82 | + 'kernelcare_license_key', |
| 83 | + 'redis_password', |
| 84 | + 'redis_memory_limit', |
| 85 | + 'php_sessions_spread_enabled', |
| 86 | + 'nodejs_versions', |
| 87 | + 'description', |
| 88 | + 'wordpress_toolkit_enabled', |
| 89 | + 'automatic_borg_repositories_prune_enabled', |
| 90 | + 'malware_toolkit_enabled', |
| 91 | + 'sync_toolkit_enabled', |
| 92 | + 'bubblewrap_toolkit_enabled', |
| 93 | + 'malware_toolkit_scans_enabled', |
| 94 | + 'database_toolkit_enabled', |
| 95 | + 'mariadb_backup_interval', |
| 96 | + 'postgresql_backup_interval', |
| 97 | + 'customer_id', |
| 98 | + ]); |
| 99 | + |
| 100 | + $request = (new Request()) |
| 101 | + ->setMethod(Request::METHOD_POST) |
| 102 | + ->setUrl('clusters') |
| 103 | + ->setBody( |
| 104 | + $this->filterFields($cluster->toArray(), [ |
| 105 | + 'groups', |
| 106 | + 'unix_user_home_directory', |
| 107 | + 'php_versions', |
| 108 | + 'mariadb_version', |
| 109 | + 'nodejs_version', |
| 110 | + 'postgresql_version', |
| 111 | + 'mariadb_cluster_name', |
| 112 | + 'custom_php_modules_names', |
| 113 | + 'php_settings', |
| 114 | + 'php_ioncube_enabled', |
| 115 | + 'kernelcare_license_key', |
| 116 | + 'redis_password', |
| 117 | + 'redis_memory_limit', |
| 118 | + 'php_sessions_spread_enabled', |
| 119 | + 'nodejs_versions', |
| 120 | + 'description', |
| 121 | + 'wordpress_toolkit_enabled', |
| 122 | + 'automatic_borg_repositories_prune_enabled', |
| 123 | + 'malware_toolkit_enabled', |
| 124 | + 'sync_toolkit_enabled', |
| 125 | + 'bubblewrap_toolkit_enabled', |
| 126 | + 'malware_toolkit_scans_enabled', |
| 127 | + 'database_toolkit_enabled', |
| 128 | + 'mariadb_backup_interval', |
| 129 | + 'postgresql_backup_interval', |
| 130 | + 'customer_id', |
| 131 | + ]) |
| 132 | + ); |
| 133 | + |
| 134 | + $response = $this |
| 135 | + ->client |
| 136 | + ->request($request); |
| 137 | + if (!$response->isSuccess()) { |
| 138 | + return $response; |
| 139 | + } |
| 140 | + |
| 141 | + return $response->setData([ |
| 142 | + 'cluster' => (new Cluster())->fromArray($response->getData()), |
| 143 | + ]); |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * @throws RequestException |
| 148 | + */ |
| 149 | + public function update(Cluster $cluster): Response |
| 150 | + { |
| 151 | + $this->validateRequired($cluster, 'update', [ |
| 152 | + 'groups', |
| 153 | + 'unix_user_home_directory', |
| 154 | + 'php_versions', |
| 155 | + 'mariadb_version', |
| 156 | + 'nodejs_version', |
| 157 | + 'postgresql_version', |
| 158 | + 'mariadb_cluster_name', |
| 159 | + 'custom_php_modules_names', |
| 160 | + 'php_settings', |
| 161 | + 'php_ioncube_enabled', |
| 162 | + 'kernelcare_license_key', |
| 163 | + 'redis_password', |
| 164 | + 'redis_memory_limit', |
| 165 | + 'php_sessions_spread_enabled', |
| 166 | + 'nodejs_versions', |
| 167 | + 'description', |
| 168 | + 'wordpress_toolkit_enabled', |
| 169 | + 'automatic_borg_repositories_prune_enabled', |
| 170 | + 'malware_toolkit_enabled', |
| 171 | + 'sync_toolkit_enabled', |
| 172 | + 'bubblewrap_toolkit_enabled', |
| 173 | + 'malware_toolkit_scans_enabled', |
| 174 | + 'database_toolkit_enabled', |
| 175 | + 'mariadb_backup_interval', |
| 176 | + 'postgresql_backup_interval', |
| 177 | + 'customer_id', |
| 178 | + 'id', |
| 179 | + ]); |
| 180 | + |
| 181 | + $request = (new Request()) |
| 182 | + ->setMethod(Request::METHOD_PUT) |
| 183 | + ->setUrl(sprintf('clusters/%d', $cluster->getId())) |
| 184 | + ->setBody( |
| 185 | + $this->filterFields($cluster->toArray(), [ |
| 186 | + 'groups', |
| 187 | + 'unix_user_home_directory', |
| 188 | + 'php_versions', |
| 189 | + 'mariadb_version', |
| 190 | + 'nodejs_version', |
| 191 | + 'postgresql_version', |
| 192 | + 'mariadb_cluster_name', |
| 193 | + 'custom_php_modules_names', |
| 194 | + 'php_settings', |
| 195 | + 'php_ioncube_enabled', |
| 196 | + 'kernelcare_license_key', |
| 197 | + 'redis_password', |
| 198 | + 'redis_memory_limit', |
| 199 | + 'php_sessions_spread_enabled', |
| 200 | + 'nodejs_versions', |
| 201 | + 'description', |
| 202 | + 'wordpress_toolkit_enabled', |
| 203 | + 'automatic_borg_repositories_prune_enabled', |
| 204 | + 'malware_toolkit_enabled', |
| 205 | + 'sync_toolkit_enabled', |
| 206 | + 'bubblewrap_toolkit_enabled', |
| 207 | + 'malware_toolkit_scans_enabled', |
| 208 | + 'database_toolkit_enabled', |
| 209 | + 'mariadb_backup_interval', |
| 210 | + 'postgresql_backup_interval', |
| 211 | + 'customer_id', |
| 212 | + 'id', |
| 213 | + ]) |
| 214 | + ); |
| 215 | + |
| 216 | + $response = $this |
| 217 | + ->client |
| 218 | + ->request($request); |
| 219 | + if (!$response->isSuccess()) { |
| 220 | + return $response; |
| 221 | + } |
| 222 | + |
| 223 | + return $response->setData([ |
| 224 | + 'cluster' => (new Cluster())->fromArray($response->getData()), |
| 225 | + ]); |
| 226 | + } |
| 227 | + |
| 228 | + /** |
| 229 | + * @throws RequestException |
| 230 | + */ |
| 231 | + public function delete(int $id): Response |
| 232 | + { |
| 233 | + $request = (new Request()) |
| 234 | + ->setMethod(Request::METHOD_DELETE) |
| 235 | + ->setUrl(sprintf('clusters/%d', $id)); |
| 236 | + |
| 237 | + return $this |
| 238 | + ->client |
| 239 | + ->request($request); |
| 240 | + } |
| 241 | + |
65 | 242 | /**
|
66 | 243 | * @throws RequestException
|
67 | 244 | */
|
@@ -129,4 +306,22 @@ public function borgSshKey(int $id): Response
|
129 | 306 | 'publicKey' => $response->getData('public_key'),
|
130 | 307 | ]);
|
131 | 308 | }
|
| 309 | + |
| 310 | + public function commonProperties(): Response |
| 311 | + { |
| 312 | + $request = (new Request()) |
| 313 | + ->setMethod(Request::METHOD_GET) |
| 314 | + ->setUrl('clusters/common-properties'); |
| 315 | + |
| 316 | + $response = $this |
| 317 | + ->client |
| 318 | + ->request($request); |
| 319 | + if (!$response->isSuccess()) { |
| 320 | + return $response; |
| 321 | + } |
| 322 | + |
| 323 | + return $response->setData([ |
| 324 | + 'commonProperties' => (new ClusterCommonProperties())->fromArray($response->getData()), |
| 325 | + ]); |
| 326 | + } |
132 | 327 | }
|
0 commit comments