cyberfusion / cluster-api-client
Client for Cyberfusion Core API
Installs: 4 176
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 6
Forks: 3
Open Issues: 3
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- illuminate/support: ^8.22 || ^9.0 || ^10.0 || ^11.0
- nesbot/carbon: ^2.43
- ramsey/uuid: ^3.9 || ^4.0
- vdhicts/http-query-builder: ^1.0
Requires (Dev)
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^9.6|^10.0
- rector/rector: ^1.0.0
- symplify/easy-coding-standard: ^12.0
- dev-main
- v1.114.2
- v1.114.1
- v1.114
- v1.113.1
- v1.113.0
- v1.111.0
- v1.110.0
- v1.109.0
- v1.108.2
- v1.108.1
- v1.108.0
- v1.107.0
- v1.106.0
- v1.105.0
- v1.104.2
- v1.104.1
- v1.104.0
- v1.103.9
- v1.103.8
- v1.103.7
- v1.103.6
- v1.103.5
- v1.103.4
- v1.103.3
- v1.103.2
- v1.103.1
- v1.103.0
- v1.102.5
- v1.102.4
- v1.102.3
- v1.102.2
- v1.102.1
- v1.102.0
- v1.101.2
- v1.101.1
- v1.101.0
- v1.100.1
- v1.100.0
- v1.99.0
- v1.98.0
- v1.97.1
- v1.97.0
- v1.96.0
- v1.95.0
- v1.94.0
- v1.93.0
- v1.92.1
- v1.92.0
- v1.91.1
- v1.91.0
- v1.90.0
- v1.89.0
- v1.88.0
- v1.87.0
- v1.86.4
- v1.86.3
- v1.86.2
- v1.86.1
- v1.86.0
- v1.85.1
- v1.85.0
- v1.84.0
- v1.83.0
- v1.82.1
- v1.82.0
- v1.81.0
- v1.80.1
- v1.80.0
- v1.79.1
- v1.79.0
- v1.78.2
- v1.78.1
- v1.78.0
- v1.77.0
- v1.76.0
- v1.75.1
- v1.75.0
- v1.74.0
- v1.73.0
- v1.72.1
- v1.72.0
- v1.71.0
- v1.70.0
- v1.69.1
- v1.69.0
- v1.67.1
- v1.67.0
- v1.66.0
- v1.65.0
- v1.64.0
- v1.63.0
- v1.62.0
- v1.61.0
- v1.60.0
- v1.58.0
- v1.57.0
- v1.56.0
- v1.55.0
- v1.54.0
- v1.53.0
- v1.52.0
- v1.51.0
- v1.50.0
- v1.49.3
- v1.49.2
- v1.49.1
- v1.49.0
- v1.48.1
- v1.48.0
- v1.47.1
- v1.47.0
- v1.46.0
- v1.45.0
- v1.44.0
- v1.43.1
- v1.43.0
- v1.42.0
- v1.41.0
- v1.40.0
- v1.39.1
- v1.39.0
- v1.38.2
- v1.38.1
- v1.38.0
- v1.37.0
- v1.36.0
- v1.35.0
- v1.34.0
- V1.33.1
- v1.33.0
- v1.32.2
- v1.32.1
- v1.32.0
- v1.30.1
- v1.30.0
- v1.29.1
- v1.29.0
- v1.28.0
- v1.27.0
- v1.26.0
- v1.25.0
- v1.24.2
- v1.24.1
- v1.24.0
- v1.23.1
- v1.23.0
- v1.22.0
- v1.21.2
- v1.21.1
- v1.20.0
- v1.19.0
- v1.17.1
- v1.17.0
- v1.16.0
- v1.15.1
- v1.15.0
- v1.14.1
- v1.14.0
- v1.13.0
- v1.12.2
- v1.12.0
- v1.11.0
- v1.10.0
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.0
- v1.4.3
- v1.4.2
- v1.4.0
- v1.3.0
- v1.1.0
- v1.0.0
- dev-renovate/major-phpstan-packages
- dev-renovate/phpunit-phpunit-11.x
- dev-fix/missing-id-update
- dev-chore/require-php81
- dev-chore/update-production-url
- dev-chore/rename-core-api
- dev-renovate/nesbot-carbon-3.x
This package is auto-updated.
Last update: 2024-11-11 08:12:23 UTC
README
Client for the Cyberfusion Core API.
This client was built for and tested on the 1.230.1 version of the API.
Support
This client is officially supported by Cyberfusion. If you have any questions, open an issue on GitHub or email support@cyberfusion.nl.
The client was created by @dvdheiden.
Requirements
This client requires PHP 8.1 or higher and uses Guzzle.
Installation
This client can be used in any PHP project and with any framework.
Install the client with Composer:
composer require cyberfusion/cluster-api-client
Usage
Refer to the API documentation for information about API requests.
Getting started
use Cyberfusion\ClusterApi\Client; use Cyberfusion\ClusterApi\Configuration; use Cyberfusion\ClusterApi\ClusterApi; // Create the configuration with your username/password $configuration = Configuration::withCredentials('username', 'password'); // Start the client once and authorize $client = new Client($configuration); // Initialize the API $api = new ClusterApi($client); // Perform the request $result = $api->virtualHosts()->list(); // Access the virtual host models $virtualHosts = $result->getData('virtualHosts');
Requests
The endpoint methods may ask for filters, models and IDs. The method type hints tell you which input is requested.
Models
The endpoint may request a model. Most create and update requests do.
$unixUserUsername = 'foo'; $unixUser = (new UnixUser()) ->setUsername($unixUserUsername) ->setPassword('bar') ->setDefaultPhpVersion('7.4') ->setVirtualHostsDirectory(sprintf('/home/%d', $unixUserUsername)) ->setClusterId(1); $result = $api ->unixUsers() ->create($unixUser);
When models need to be provided, the required properties are checked before executing the request.
RequestException
is thrown when properties are missing. See the error message for more details.
Filtering data
Some endpoints require a ListFilter
and return a list of models according to the filter. It's also possible to change
the sort order.
Model filters
A ListFilter
can be initialized for a model, so it automatically validates if the provided fields are available for
the model.
use Cyberfusion\ClusterApi\Enums\Sort; use Cyberfusion\ClusterApi\Models\VirtualHost; use Cyberfusion\ClusterApi\Support\FilterEntry; use Cyberfusion\ClusterApi\Support\SortEntry; $listFilter = VirtualHost::listFilter() ->filter(new FilterEntry('server_software_name', 'Apache')) ->filter(new FilterEntry('domain', 'cyberfusion.nl')) ->sort(new SortEntry('domain', Sort::DESC));
Manually creating filters
You can initialize the ListFilter
manually, but fields are not validated if they are available for the model.
$listFilter = (new ListFilter()) ->filter(new FilterEntry('server_software_name', 'Apache')) ->filter(new FilterEntry('domain', 'cyberfusion.nl')) ->sort(new SortEntry('domain', Sort::DESC));
Or provide the entries and sort directly:
$listFilter = (new ListFilter()) ->setFilters([ new FilterEntry('server_software_name', 'Apache'), new FilterEntry('domain', 'cyberfusion.nl'), ]) ->setSort([ new SortEntry('domain', Sort::DESC) ]); );
Alternative method
This package used to offer this way to build the filter. Due to backwards compatibility, this functionality is still available.
$listFilter = ListFilter::forModel(new Cluster()) ->filter('server_software_name', 'Apache') ->filter('domain', 'cyberfusion.nl') ->sort('domain', Sort::DESC);
Or provide the entries and sort directly:
$listFilter = (new ListFilter()) ->setFilters([ ['field' => 'server_software_name', 'value' => 'Apache'], ['field' => 'domain', 'value' => 'cyberfusion.nl'], ]) ->setSort([ ['field' => 'domain', 'value' => Sort::DESC], ]); );
Manually make requests
To use the API directly, use the request()
method on the Client
. This method needs a Request
class. See the class
itself for its options.
Responses
The endpoint methods throw exceptions when requests fail due to timeouts. When the API replies with HTTP protocol
errors, the Response
class is returned nonetheless. Check if the request succeeded with: $response->isSuccess()
.
API responses are automatically converted to models.
Authentication
The API is authenticated with a username and password and returns an access token. This client takes care of authentication. To get credentials, contact Cyberfusion.
$configuration = Configuration::withCredentials('username', 'password');
When you authenticate with username and password, this client automatically retrieves the access token.
The access token is valid for 30 minutes, so there's no need to store it. To store it anyway, access it with
$configuration->getAccessToken()
.
Manually authenticate
use Cyberfusion\ClusterApi\Client; use Cyberfusion\ClusterApi\ClusterApi; use Cyberfusion\ClusterApi\Configuration; use Cyberfusion\ClusterApi\Models\Login; // Initialize the configuration without any credentials or access token $configuration = new Configuration(); // Start the client with manual authentication $client = new Client($configuration, true); // Initialize the API $api = new ClusterApi($client); // Create the request $login = (new Login()) ->setUsername('username') ->setPassword('password'); // Perform the request $response = $api ->authentication() ->login($login); // Store the access token in the configuration if ($response->isSuccess()) { $configuration->setAccessToken($response->getData('access_token')); }
Enums
Some properties should contain certain values. These values can be found in the enum classes.
Exceptions
In case of errors, the client throws an exception which extends ClusterApiException
.
All exceptions have a code. These can be found in the ClusterApiException
class.
Laravel
This client can be easily used in any Laravel application. Add your API credentials to the .env
file:
CLUSTER_USERNAME=username
CLUSTER_PASSWORD=password
Next, create a config file called cluster.php
in the config
directory:
<?php return [ 'username' => env('CLUSTER_USERNAME'), 'password' => env('CLUSTER_PASSWORD'), ];
Use those files to build the configuration:
$configuration = Configuration::withCredentials(config('cluster.username'), config('cluster.password'));
Tests
Unit tests are available in the tests
directory. Run:
composer test
To generate a code coverage report in the build/report
directory, run:
composer test-coverage
Contribution
Contributions are welcome. See the contributing guidelines.
Security
If you discover any security related issues, please email support@cyberfusion.nl instead of using the issue tracker.
License
This client is open-sourced software licensed under the MIT license.