Skip to content

Commit

Permalink
Merge pull request pypa#59 from vdhicts/feature/1.77
Browse files Browse the repository at this point in the history
Update to API version 1.77
  • Loading branch information
dvdheiden authored Oct 9, 2021
2 parents e785859 + 9164e3d commit 31eed8d
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Provide a summary of your changes.

# Checks

- [ ] The version constant is updated in `Client.php`
- [ ] The changelog is updated (when applicable)
- [ ] The support Cluster API version is updated in the readme (when applicable)
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ 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.29.0]

### Added

- Add `disableAsync` to the `UnixUsers` endpoint. Thanks to @WilliamDEdwards.
- Add `unit name` property to the FPM pool. Thanks to @WilliamDEdwards.
- Add version based user agent, i.e. `cyberfusion-cluster-api-client/1.29`. Thanks to @WilliamDEdwards.

### Changed

- Add positive integer validation to `keep_hourly`, `keep_daily`, `keep_weekly`, `keep_monthly`, `keep_yearly` of Borg
Repositories.
- Add positive integer validation to `error_count` of Crons.
- Add positive integer validation to `max_children`, `max_requests`, `process_idle_timeout` and `cpu_limit` of FPM
pools.
- Add positive integer validation to `quota` of Mail accounts.
- Update to [API version 1.77](https://cluster-api.cyberfusion.nl/redoc#section/Changelog/1.77-2021-09-30)

## [1.28.0]

### Added
Expand All @@ -26,6 +44,7 @@ detailed information.

- Add `description` to unix user.
- Add `borg_repositories_directory` to unix user.
- Add user agent for this client, see `USER_AGENT` in `Client`.

### 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.65** version of the API.
[Cyberfusion](https://cyberfusion.nl/). This package is build and tested on the **1.77** version of the API.
This package is not created or maintained by Cyberfusion.

## Requirements
Expand Down
5 changes: 5 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Client implements ClientContract
{
private const CONNECT_TIMEOUT = 60;
private const TIMEOUT = 180;
private const VERSION = '1.29';
private const USER_AGENT = 'cyberfusion-cluster-api-client/' . self::VERSION;

private Configuration $configuration;
private GuzzleClient $httpClient;
Expand Down Expand Up @@ -64,6 +66,9 @@ private function initHttpClient(): void
'timeout' => self::TIMEOUT,
'connect_timeout' => self::CONNECT_TIMEOUT,
'http_errors' => false,
'headers' => [
'User-Agent' => self::USER_AGENT,
]
]);
}

Expand Down
30 changes: 30 additions & 0 deletions src/Endpoints/UnixUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,34 @@ public function enableAsync(int $id): Response
'unixUser' => $unixUser,
]);
}

/**
* @param int $id
* @return Response
* @throws RequestException
*/
public function disableAsync(int $id): Response
{
$request = (new Request())
->setMethod(Request::METHOD_DELETE)
->setUrl(sprintf('unix-users/%d/async-support', $id));

$response = $this
->client
->request($request);
if (!$response->isSuccess()) {
return $response;
}

$unixUser = (new UnixUser())->fromArray($response->getData());

// Log which cluster is affected by this change
$this
->client
->addAffectedCluster($unixUser->getClusterId());

return $response->setData([
'unixUser' => $unixUser,
]);
}
}
20 changes: 20 additions & 0 deletions src/Models/BorgRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function getKeepHourly(): ?int

public function setKeepHourly(int $keepHourly = null): BorgRepository
{
$this->validate($keepHourly, [
'positive_integer',
]);

$this->keepHourly = $keepHourly;

return $this;
Expand All @@ -70,6 +74,10 @@ public function getKeepDaily(): ?int

public function setKeepDaily(int $keepDaily = null): BorgRepository
{
$this->validate($keepDaily, [
'positive_integer',
]);

$this->keepDaily = $keepDaily;

return $this;
Expand All @@ -82,6 +90,10 @@ public function getKeepWeekly(): ?int

public function setKeepWeekly(int $keepWeekly = null): BorgRepository
{
$this->validate($keepWeekly, [
'positive_integer',
]);

$this->keepWeekly = $keepWeekly;

return $this;
Expand All @@ -94,6 +106,10 @@ public function getKeepMonthly(): ?int

public function setKeepMonthly(int $keepMonthly = null): BorgRepository
{
$this->validate($keepMonthly, [
'positive_integer',
]);

$this->keepMonthly = $keepMonthly;

return $this;
Expand All @@ -106,6 +122,10 @@ public function getKeepYearly(): ?int

public function setKeepYearly(int $keepYearly = null): BorgRepository
{
$this->validate($keepYearly, [
'positive_integer',
]);

$this->keepYearly = $keepYearly;

return $this;
Expand Down
2 changes: 2 additions & 0 deletions src/Models/ClusterModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public function __set(string $name, $value): void
private function performValidation($value, string $type, $setting): bool
{
switch ($type) {
case 'positive_integer':
return is_integer($value) && $value >= 0;
case 'length_max':
return is_string($value) && Str::length($value) <= $setting;
case 'pattern':
Expand Down
4 changes: 4 additions & 0 deletions src/Models/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public function getErrorCount(): int

public function setErrorCount(int $errorCount): Cron
{
$this->validate($errorCount, [
'positive_integer',
]);

$this->errorCount = $errorCount;

return $this;
Expand Down
31 changes: 31 additions & 0 deletions src/Models/FpmPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class FpmPool extends ClusterModel implements Model
private int $processIdleTimeout = 10;
private ?int $cpuLimit = null;
private bool $isNamespaced = false;
private ?string $unitName;
private ?int $id = null;
private ?int $clusterId = null;
private ?string $createdAt = null;
Expand Down Expand Up @@ -68,6 +69,10 @@ public function getMaxChildren(): int

public function setMaxChildren(int $maxChildren): FpmPool
{
$this->validate($maxChildren, [
'positive_integer',
]);

$this->maxChildren = $maxChildren;

return $this;
Expand All @@ -80,6 +85,10 @@ public function getMaxRequests(): int

public function setMaxRequests(int $maxRequests): FpmPool
{
$this->validate($maxRequests, [
'positive_integer',
]);

$this->maxRequests = $maxRequests;

return $this;
Expand All @@ -92,6 +101,10 @@ public function getProcessIdleTimeout(): int

public function setProcessIdleTimeout(int $processIdleTimeout): FpmPool
{
$this->validate($processIdleTimeout, [
'positive_integer',
]);

$this->processIdleTimeout = $processIdleTimeout;

return $this;
Expand All @@ -104,6 +117,10 @@ public function getCpuLimit(): ?int

public function setCpuLimit(?int $cpuLimit): FpmPool
{
$this->validate($cpuLimit, [
'positive_integer',
]);

$this->cpuLimit = $cpuLimit;

return $this;
Expand All @@ -121,6 +138,18 @@ public function setIsNamespaced(bool $isNamespaced): FpmPool
return $this;
}

public function getUnitName(): ?string
{
return $this->unitName;
}

public function setUnitName(?string $unitName): FpmPool
{
$this->unitName = $unitName;

return $this;
}

public function getId(): ?int
{
return $this->id;
Expand Down Expand Up @@ -180,6 +209,7 @@ public function fromArray(array $data): FpmPool
->setProcessIdleTimeout(Arr::get($data, 'process_idle_timeout'))
->setCpuLimit(Arr::get($data, 'cpu_limit'))
->setIsNamespaced((bool)Arr::get($data, 'is_namespaced'))
->setUnitName((bool)Arr::get($data, 'unit_name'))
->setId(Arr::get($data, 'id'))
->setClusterId(Arr::get($data, 'cluster_id'))
->setCreatedAt(Arr::get($data, 'created_at'))
Expand All @@ -197,6 +227,7 @@ public function toArray(): array
'process_idle_timeout' => $this->getProcessIdleTimeout(),
'cpu_limit' => $this->getCpuLimit(),
'is_namespaced' => $this->isNamespaced(),
'unit_name' => $this->getUnitName(),
'id' => $this->getId(),
'cluster_id' => $this->getClusterId(),
'created_at' => $this->getCreatedAt(),
Expand Down
4 changes: 4 additions & 0 deletions src/Models/MailAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function getQuota(): ?int

public function setQuota(?int $quota): MailAccount
{
$this->validate($quota, [
'positive_integer',
]);

$this->quota = $quota;

return $this;
Expand Down

0 comments on commit 31eed8d

Please sign in to comment.