From 5850068a582dcaf24827294232ba12953fcdfe00 Mon Sep 17 00:00:00 2001 From: Dick van der Heiden Date: Tue, 14 Dec 2021 15:03:28 +0100 Subject: [PATCH] Prepare update to API version 1.101 --- .github/ISSUE_TEMPLATE/bug_report.md | 6 +-- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- CHANGELOG.md | 29 ++++++++-- README.md | 2 +- src/Client.php | 2 +- src/Endpoints/Certificates.php | 65 ++++++++++++++--------- src/Endpoints/SshKeys.php | 46 ---------------- 7 files changed, 69 insertions(+), 83 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 62805f007..9d4786c64 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -3,7 +3,7 @@ name: Bug report about: Create a report to help us improve title: "" labels: bug -assignees: vdhicts +assignees: dvdheiden --- @@ -11,10 +11,6 @@ assignees: vdhicts A clear and concise description of what the bug is. -## Affects - -For example: unix-users endpoint - ## Reproduction Steps to reproduce the behavior. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index afed91956..ac4c07efa 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -3,7 +3,7 @@ name: Feature request about: Suggest an idea for this project title: "" labels: feature -assignees: vdhicts +assignees: dvdheiden --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 644b7d0e8..f42538c8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,34 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) cluster API. See the changelog of the [cluster API](https://cluster-api.cyberfusion.nl/redoc#section/Changelog) for detailed information. +## [1.34.0] + +### Added + +- Add the Let's Encrypt certificate endpoint: `createLetsEncryptCertificate`. +- Add the endpoint to provide your own SSL certificates: `createCertificateWithOwnMaterial`. + +### Changed + +- Update to [API version 1.101](https://cluster-api.cyberfusion.nl/redoc#section/Changelog/1.101-2021-12-14). +- Issue templates to assign the correct user instead of the organisation. Also made the bug report a bit easier to use. + +### Fixed + +- Not all headers in this changelog were of the correct depth. + +### Removed + +- Remove the `common_names` and `main_common_name` from the certificate update as it can't be changed. +- Remove the SSH key update endpoint as it's no longer available. + ## [1.33.1] -## Fixed +### Fixed - The MariaDB password hash for Database Users is now generated correctly. -## [1.33.0] +### [1.33.0] ## Changed @@ -25,7 +46,7 @@ detailed information. ## [1.32.2] -## Fixed +### Fixed - Make e-mailaddress of the Cron and the unit name of the FPM pool optional. @@ -406,7 +427,7 @@ detailed information. - Add mail aliases endpoint. - Add `balancer_backend_name` to virtualhosts. - Add `catch_all_forward_email_addresses` to mail domain. -- Add commit call to the cluster endpoint. See the [readme](readme.md) for more information. +- Add commit call to the cluster endpoint. See the [readme](README.md) for more information. ### Changed diff --git a/README.md b/README.md index ed491b632..95d596dde 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Cyberfusion cluster API client Easily use the [API of the clusters](https://cluster-api.cyberfusion.nl/) of the hosting company -[Cyberfusion](https://cyberfusion.nl/). This package is build and tested on the **1.97** version of the API. +[Cyberfusion](https://cyberfusion.nl/). This package is build and tested on the **1.101** version of the API. This package is not created or maintained by Cyberfusion. ## Requirements diff --git a/src/Client.php b/src/Client.php index 401496317..38857419a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -20,7 +20,7 @@ class Client implements ClientContract { private const CONNECT_TIMEOUT = 60; private const TIMEOUT = 180; - private const VERSION = '1.33.1'; + private const VERSION = '1.34.0'; private const USER_AGENT = 'cyberfusion-cluster-api-client/' . self::VERSION; private Configuration $configuration; diff --git a/src/Endpoints/Certificates.php b/src/Endpoints/Certificates.php index 71fe196a6..76e4e559c 100644 --- a/src/Endpoints/Certificates.php +++ b/src/Endpoints/Certificates.php @@ -11,8 +11,6 @@ class Certificates extends Endpoint { /** - * @param ListFilter|null $filter - * @return Response * @throws RequestException */ public function list(ListFilter $filter = null): Response @@ -43,8 +41,6 @@ function (array $data) { } /** - * @param int $id - * @return Response * @throws RequestException */ public function get(int $id): Response @@ -66,24 +62,51 @@ public function get(int $id): Response } /** - * @param Certificate $certificate - * @return Response * @throws RequestException */ - public function create(Certificate $certificate): Response + public function createLetsEncryptCertificate(Certificate $certificate): Response { - $requiredAttributes = is_null($certificate->getCertificate()) - ? ['common_names', 'cluster_id'] // Request Let's Encrypt certificate - : ['certificate', 'ca_chain', 'private_key', 'cluster_id']; // Supply own certificate - $this->validateRequired($certificate, 'create', $requiredAttributes); - - $isLetEnscrypt = $certificate->isLetsEncrypt(); + $this->validateRequired($certificate, 'create', [ + 'common_names', + 'cluster_id', + ]); $request = (new Request()) ->setMethod(Request::METHOD_POST) - ->setUrl('certificates') + ->setUrl('certificates/lets-encrypt') ->setBody($this->filterFields($certificate->toArray(), [ 'common_names', + 'cluster_id', + ])); + + $response = $this + ->client + ->request($request); + if (!$response->isSuccess()) { + return $response; + } + + return $response->setData([ + 'certificate' => (new Certificate())->fromArray($response->getData()), + ]); + } + + /** + * @throws RequestException + */ + public function createCertificateWithOwnMaterial(Certificate $certificate): Response + { + $this->validateRequired($certificate, 'create', [ + 'certificate', + 'ca_chain', + 'private_key', + 'cluster_id', + ]); + + $request = (new Request()) + ->setMethod(Request::METHOD_POST) + ->setUrl('certificates/own-material') + ->setBody($this->filterFields($certificate->toArray(), [ 'certificate', 'ca_chain', 'private_key', @@ -100,11 +123,9 @@ public function create(Certificate $certificate): Response $certificate = (new Certificate())->fromArray($response->getData()); // Log which cluster is affected by this change - if (!$isLetEnscrypt) { - $this - ->client - ->addAffectedCluster($certificate->getClusterId()); - } + $this + ->client + ->addAffectedCluster($certificate->getClusterId()); return $response->setData([ 'certificate' => $certificate, @@ -112,8 +133,6 @@ public function create(Certificate $certificate): Response } /** - * @param Certificate $certificate - * @return Response * @throws RequestException */ public function update(Certificate $certificate): Response @@ -124,8 +143,6 @@ public function update(Certificate $certificate): Response ->setMethod(Request::METHOD_PATCH) ->setUrl(sprintf('certificates/%d', $certificate->getId())) ->setBody($this->filterFields($certificate->toArray(), [ - 'main_common_name', - 'common_names', 'certificate', 'ca_chain', 'private_key', @@ -152,8 +169,6 @@ public function update(Certificate $certificate): Response } /** - * @param int $id - * @return Response * @throws RequestException */ public function delete(int $id): Response diff --git a/src/Endpoints/SshKeys.php b/src/Endpoints/SshKeys.php index c948fb299..33cc401b0 100644 --- a/src/Endpoints/SshKeys.php +++ b/src/Endpoints/SshKeys.php @@ -107,52 +107,6 @@ public function create(SshKey $sshKey): Response ]); } - /** - * @param SshKey $sshKey - * @return Response - * @throws RequestException - */ - public function update(SshKey $sshKey): Response - { - $this->validateRequired($sshKey, 'update', [ - 'name', - 'public_key', - 'unix_user_id', - 'id', - 'cluster_id', - ]); - - $request = (new Request()) - ->setMethod(Request::METHOD_PUT) - ->setUrl(sprintf('ssh-keys/%d', $sshKey->getId())) - ->setBody($this->filterFields($sshKey->toArray(), [ - 'name', - 'public_key', - 'private_key', - 'unix_user_id', - 'id', - 'cluster_id', - ])); - - $response = $this - ->client - ->request($request); - if (!$response->isSuccess()) { - return $response; - } - - $sshKey = (new SshKey())->fromArray($response->getData()); - - // Log which cluster is affected by this change - $this - ->client - ->addAffectedCluster($sshKey->getClusterId()); - - return $response->setData([ - 'sshKey' => $sshKey, - ]); - } - /** * @param int $id * @return Response