Skip to content

Commit

Permalink
Merge pull request #129 from CyberfusionIO/feature/1.238.0
Browse files Browse the repository at this point in the history
Update to API version 1.238.0
  • Loading branch information
WilliamDEdwards authored Jan 20, 2025
2 parents 7280644 + dc972ae commit b0cd7a1
Show file tree
Hide file tree
Showing 29 changed files with 292 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.1', '8.2', '8.3' ]
php-versions: [ '8.1', '8.2', '8.3', '8.4' ]

name: PHP ${{ matrix.php-versions }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ composer.lock
/.idea/
/build/
.phpunit.result.cache
.phpunit.cache

# macOS
.DS_Store
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
this package and not the Core API. See the changelog of the [Core API](https://core-api.cyberfusion.io/redoc#section/Changelog)
for detailed information.

## [1.118.0]

### Added

- Add NextCloud endpoints.
- Add `index` property to `CmsConfigurationContstant` and add it to the request body.
- Add plugin methods to CMSes endpoint.
- Add `reference` property to the `TaskCollection` model.
- Add `deploymentResults` method to the `Cluster` endpoint.
- Add `ClamAV` as node group.
- Add `AWS` as option for the `external_provider_name` property of the `FirewallRule` model.
- Add `name` property to the `BorgArchiveMetadata` model.
- Add `load_balancing_method` property to the `Cluster` model.
- Add `load_balancing_method` property to the `HAProxyListen` model.
- Add compatibility for this client for PHP 8.4.

### Changed

- Update to [API version 1.238.0](https://core-api.cyberfusion.io/redoc#section/Changelog/1.238.0-2024-12-27).

### Fixed

- Fix task collection return when just the `task_collection_uuid` is returned.

### Removed

- Removed the `show_raw_message` parameter from the LogFilter as the raw message is now always returned.
- Removed the `restore` method of the `CertificateManagers` endpoint as Certificate Manager are no longer soft-deleted.

## [1.117.1]

### Fixed
Expand Down
6 changes: 1 addition & 5 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\Config\RectorConfig;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
SetList::PHP_80,
SetList::PHP_81,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
]);
Expand All @@ -22,9 +20,7 @@
]);

$rectorConfig->skip([
AddLiteralSeparatorToNumberRector::class,
CountArrayToEmptyArrayComparisonRector::class,
JsonThrowOnErrorRector::class,
DisallowedEmptyRuleFixerRector::class,
]);

Expand Down
32 changes: 13 additions & 19 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@ class Client implements ClientContract
private const CONNECT_TIMEOUT = 60;

private const TIMEOUT = 180;

private const VERSION = '1.117.1';

private const USER_AGENT = 'cyberfusion-cluster-api-client/' . self::VERSION;
private const VERSION = '1.118.0';

private ClientInterface $httpClient;
private const USER_AGENT = 'cyberfusion-cluster-api-client/' . self::VERSION;

/**
* @throws ClientException
* @throws ClusterApiException
*/
public function __construct(
private Configuration $configuration,
private readonly Configuration $configuration,
bool $manuallyAuthenticate = false,
ClientInterface $httpClient = null
private ?ClientInterface $httpClient = null
) {
// Initialize the HTTP client
$this->initHttpClient($httpClient);
Expand All @@ -52,21 +50,17 @@ public function __construct(
/**
* Initialize the HTTP client with default configuration which is used for every request.
*/
private function initHttpClient(ClientInterface $httpClient = null): void
private function initHttpClient(?ClientInterface $httpClient = null): void
{
if ($httpClient instanceof ClientInterface) {
$this->httpClient = $httpClient;

return;
if (!$httpClient instanceof ClientInterface) {
$this->httpClient = new GuzzleClient([
'timeout' => self::TIMEOUT,
'connect_timeout' => self::CONNECT_TIMEOUT,
'headers' => [
'User-Agent' => self::USER_AGENT,
]
]);
}

$this->httpClient = new GuzzleClient([
'timeout' => self::TIMEOUT,
'connect_timeout' => self::CONNECT_TIMEOUT,
'headers' => [
'User-Agent' => self::USER_AGENT,
]
]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ClusterApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

class ClusterApi
{
public function __construct(private ClientContract $client)
public function __construct(private readonly ClientContract $client)
{
}

Expand Down
21 changes: 0 additions & 21 deletions src/Endpoints/CertificateManagers.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,6 @@ public function update(CertificateManager $certificateManager): Response
]);
}

/**
* @throws RequestException
*/
public function restore(int $id): Response
{
$request = (new Request())
->setMethod(Request::METHOD_POST)
->setUrl(sprintf('certificate-managers/%d/restore', $id));

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

return $response->setData([
'certificateManager' => (new CertificateManager())->fromArray($response->getData()),
]);
}

/**
* @throws RequestException
*/
Expand Down
33 changes: 33 additions & 0 deletions src/Endpoints/Clusters.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use Cyberfusion\ClusterApi\Models\IpAddressCreate;
use Cyberfusion\ClusterApi\Models\IpAddressProduct;
use Cyberfusion\ClusterApi\Models\TaskCollection;
use Cyberfusion\ClusterApi\Models\TaskResult;
use Cyberfusion\ClusterApi\Models\UnixUsersHomeDirectoryUsage;
use Cyberfusion\ClusterApi\Request;
use Cyberfusion\ClusterApi\Response;
use Cyberfusion\ClusterApi\Support\ListFilter;
use Cyberfusion\ClusterApi\Support\Str;
use DateTimeInterface;

class Clusters extends Endpoint
Expand Down Expand Up @@ -76,6 +78,7 @@ public function create(Cluster $cluster): Response
'groups',
'unix_users_home_directory',
'php_versions',
'load_balancing_method',
'mariadb_version',
'mariadb_cluster_name',
'php_settings',
Expand Down Expand Up @@ -132,6 +135,7 @@ public function create(Cluster $cluster): Response
'groups',
'unix_users_home_directory',
'php_versions',
'load_balancing_method',
'mariadb_version',
'mariadb_cluster_name',
'php_settings',
Expand Down Expand Up @@ -203,6 +207,7 @@ public function update(Cluster $cluster): Response
'groups',
'unix_users_home_directory',
'php_versions',
'load_balancing_method',
'mariadb_version',
'mariadb_cluster_name',
'php_settings',
Expand Down Expand Up @@ -262,6 +267,7 @@ public function update(Cluster $cluster): Response
'groups',
'unix_users_home_directory',
'php_versions',
'load_balancing_method',
'mariadb_version',
'mariadb_cluster_name',
'php_settings',
Expand Down Expand Up @@ -522,4 +528,31 @@ public function products(): Response
),
]);
}

public function deploymentResults(int $id, bool $nonRunning = false): Response
{
$url = Str::optionalQueryParameters(
sprintf('clusters/%s/deployment-results', $id),
['get_non_running' => $nonRunning]
);

$request = (new Request())
->setMethod(Request::METHOD_GET)
->setUrl($url);

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

return $response->setData([
'created_at' => $response->getData('created_at'),
'taskResults' => array_map(
fn (array $data) => (new TaskResult())->fromArray($data),
$response->getData('tasks_results')
),
]);
}
}
97 changes: 96 additions & 1 deletion src/Endpoints/Cmses.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Cyberfusion\ClusterApi\Models\CmsInstallation;
use Cyberfusion\ClusterApi\Models\CmsOption;
use Cyberfusion\ClusterApi\Models\CmsUserCredentials;
use Cyberfusion\ClusterApi\Models\DetailMessage;
use Cyberfusion\ClusterApi\Models\TaskCollection;
use Cyberfusion\ClusterApi\Request;
use Cyberfusion\ClusterApi\Response;
Expand Down Expand Up @@ -285,8 +286,8 @@ public function updateConfigurationConstant(int $id, CmsConfigurationConstant $c
->setUrl(sprintf('cmses/%d/configuration-constants/%d', $id, $cmsConfigurationConstant->getName()))
->setBody(
$this->filterFields($cmsConfigurationConstant->toArray(), [
'name',
'value',
'index',
])
);

Expand Down Expand Up @@ -432,4 +433,98 @@ public function updateUserCredentials(int $id, int $userId, CmsUserCredentials $

return null;
}

public function plugins(int $id): Response
{
$request = (new Request())
->setMethod(Request::METHOD_GET)
->setUrl(sprintf('cmses/%d/plugins', $id));

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

return $response->setData([
'plugins' => $response->getData(),
]);
}

public function updateCore(int $id, ?string $callbackUrl = null): Response
{
$url = Str::optionalQueryParameters(
sprintf('cmses/%d/core/update', $id),
['callback_url' => $callbackUrl]
);

$request = (new Request())
->setMethod(Request::METHOD_POST)
->setUrl($url);

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

return $response->setData([
'taskCollection' => (new TaskCollection())->fromArray($response->getData()),
]);
}

public function updatePlugin(int $id, string $name, ?string $callbackUrl = null): Response
{
$url = Str::optionalQueryParameters(
sprintf('cmses/%d/plugins/%s/update', $id, $name),
['callback_url' => $callbackUrl]
);

$request = (new Request())
->setMethod(Request::METHOD_POST)
->setUrl($url);

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

return $response->setData([
'taskCollection' => (new TaskCollection())->fromArray($response->getData()),
]);
}

public function enablePlugin(int $id, string $name): Response
{
$request = (new Request())
->setMethod(Request::METHOD_POST)
->setUrl(sprintf('cmses/%d/plugins/%s/enable', $id, $name));

$response = $this
->client
->request($request);

return $response->setData([
'detail' => (new DetailMessage())->fromArray($response->getData()),
]);
}

public function disablePlugin(int $id, string $name): Response
{
$request = (new Request())
->setMethod(Request::METHOD_POST)
->setUrl(sprintf('cmses/%d/plugins/%s/disable', $id, $name));

$response = $this
->client
->request($request);

return $response->setData([
'detail' => (new DetailMessage())->fromArray($response->getData()),
]);
}
}
2 changes: 2 additions & 0 deletions src/Endpoints/HAProxyListens.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function create(HAProxyListen $haProxyListen): Response
'nodes_ids',
'port',
'socket_path',
'load_balancing_method',
'destination_cluster_id',
'cluster_id',
]);
Expand All @@ -84,6 +85,7 @@ public function create(HAProxyListen $haProxyListen): Response
'nodes_ids',
'port',
'socket_path',
'load_balancing_method',
'destination_cluster_id',
'cluster_id',
])
Expand Down
3 changes: 3 additions & 0 deletions src/Enums/CmsConfigurationConstantName.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Cyberfusion\ClusterApi\Enums;

/*
* @deprecated see 1.231
*/
class CmsConfigurationConstantName
{
public const DB_NAME = 'DB_NAME';
Expand Down
Loading

0 comments on commit b0cd7a1

Please sign in to comment.