-
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 'objectstoreTokens' into 'master'
Objectstore tokens See merge request transip/restapi-php-library!205
- Loading branch information
Showing
8 changed files
with
183 additions
and
10 deletions.
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
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
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
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,98 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity; | ||
|
||
class OpenStackToken extends AbstractEntity | ||
{ | ||
/** | ||
* @description Identifier | ||
* @example 6322872d9c7e445dbbb49c1f9ca28adc | ||
* @readonly | ||
* @type string | ||
* @var string | ||
*/ | ||
protected $tokenId; | ||
|
||
/** | ||
* User id | ||
* | ||
* @var string | ||
*/ | ||
protected $userId; | ||
|
||
/** | ||
* Project id | ||
* | ||
* @var string | ||
*/ | ||
protected $projectId; | ||
|
||
/** | ||
* Access key | ||
* | ||
* @var string | ||
*/ | ||
protected $accessKey; | ||
|
||
/** | ||
* Secret key | ||
* | ||
* @var string | ||
*/ | ||
protected $secretKey; | ||
|
||
/** | ||
* Management url | ||
* | ||
* @var string | ||
*/ | ||
protected $managementUrl; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getTokenId() | ||
{ | ||
return $this->tokenId; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUserId(): string | ||
{ | ||
return $this->userId; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getProjectId(): string | ||
{ | ||
return $this->projectId; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAccessKey(): string | ||
{ | ||
return $this->accessKey; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSecretKey(): string | ||
{ | ||
return $this->secretKey; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getManagementUrl(): string | ||
{ | ||
return $this->managementUrl; | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Repository\OpenStack; | ||
|
||
use Transip\Api\Library\Entity\OpenStackProject; | ||
use Transip\Api\Library\Entity\OpenStackToken; | ||
use Transip\Api\Library\Entity\OpenStackUser; | ||
use Transip\Api\Library\Repository\ApiRepository; | ||
|
||
class TokenRepository extends ApiRepository | ||
{ | ||
public const RESOURCE_NAME = 'tokens'; | ||
|
||
public const RESOURCE_PARAMETER_SINGULAR = 'token'; | ||
public const RESOURCE_PARAMETER_PLURAL = 'tokens'; | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
protected function getRepositoryResourceNames(): array | ||
{ | ||
return [UserRepository::RESOURCE_NAME, self::RESOURCE_NAME]; | ||
} | ||
|
||
/** | ||
* @param string $userId | ||
* @return OpenStackToken[] | ||
*/ | ||
public function getAllByUserId(string $userId): array | ||
{ | ||
$tokens = []; | ||
$response = $this->httpClient->get($this->getResourceUrl($userId)); | ||
$tokenArray = $this->getParameterFromResponse($response, self::RESOURCE_PARAMETER_PLURAL); | ||
|
||
foreach ($tokenArray as $token) { | ||
$tokens[] = new OpenStackToken($token); | ||
} | ||
|
||
return $tokens; | ||
} | ||
|
||
public function getByTokenId(string $userId, string $tokenId): OpenStackToken | ||
{ | ||
$response = $this->httpClient->get($this->getResourceUrl($userId, $tokenId)); | ||
$token = $this->getParameterFromResponse($response, self::RESOURCE_PARAMETER_SINGULAR); | ||
|
||
return new OpenStackToken($token); | ||
} | ||
|
||
public function create(string $userId, string $projectId): void | ||
{ | ||
$parameters = [ | ||
"projectId" => $projectId | ||
]; | ||
|
||
$this->httpClient->post( | ||
$this->getResourceUrl($userId), | ||
$parameters | ||
); | ||
} | ||
|
||
public function delete(string $userId, string $tokenId): void | ||
{ | ||
$this->httpClient->delete( | ||
$this->getResourceUrl($userId, $tokenId) | ||
); | ||
} | ||
} |
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