-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'openstack' into 'master'
Add support for the OpenStack product See merge request transip/restapi-php-library!156
- Loading branch information
Showing
8 changed files
with
409 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
composer.lock | ||
ci/deploy_to_github.sh | ||
src/TransipAPI.php | ||
src/Entity/OpenStackProject.php | ||
src/Entity/OpenStackUser.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity; | ||
|
||
class OpenStackProject extends AbstractEntity | ||
{ | ||
/** | ||
* @description Identifier | ||
* @example `7a7a3bcb46c6450f95c53edb8dcebc7b` | ||
* @type string | ||
* @readonly | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @description Name of the project | ||
* @example `hosting101-datacenter` | ||
* @type string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* @description Describes this project | ||
* @example This is an example project | ||
* @type string | ||
*/ | ||
protected $description; | ||
|
||
/** | ||
* @description When an ongoing process blocks the project from being modified, this is set to `true` | ||
* @example false | ||
* @type boolean | ||
* @readonly | ||
*/ | ||
protected $isLocked; | ||
|
||
/** | ||
* @description Set to `true` when a project has been administratively blocked | ||
* @example false | ||
* @type boolean | ||
* @readonly | ||
*/ | ||
protected $isBlocked; | ||
|
||
public function getId(): string | ||
{ | ||
return $this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity; | ||
|
||
class OpenStackUser extends AbstractEntity | ||
{ | ||
/** | ||
* @description Identifier | ||
* @example 6322872d9c7e445dbbb49c1f9ca28adc | ||
* @readonly | ||
* @type string | ||
* @var string | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @description Login name | ||
* @example `hosting101-support` | ||
* @readonly | ||
* @type string | ||
*/ | ||
protected $username; | ||
|
||
/** | ||
* @description Description | ||
* @example `Supporter account` | ||
* @type string | ||
*/ | ||
protected $description; | ||
|
||
/** | ||
* @description Email address | ||
* @example `[email protected]` | ||
* @type string | ||
*/ | ||
protected $email; | ||
|
||
public function getId(): string | ||
{ | ||
return $this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Repository\OpenStack\Project; | ||
|
||
use Transip\Api\Library\Entity\OpenStackUser; | ||
use Transip\Api\Library\Repository\ApiRepository; | ||
use Transip\Api\Library\Repository\OpenStack\ProjectRepository; | ||
|
||
class UserRepository extends ApiRepository | ||
{ | ||
public const RESOURCE_NAME = 'users'; | ||
|
||
public const RESOURCE_PARAMETER_PLURAL = 'users'; | ||
|
||
protected function getRepositoryResourceNames(): array | ||
{ | ||
return [ProjectRepository::RESOURCE_NAME, self::RESOURCE_NAME]; | ||
} | ||
|
||
/** | ||
* @param string $projectId | ||
* @return OpenStackUser[] | ||
*/ | ||
public function getByProjectId(string $projectId): array | ||
{ | ||
$users = []; | ||
$response = $this->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) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Repository\OpenStack; | ||
|
||
use Transip\Api\Library\Entity\OpenStackProject; | ||
use Transip\Api\Library\Repository\ApiRepository; | ||
|
||
class ProjectRepository extends ApiRepository | ||
{ | ||
public const RESOURCE_NAME = 'openstack/projects'; | ||
|
||
public const RESOURCE_PARAMETER_SINGUlAR = 'project'; | ||
public const RESOURCE_PARAMETER_PLURAL = 'projects'; | ||
|
||
protected function getRepositoryResourceNames(): array | ||
{ | ||
return [self::RESOURCE_NAME]; | ||
} | ||
|
||
/** | ||
* @return OpenStackProject[] | ||
*/ | ||
public function getAll(): array | ||
{ | ||
$projects = []; | ||
$response = $this->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) | ||
); | ||
} | ||
} |
Oops, something went wrong.