From d898c2c2449a4370b0add207c0297b851ee846b0 Mon Sep 17 00:00:00 2001 From: Samih Soylu Date: Fri, 29 Jan 2021 15:43:46 +0100 Subject: [PATCH] When listing OSs, you can now see licences This is in conjunction with bringing the possibility to upgrade/downgrade licences for cPanel or Plesk using the API. --- CHANGELOG.md | 4 ++ src/Entity/Vps/License.php | 88 ++++++++++++++++++++++++ src/Entity/Vps/LicenseKey.php | 24 +++++++ src/Entity/Vps/LicenseProduct.php | 48 +++++++++++++ src/Entity/Vps/Licenses.php | 41 +++++++++++ src/Entity/Vps/OperatingSystem.php | 29 +++++++- src/Repository/Vps/LicenseRepository.php | 59 ++++++++++++++++ src/TransipAPI.php | 9 ++- 8 files changed, 298 insertions(+), 4 deletions(-) create mode 100644 src/Entity/Vps/License.php create mode 100644 src/Entity/Vps/LicenseKey.php create mode 100644 src/Entity/Vps/LicenseProduct.php create mode 100644 src/Entity/Vps/Licenses.php create mode 100644 src/Repository/Vps/LicenseRepository.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b6cd95..cbe4acb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +6.6.0 +----- +* Added VPS license resource + 6.5.0 ----- * Added isLocked property to HA-IP diff --git a/src/Entity/Vps/License.php b/src/Entity/Vps/License.php new file mode 100644 index 0000000..0584ac5 --- /dev/null +++ b/src/Entity/Vps/License.php @@ -0,0 +1,88 @@ +keys = $licenseKeys; + } + + public function getId(): int + { + return $this->id; + } + + public function getName(): string + { + return $this->name; + } + + public function getPrice(): int + { + return $this->price; + } + + public function getRecurringPrice(): int + { + return $this->recurringPrice; + } + + public function getType(): string + { + return $this->type; + } + + public function getQuantity(): int + { + return $this->quantity; + } + + public function getMaxQuantity(): int + { + return $this->maxQuantity; + } + + public function getKeys(): array + { + return $this->keys; + } +} diff --git a/src/Entity/Vps/LicenseKey.php b/src/Entity/Vps/LicenseKey.php new file mode 100644 index 0000000..8c7b95d --- /dev/null +++ b/src/Entity/Vps/LicenseKey.php @@ -0,0 +1,24 @@ +name; + } + + public function getKey(): string + { + return $this->key; + } +} diff --git a/src/Entity/Vps/LicenseProduct.php b/src/Entity/Vps/LicenseProduct.php new file mode 100644 index 0000000..7b4a41c --- /dev/null +++ b/src/Entity/Vps/LicenseProduct.php @@ -0,0 +1,48 @@ +name; + } + + public function getPrice(): int + { + return $this->price; + } + + public function getRecurringPrice(): int + { + return $this->recurringPrice; + } + + public function getType(): string + { + return $this->type; + } + + public function getMaxQuantity(): int + { + return $this->maxQuantity; + } +} diff --git a/src/Entity/Vps/Licenses.php b/src/Entity/Vps/Licenses.php new file mode 100644 index 0000000..a101f4c --- /dev/null +++ b/src/Entity/Vps/Licenses.php @@ -0,0 +1,41 @@ +active; + } + + /** + * @return License[] + */ + public function getCancellable(): array + { + return $this->cancellable; + } + + /** + * @return LicenseProduct[] + */ + public function getAvailable(): array + { + return $this->available; + } +} diff --git a/src/Entity/Vps/OperatingSystem.php b/src/Entity/Vps/OperatingSystem.php index 5dde4eb..4427806 100644 --- a/src/Entity/Vps/OperatingSystem.php +++ b/src/Entity/Vps/OperatingSystem.php @@ -6,9 +6,9 @@ class OperatingSystem extends AbstractEntity { - public const INSTALL_FLAVOUR_INSTALLER = 'installer'; + public const INSTALL_FLAVOUR_INSTALLER = 'installer'; public const INSTALL_FLAVOUR_PREINSTALLABLE = 'preinstallable'; - public const INSTALL_FLAVOUR_CLOUDINIT = 'cloudinit'; + public const INSTALL_FLAVOUR_CLOUDINIT = 'cloudinit'; /** * @var string $name @@ -35,6 +35,21 @@ class OperatingSystem extends AbstractEntity */ protected $installFlavours = []; + /** + * @var LicenseProduct[] + */ + protected $licenses = []; + + public function __construct(array $valueArray = []) + { + parent::__construct($valueArray); + + $licenses = $valueArray['licenses'] ?? []; + foreach ($licenses as $license) { + $this->licenses[] = new LicenseProduct($license); + } + } + public function getName(): string { return $this->name; @@ -46,7 +61,7 @@ public function getDescription(): string } /** - * @deprecated + * @deprecated use getInstallFlavours() instead * @return bool */ public function isPreinstallableImage(): bool @@ -68,4 +83,12 @@ public function getInstallFlavours(): array { return $this->installFlavours; } + + /** + * @return LicenseProduct[] + */ + public function getLicenses(): array + { + return $this->licenses; + } } diff --git a/src/Repository/Vps/LicenseRepository.php b/src/Repository/Vps/LicenseRepository.php new file mode 100644 index 0000000..ec59976 --- /dev/null +++ b/src/Repository/Vps/LicenseRepository.php @@ -0,0 +1,59 @@ +httpClient->get($this->getResourceUrl($vpsName)); + $licencesArray = $this->getParameterFromResponse($response, 'licenses'); + + $struct = []; + foreach ($licencesArray as $licenseType => $licenses) { + foreach ($licenses as $license) { + if ($licenseType === 'available') { + $struct[$licenseType][] = new LicenseProduct($license); + continue; + } + + $struct[$licenseType][] = new License($license); + } + } + + return new Licenses($struct); + } + + public function order(string $vpsName, string $licenseName, int $quantity): void + { + $parameters = [ + 'licenseName' => $licenseName, + 'quantity' => $quantity, + ]; + + $this->httpClient->post($this->getResourceUrl($vpsName), $parameters); + } + + public function update(string $vpsName, int $licenseId, string $newLicenseName): void + { + $this->httpClient->put($this->getResourceUrl($vpsName, $licenseId), ['newLicenseName' => $newLicenseName]); + } + + public function cancel(string $vpsName, int $licenseId): void + { + $this->httpClient->delete($this->getResourceUrl($vpsName, $licenseId)); + } +} diff --git a/src/TransipAPI.php b/src/TransipAPI.php index 44528df..3623780 100644 --- a/src/TransipAPI.php +++ b/src/TransipAPI.php @@ -38,6 +38,8 @@ use Transip\Api\Library\Repository\TrafficRepository; use Transip\Api\Library\Repository\Vps\AddonRepository; use Transip\Api\Library\Repository\Vps\BackupRepository as VpsBackupRepository; +use Transip\Api\Library\Repository\Vps\License\KeyRepository; +use Transip\Api\Library\Repository\Vps\LicenseRepository; use Transip\Api\Library\Repository\Vps\MonitoringContactRepository; use Transip\Api\Library\Repository\Vps\FirewallRepository as VpsFirewallRepository; use Transip\Api\Library\Repository\Vps\IpAddressRepository as VpsIpAddressRepository; @@ -57,7 +59,7 @@ class TransipAPI { public const TRANSIP_API_ENDPOINT = "https://api.transip.nl/v6"; - public const TRANSIP_API_LIBRARY_VERSION = "6.5.0"; + public const TRANSIP_API_LIBRARY_VERSION = "6.6.0"; public const TRANSIP_API_DEMO_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImN3MiFSbDU2eDNoUnkjelM4YmdOIn0.eyJpc3MiOiJhcGkudHJhbnNpcC5ubCIsImF1ZCI6ImFwaS50cmFuc2lwLm5sIiwianRpIjoiY3cyIVJsNTZ4M2hSeSN6UzhiZ04iLCJpYXQiOjE1ODIyMDE1NTAsIm5iZiI6MTU4MjIwMTU1MCwiZXhwIjoyMTE4NzQ1NTUwLCJjaWQiOiI2MDQ0OSIsInJvIjpmYWxzZSwiZ2siOmZhbHNlLCJrdiI6dHJ1ZX0.fYBWV4O5WPXxGuWG-vcrFWqmRHBm9yp0PHiYh_oAWxWxCaZX2Rf6WJfc13AxEeZ67-lY0TA2kSaOCp0PggBb_MGj73t4cH8gdwDJzANVxkiPL1Saqiw2NgZ3IHASJnisUWNnZp8HnrhLLe5ficvb1D9WOUOItmFC2ZgfGObNhlL2y-AMNLT4X7oNgrNTGm-mespo0jD_qH9dK5_evSzS3K8o03gu6p19jxfsnIh8TIVRvNdluYC2wo4qDl5EW5BEZ8OSuJ121ncOT1oRpzXB0cVZ9e5_UVAEr9X3f26_Eomg52-PjrgcRJ_jPIUYbrlo06KjjX2h0fzMr21ZE023Gw"; /** @@ -271,6 +273,11 @@ public function vpsTCPMonitorContact(): MonitoringContactRepository return new MonitoringContactRepository($this->httpClient); } + public function vpsLicenses(): LicenseRepository + { + return new LicenseRepository($this->httpClient); + } + public function privateNetworks(): PrivateNetworkRepository { return new PrivateNetworkRepository($this->httpClient);