Skip to content

Commit

Permalink
Merge pull request pypa#79 from vdhicts/feature/1.101
Browse files Browse the repository at this point in the history
Prepare update to API version 1.101
  • Loading branch information
dvdheiden authored Dec 15, 2021
2 parents 4107709 + 5850068 commit d1190d7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 83 deletions.
6 changes: 1 addition & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ name: Bug report
about: Create a report to help us improve
title: ""
labels: bug
assignees: vdhicts
assignees: dvdheiden

---

## Describe the bug

A clear and concise description of what the bug is.

## Affects

For example: unix-users endpoint

## Reproduction

Steps to reproduce the behavior.
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Feature request
about: Suggest an idea for this project
title: ""
labels: feature
assignees: vdhicts
assignees: dvdheiden

---

Expand Down
29 changes: 25 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 40 additions & 25 deletions src/Endpoints/Certificates.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
class Certificates extends Endpoint
{
/**
* @param ListFilter|null $filter
* @return Response
* @throws RequestException
*/
public function list(ListFilter $filter = null): Response
Expand Down Expand Up @@ -43,8 +41,6 @@ function (array $data) {
}

/**
* @param int $id
* @return Response
* @throws RequestException
*/
public function get(int $id): Response
Expand All @@ -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',
Expand All @@ -100,20 +123,16 @@ 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,
]);
}

/**
* @param Certificate $certificate
* @return Response
* @throws RequestException
*/
public function update(Certificate $certificate): Response
Expand All @@ -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',
Expand All @@ -152,8 +169,6 @@ public function update(Certificate $certificate): Response
}

/**
* @param int $id
* @return Response
* @throws RequestException
*/
public function delete(int $id): Response
Expand Down
46 changes: 0 additions & 46 deletions src/Endpoints/SshKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d1190d7

Please sign in to comment.