diff --git a/.secretsignore b/.secretsignore index 3ee961a..f06e33a 100644 --- a/.secretsignore +++ b/.secretsignore @@ -1,3 +1,5 @@ composer.lock ci/deploy_to_github.sh src/TransipAPI.php +src/Entity/OpenStackProject.php +src/Entity/OpenStackUser.php diff --git a/CHANGELOG.md b/CHANGELOG.md index d0cd3fb..f73b697 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +6.12.0 +----- +* Added OpenStack resource + 6.11.0 ----- * Added destination big storage name for backup restore diff --git a/src/Entity/OpenStackProject.php b/src/Entity/OpenStackProject.php new file mode 100644 index 0000000..79de39d --- /dev/null +++ b/src/Entity/OpenStackProject.php @@ -0,0 +1,85 @@ +id; + } + + public function getName(): string + { + return $this->name; + } + + public function getDescription(): string + { + return $this->description; + } + + public function isLocked(): bool + { + return $this->isLocked; + } + + public function isBlocked(): bool + { + return $this->isBlocked; + } + + /** + * @param string $name + */ + public function setName(string $name): void + { + $this->name = $name; + } + + /** + * @param string $description + */ + public function setDescription(string $description): void + { + $this->description = $description; + } +} diff --git a/src/Entity/OpenStackUser.php b/src/Entity/OpenStackUser.php new file mode 100644 index 0000000..dafc553 --- /dev/null +++ b/src/Entity/OpenStackUser.php @@ -0,0 +1,67 @@ +id; + } + + public function getUsername(): string + { + return $this->username; + } + + public function getDescription(): string + { + return $this->description; + } + + public function getEmail(): string + { + return $this->email; + } + + public function setDescription(string $description): void + { + $this->description = $description; + } + + public function setEmail(string $email): void + { + $this->email = $email; + } +} diff --git a/src/Repository/OpenStack/Project/UserRepository.php b/src/Repository/OpenStack/Project/UserRepository.php new file mode 100644 index 0000000..7cbc36f --- /dev/null +++ b/src/Repository/OpenStack/Project/UserRepository.php @@ -0,0 +1,51 @@ +httpClient->get($this->getResourceUrl($projectId)); + $usersArray = $this->getParameterFromResponse($response, self::RESOURCE_PARAMETER_PLURAL); + + foreach ($usersArray as $userArray) { + $users[] = new OpenStackUser($userArray); + } + + return $users; + } + + public function grantUserAccessToProject(string $projectId, string $userId): void + { + $url = $this->getResourceUrl($projectId); + $parameters = ['userId' => $userId]; + + $this->httpClient->post($url, $parameters); + } + + public function revokeUserAccessFromProject(string $projectId, string $userId): void + { + $this->httpClient->delete( + $this->getResourceUrl($projectId, $userId) + ); + } +} diff --git a/src/Repository/OpenStack/ProjectRepository.php b/src/Repository/OpenStack/ProjectRepository.php new file mode 100644 index 0000000..d791d21 --- /dev/null +++ b/src/Repository/OpenStack/ProjectRepository.php @@ -0,0 +1,88 @@ +httpClient->get($this->getResourceUrl()); + $projectsArray = $this->getParameterFromResponse($response, self::RESOURCE_PARAMETER_PLURAL); + + foreach ($projectsArray as $projectArray) { + $projects[] = new OpenStackProject($projectArray); + } + + return $projects; + } + + public function create(string $name, string $description): void + { + $parameters = [ + 'name' => $name, + 'description' => $description, + ]; + + $this->httpClient->post( + $this->getResourceUrl(), + $parameters + ); + } + + public function getByProjectId(string $projectId): OpenStackProject + { + $response = $this->httpClient->get($this->getResourceUrl($projectId)); + $projectArray = $this->getParameterFromResponse($response, self::RESOURCE_PARAMETER_SINGUlAR); + + return new OpenStackProject($projectArray); + } + + public function updateProject(OpenStackProject $project): void + { + $parameters = [ + 'project' => $project, + ]; + + $this->httpClient->put( + $this->getResourceUrl($project->getId()), + $parameters + ); + } + + public function handover(string $projectID, string $targetCustomerName): void + { + $parameters = [ + 'action' => 'handover', + 'targetCustomerName' => $targetCustomerName, + ]; + + $this->httpClient->patch( + $this->getResourceUrl($projectID), + $parameters + ); + } + + public function cancel(string $projectID): void + { + $this->httpClient->delete( + $this->getResourceUrl($projectID) + ); + } +} diff --git a/src/Repository/OpenStack/UserRepository.php b/src/Repository/OpenStack/UserRepository.php new file mode 100644 index 0000000..dcf89fd --- /dev/null +++ b/src/Repository/OpenStack/UserRepository.php @@ -0,0 +1,92 @@ +httpClient->get($this->getResourceUrl()); + $usersArray = $this->getParameterFromResponse($response, self::RESOURCE_PARAMETER_PLURAL); + + foreach ($usersArray as $userArray) { + $users[] = new OpenStackUser($userArray); + } + + return $users; + } + + public function getByUserId(string $userId): OpenStackUser + { + $response = $this->httpClient->get($this->getResourceUrl($userId)); + $userArray = $this->getParameterFromResponse($response, self::RESOURCE_PARAMETER_SINGUlAR); + + return new OpenStackUser($userArray); + } + + public function create( + string $username, + string $description, + string $email, + string $password, + string $projectId + ): void { + $parameters = [ + 'username' => $username, + 'description' => $description, + 'email' => $email, + 'password' => $password, + 'projectId' => $projectId, + ]; + + $this->httpClient->post($this->getResourceUrl(), $parameters); + } + + public function delete(string $userId): void + { + $this->httpClient->delete( + $this->getResourceUrl($userId) + ); + } + + public function updatePassword(string $userId, string $password): void + { + $parameters = [ + 'newPassword' => $password + ]; + + $this->httpClient->patch( + $this->getResourceUrl($userId), + $parameters + ); + } + + public function updateUser(OpenStackUser $openStackUser): void + { + $parameters = [ + 'user' => $openStackUser + ]; + + $this->httpClient->put( + $this->getResourceUrl($openStackUser->getId()), + $parameters + ); + } +} diff --git a/src/TransipAPI.php b/src/TransipAPI.php index cb5d078..186d6ee 100644 --- a/src/TransipAPI.php +++ b/src/TransipAPI.php @@ -7,6 +7,7 @@ use Transip\Api\Library\HttpClient\GuzzleClient; use Transip\Api\Library\HttpClient\HttpClient; use Transip\Api\Library\HttpClient\HttpClientInterface; +use Transip\Api\Library\Repository\ApiRepository; use Transip\Api\Library\Repository\ApiTestRepository; use Transip\Api\Library\Repository\AuthRepository; use Transip\Api\Library\Repository\AvailabilityZoneRepository; @@ -31,6 +32,9 @@ use Transip\Api\Library\Repository\Invoice\ItemRepository as InvoiceItemRepository; use Transip\Api\Library\Repository\Invoice\PdfRepository as InvoicePdfRepository; use Transip\Api\Library\Repository\MailServiceRepository; +use Transip\Api\Library\Repository\OpenStack\ProjectRepository as OpenStackProjectRepository; +use Transip\Api\Library\Repository\OpenStack\UserRepository as OpenStackUserRepository; +use Transip\Api\Library\Repository\OpenStack\Project\UserRepository as OpenStackProjectUserRepository; use Transip\Api\Library\Repository\PrivateNetworkRepository; use Transip\Api\Library\Repository\ProductRepository; use Transip\Api\Library\Repository\Product\ElementRepository as ProductElementRepository; @@ -60,7 +64,7 @@ class TransipAPI { public const TRANSIP_API_ENDPOINT = "https://api.transip.nl/v6"; - public const TRANSIP_API_LIBRARY_VERSION = "6.11.0"; + public const TRANSIP_API_LIBRARY_VERSION = "6.12.0"; public const TRANSIP_API_DEMO_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImN3MiFSbDU2eDNoUnkjelM4YmdOIn0.eyJpc3MiOiJhcGkudHJhbnNpcC5ubCIsImF1ZCI6ImFwaS50cmFuc2lwLm5sIiwianRpIjoiY3cyIVJsNTZ4M2hSeSN6UzhiZ04iLCJpYXQiOjE1ODIyMDE1NTAsIm5iZiI6MTU4MjIwMTU1MCwiZXhwIjoyMTE4NzQ1NTUwLCJjaWQiOiI2MDQ0OSIsInJvIjpmYWxzZSwiZ2siOmZhbHNlLCJrdiI6dHJ1ZX0.fYBWV4O5WPXxGuWG-vcrFWqmRHBm9yp0PHiYh_oAWxWxCaZX2Rf6WJfc13AxEeZ67-lY0TA2kSaOCp0PggBb_MGj73t4cH8gdwDJzANVxkiPL1Saqiw2NgZ3IHASJnisUWNnZp8HnrhLLe5ficvb1D9WOUOItmFC2ZgfGObNhlL2y-AMNLT4X7oNgrNTGm-mespo0jD_qH9dK5_evSzS3K8o03gu6p19jxfsnIh8TIVRvNdluYC2wo4qDl5EW5BEZ8OSuJ121ncOT1oRpzXB0cVZ9e5_UVAEr9X3f26_Eomg52-PjrgcRJ_jPIUYbrlo06KjjX2h0fzMr21ZE023Gw"; /** @@ -353,6 +357,21 @@ public function colocationRemoteHands(): ColoRemoteHandsRepository return new ColoRemoteHandsRepository($this->httpClient); } + public function openStackProjects(): OpenStackProjectRepository + { + return new OpenStackProjectRepository($this->httpClient); + } + + public function openStackProjectUsers(): OpenStackProjectUserRepository + { + return new OpenStackProjectUserRepository($this->httpClient); + } + + public function openStackUsers(): OpenStackUserRepository + { + return new OpenStackUserRepository($this->httpClient); + } + public function test(): ApiTestRepository { return new ApiTestRepository($this->httpClient);