Skip to content

Commit

Permalink
Merge branch 'objectstoreTokens' into 'master'
Browse files Browse the repository at this point in the history
Objectstore tokens

See merge request transip/restapi-php-library!205
  • Loading branch information
roeldijkstra committed Sep 6, 2022
2 parents 5486681 + 9d1633a commit e6546e3
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ test phpunit:
expire_in: 1 day
reports:
junit: build/logs/junit.xml
cobertura: build/cobertura.xml

validate tag-message:
stage: validate
Expand Down
1 change: 1 addition & 0 deletions .secretsignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ ci/deploy_to_github.sh
src/TransipAPI.php
src/Entity/OpenStackProject.php
src/Entity/OpenStackUser.php
src/Entity/OpenStackToken.php
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
CHANGELOG
=========
6.28.0
-----
* Implemented Object Store functionality
* Added token endpoint to Openstack

6.27.1
-----
* Fixed action on ssl reissue
Expand Down
1 change: 0 additions & 1 deletion examples/GetBigStorageUsageStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
);

foreach ($usageStatistics as $statistic) {

// Convert unix timestamp to human readable date
$date = new DateTime("@{$statistic->getDate()}");

Expand Down
1 change: 0 additions & 1 deletion examples/Vps/Backup/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

$backupId = 0;
foreach ($backups as $backup) {

// An example search
if ($backup->getOperatingSystem() === 'OpenBSD 6.4') {
$backupId = $backup->getId();
Expand Down
98 changes: 98 additions & 0 deletions src/Entity/OpenStackToken.php
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;
}
}
68 changes: 68 additions & 0 deletions src/Repository/OpenStack/TokenRepository.php
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)
);
}
}
18 changes: 11 additions & 7 deletions src/TransipAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Transip\Api\Library\HttpClient\Builder\ClientBuilder;
use Transip\Api\Library\HttpClient\GuzzleClient;
use Transip\Api\Library\HttpClient\HttpClient;
use Transip\Api\Library\HttpClient\HttpClientInterface;
use Transip\Api\Library\HttpClient\HttpMethodsClient;
use Transip\Api\Library\Repository\ApiTestRepository;
use Transip\Api\Library\Repository\AuthRepository;
use Transip\Api\Library\Repository\AvailabilityZoneRepository;
Expand Down Expand Up @@ -40,6 +38,7 @@
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\TokenRepository as OpenStackTokenRepository;
use Transip\Api\Library\Repository\OpenStack\UserRepository as OpenStackUserRepository;
use Transip\Api\Library\Repository\OpenStack\Project\UserRepository as OpenStackProjectUserRepository;
use Transip\Api\Library\Repository\OperatingSystemFilterRepository;
Expand Down Expand Up @@ -79,7 +78,7 @@
class TransipAPI
{
public const TRANSIP_API_ENDPOINT = "https://api.transip.nl/v6";
public const TRANSIP_API_LIBRARY_VERSION = "6.27.1";
public const TRANSIP_API_LIBRARY_VERSION = "6.28.0";
public const TRANSIP_API_DEMO_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImN3MiFSbDU2eDNoUnkjelM4YmdOIn0.eyJpc3MiOiJhcGkudHJhbnNpcC5ubCIsImF1ZCI6ImFwaS50cmFuc2lwLm5sIiwianRpIjoiY3cyIVJsNTZ4M2hSeSN6UzhiZ04iLCJpYXQiOjE1ODIyMDE1NTAsIm5iZiI6MTU4MjIwMTU1MCwiZXhwIjoyMTE4NzQ1NTUwLCJjaWQiOiI2MDQ0OSIsInJvIjpmYWxzZSwiZ2siOmZhbHNlLCJrdiI6dHJ1ZX0.fYBWV4O5WPXxGuWG-vcrFWqmRHBm9yp0PHiYh_oAWxWxCaZX2Rf6WJfc13AxEeZ67-lY0TA2kSaOCp0PggBb_MGj73t4cH8gdwDJzANVxkiPL1Saqiw2NgZ3IHASJnisUWNnZp8HnrhLLe5ficvb1D9WOUOItmFC2ZgfGObNhlL2y-AMNLT4X7oNgrNTGm-mespo0jD_qH9dK5_evSzS3K8o03gu6p19jxfsnIh8TIVRvNdluYC2wo4qDl5EW5BEZ8OSuJ121ncOT1oRpzXB0cVZ9e5_UVAEr9X3f26_Eomg52-PjrgcRJ_jPIUYbrlo06KjjX2h0fzMr21ZE023Gw";

/**
Expand Down Expand Up @@ -174,14 +173,14 @@ public function sslCertificateUninstall(): UninstallRepository
return new UninstallRepository($this->httpClient);
}

public function sslCertificateDownload(): DownloadRepository
public function invoice(): InvoiceRepository
{
return new DownloadRepository($this->httpClient);
return new InvoiceRepository($this->httpClient);
}

public function invoice(): InvoiceRepository
public function sslCertificateDownload(): DownloadRepository
{
return new InvoiceRepository($this->httpClient);
return new DownloadRepository($this->httpClient);
}

public function invoicePdf(): InvoicePdfRepository
Expand Down Expand Up @@ -437,6 +436,11 @@ public function openStackUsers(): OpenStackUserRepository
return new OpenStackUserRepository($this->httpClient);
}

public function openStackTokens(): OpenStackTokenRepository
{
return new OpenStackTokenRepository($this->httpClient);
}

public function mailForwards(): MailForwardRepository
{
return new MailForwardRepository($this->httpClient);
Expand Down

0 comments on commit e6546e3

Please sign in to comment.