Обновление клиента (apps, 3rdparty, install)

This commit is contained in:
root
2026-03-16 08:42:57 +00:00
parent b8905de237
commit f390426546
3354 changed files with 505213 additions and 3 deletions
@@ -0,0 +1,69 @@
<?php
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class ApplicationCredential extends OperatorResource implements Creatable, Listable, Retrievable, Deletable
{
/** @var string */
public $id;
/** @var string */
public $userId;
/** @var string */
public $name;
/** @var string */
public $description;
/** @var string|null */
public $secret = null;
protected $aliases = [
'user_id' => 'userId',
];
protected $resourceKey = 'application_credential';
protected $resourcesKey = 'application_credentials';
/**
* {@inheritdoc}
*
* @param array $userOptions {@see \OpenStack\Identity\v3\Api::postApplicationCredential}
*/
public function create(array $userOptions): Creatable
{
$response = $this->execute($this->api->postApplicationCredential(), $userOptions);
return $this->populateFromResponse($response);
}
/**
* {@inheritdoc}
*/
public function retrieve()
{
$response = $this->execute(
$this->api->getApplicationCredential(),
['id' => $this->id, 'userId' => $this->userId]
);
$this->populateFromResponse($response);
}
/**
* {@inheritdoc}
*/
public function delete()
{
$this->executeWithState($this->api->deleteApplicationCredential());
}
}
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Alias;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
class Assignment extends OperatorResource implements Listable
{
/** @var Role */
public $role;
/** @var array */
public $scope;
/** @var Group */
public $group;
/** @var User */
public $user;
protected $resourcesKey = 'role_assignments';
protected $resourceKey = 'role_assignment';
protected function getAliases(): array
{
return parent::getAliases() + [
'role' => new Alias('role', Role::class),
'user' => new Alias('user', User::class),
'group' => new Alias('group', Group::class),
];
}
}
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Alias;
use OpenStack\Common\Resource\OperatorResource;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Catalog extends OperatorResource implements \OpenStack\Common\Auth\Catalog
{
/** @var []Service */
public $services;
protected function getAliases(): array
{
return parent::getAliases() + [
'services' => new Alias('services', Service::class, true),
];
}
public function populateFromArray(array $data): self
{
foreach ($data as $service) {
$this->services[] = $this->model(Service::class, $service);
}
return $this;
}
/**
* Retrieve a base URL for a service, according to its catalog name, type, region.
*
* @param string $name the name of the service as it appears in the catalog
* @param string $type the type of the service as it appears in the catalog
* @param string $region the region of the service as it appears in the catalog
* @param string $urlType unused
*
* @return false|string FALSE if no URL found
*/
public function getServiceUrl(string $name, string $type, string $region, string $urlType): string
{
if (empty($this->services)) {
throw new \RuntimeException('No services are defined');
}
foreach ($this->services as $service) {
if (false !== ($url = $service->getUrl($name, $type, $region, $urlType))) {
return $url;
}
}
throw new \RuntimeException(sprintf("Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s", $name, $type, $region, $urlType));
}
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Resource\Updateable;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Credential extends OperatorResource implements Creatable, Updateable, Retrievable, Listable, Deletable
{
/** @var string */
public $blob;
/** @var string */
public $id;
/** @var array */
public $links;
/** @var string */
public $projectId;
/** @var string */
public $type;
/** @var string */
public $userId;
protected $aliases = [
'project_id' => 'projectId',
'user_id' => 'userId',
];
public function create(array $userOptions): Creatable
{
$response = $this->execute($this->api->postCredentials(), $userOptions);
return $this->populateFromResponse($response);
}
public function retrieve()
{
$response = $this->executeWithState($this->api->getCredential());
$this->populateFromResponse($response);
}
public function update()
{
$response = $this->executeWithState($this->api->patchCredential());
$this->populateFromResponse($response);
}
public function delete()
{
$this->executeWithState($this->api->deleteCredential());
}
}
@@ -0,0 +1,148 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Resource\Updateable;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Domain extends OperatorResource implements Creatable, Listable, Retrievable, Updateable, Deletable
{
/** @var string */
public $id;
/** @var string */
public $name;
/** @var array */
public $links;
/** @var bool */
public $enabled;
/** @var string */
public $description;
protected $resourceKey = 'domain';
protected $resourcesKey = 'domains';
/**
* @param array $data {@see \OpenStack\Identity\v3\Api::postDomains}
*/
public function create(array $data): Creatable
{
$response = $this->execute($this->api->postDomains(), $data);
return $this->populateFromResponse($response);
}
public function retrieve()
{
$response = $this->executeWithState($this->api->getDomain());
$this->populateFromResponse($response);
}
public function update()
{
$response = $this->executeWithState($this->api->patchDomain());
$this->populateFromResponse($response);
}
public function delete()
{
$this->executeWithState($this->api->deleteDomain());
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::getUserRoles}
*
* @return \Generator<mixed, \OpenStack\Identity\v3\Models\Role>
*/
public function listUserRoles(array $options = []): \Generator
{
$options['domainId'] = $this->id;
return $this->model(Role::class)->enumerate($this->api->getUserRoles(), $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::putUserRoles}
*/
public function grantUserRole(array $options = [])
{
$this->execute($this->api->putUserRoles(), ['domainId' => $this->id] + $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::headUserRole}
*/
public function checkUserRole(array $options = []): bool
{
try {
$this->execute($this->api->headUserRole(), ['domainId' => $this->id] + $options);
return true;
} catch (BadResponseError $e) {
return false;
}
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::deleteUserRole}
*/
public function revokeUserRole(array $options = [])
{
$this->execute($this->api->deleteUserRole(), ['domainId' => $this->id] + $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::getGroupRoles}
*
* @return \Generator<mixed, \OpenStack\Identity\v3\Models\Role>
*/
public function listGroupRoles(array $options = []): \Generator
{
$options['domainId'] = $this->id;
return $this->model(Role::class)->enumerate($this->api->getGroupRoles(), $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::putGroupRole}
*/
public function grantGroupRole(array $options = [])
{
$this->execute($this->api->putGroupRole(), ['domainId' => $this->id] + $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::headGroupRole}
*/
public function checkGroupRole(array $options = []): bool
{
try {
$this->execute($this->api->headGroupRole(), ['domainId' => $this->id] + $options);
return true;
} catch (BadResponseError $e) {
return false;
}
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::deleteGroupRole}
*/
public function revokeGroupRole(array $options = [])
{
$this->execute($this->api->deleteGroupRole(), ['domainId' => $this->id] + $options);
}
}
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Resource\Updateable;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Endpoint extends OperatorResource implements Creatable, Updateable, Deletable, Retrievable
{
/** @var string */
public $id;
/** @var string */
public $interface;
/** @var string */
public $name;
/** @var string */
public $serviceId;
/** @var string */
public $region;
/** @var array */
public $links;
/** @var string */
public $url;
protected $resourceKey = 'endpoint';
protected $resourcesKey = 'endpoints';
protected $aliases = ['service_id' => 'serviceId'];
/**
* @param array $data {@see \OpenStack\Identity\v3\Api::postEndpoints}
*/
public function create(array $data): Creatable
{
$response = $this->execute($this->api->postEndpoints(), $data);
return $this->populateFromResponse($response);
}
public function retrieve()
{
$response = $this->executeWithState($this->api->getEndpoint());
$this->populateFromResponse($response);
}
public function update()
{
$response = $this->executeWithState($this->api->patchEndpoint());
$this->populateFromResponse($response);
}
public function delete()
{
$this->execute($this->api->deleteEndpoint(), $this->getAttrs(['id']));
}
public function regionMatches(string $value): bool
{
return in_array($this->region, ['*', $value]);
}
public function interfaceMatches(string $value): bool
{
return $this->interface && $this->interface == $value;
}
}
@@ -0,0 +1,108 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Resource\Updateable;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Group extends OperatorResource implements Creatable, Listable, Retrievable, Updateable, Deletable
{
/** @var string */
public $domainId;
/** @var string */
public $id;
/** @var string */
public $description;
/** @var array */
public $links;
/** @var string */
public $name;
protected $aliases = ['domain_id' => 'domainId'];
protected $resourceKey = 'group';
protected $resourcesKey = 'groups';
/**
* @param array $data {@see \OpenStack\Identity\v3\Api::postGroups}
*/
public function create(array $data): Creatable
{
$response = $this->execute($this->api->postGroups(), $data);
return $this->populateFromResponse($response);
}
public function retrieve()
{
$response = $this->execute($this->api->getGroup(), ['id' => $this->id]);
$this->populateFromResponse($response);
}
public function update()
{
$response = $this->executeWithState($this->api->patchGroup());
$this->populateFromResponse($response);
}
public function delete()
{
$this->execute($this->api->deleteGroup(), ['id' => $this->id]);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::getGroupUsers}
*
* @return \Generator<mixed, \OpenStack\Identity\v3\Models\User>
*/
public function listUsers(array $options = []): \Generator
{
$options['id'] = $this->id;
return $this->model(User::class)->enumerate($this->api->getGroupUsers(), $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::putGroupUser}
*/
public function addUser(array $options)
{
$this->execute($this->api->putGroupUser(), ['groupId' => $this->id] + $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::deleteGroupUser}
*/
public function removeUser(array $options)
{
$this->execute($this->api->deleteGroupUser(), ['groupId' => $this->id] + $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::headGroupUser}
*/
public function checkMembership(array $options): bool
{
try {
$this->execute($this->api->headGroupUser(), ['groupId' => $this->id] + $options);
return true;
} catch (BadResponseError $e) {
return false;
}
}
}
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Resource\Updateable;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Policy extends OperatorResource implements Creatable, Listable, Retrievable, Updateable, Deletable
{
/** @var string */
public $blob;
/** @var string */
public $id;
/** @var array */
public $links;
/** @var string */
public $projectId;
/** @var string */
public $type;
/** @var string */
public $userId;
protected $resourceKey = 'policy';
protected $resourcesKey = 'policies';
protected $aliases = [
'project_id' => 'projectId',
'user_id' => 'userId',
];
/**
* @param array $data {@see \OpenStack\Identity\v3\Api::postPolicies}
*/
public function create(array $data): Creatable
{
$response = $this->execute($this->api->postPolicies(), $data);
return $this->populateFromResponse($response);
}
public function retrieve()
{
$response = $this->execute($this->api->getPolicy(), ['id' => $this->id]);
$this->populateFromResponse($response);
}
public function update()
{
$response = $this->executeWithState($this->api->patchPolicy());
$this->populateFromResponse($response);
}
public function delete()
{
$this->execute($this->api->deletePolicy(), ['id' => $this->id]);
}
}
@@ -0,0 +1,160 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Resource\Updateable;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Project extends OperatorResource implements Creatable, Retrievable, Listable, Updateable, Deletable
{
/** @var string */
public $domainId;
/** @var string */
public $parentId;
/** @var bool */
public $enabled;
/** @var string */
public $description;
/** @var string */
public $id;
/** @var array */
public $links;
/** @var string */
public $name;
protected $aliases = [
'domain_id' => 'domainId',
'parent_id' => 'parentId',
];
protected $resourceKey = 'project';
protected $resourcesKey = 'projects';
/**
* @param array $data {@see \OpenStack\Identity\v3\Api::postProjects}
*/
public function create(array $data): Creatable
{
$response = $this->execute($this->api->postProjects(), $data);
$this->populateFromResponse($response);
return $this;
}
public function retrieve()
{
$response = $this->executeWithState($this->api->getProject());
$this->populateFromResponse($response);
}
public function update()
{
$response = $this->executeWithState($this->api->patchProject());
$this->populateFromResponse($response);
}
public function delete()
{
$this->executeWithState($this->api->deleteProject());
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::getProjectUserRoles}
*
* @return \Generator<mixed, \OpenStack\Identity\v3\Models\Role>
*/
public function listUserRoles(array $options = []): \Generator
{
$options['projectId'] = $this->id;
return $this->model(Role::class)->enumerate($this->api->getProjectUserRoles(), $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::putProjectUserRole}
*/
public function grantUserRole(array $options)
{
$this->execute($this->api->putProjectUserRole(), ['projectId' => $this->id] + $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::headProjectUserRole}
*/
public function checkUserRole(array $options): bool
{
try {
$this->execute($this->api->headProjectUserRole(), ['projectId' => $this->id] + $options);
return true;
} catch (BadResponseError $e) {
return false;
}
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::deleteProjectUserRole}
*/
public function revokeUserRole(array $options)
{
$this->execute($this->api->deleteProjectUserRole(), ['projectId' => $this->id] + $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::getProjectGroupRoles}
*
* @return \Generator<mixed, \OpenStack\Identity\v3\Models\Role>
*/
public function listGroupRoles(array $options = []): \Generator
{
$options['projectId'] = $this->id;
return $this->model(Role::class)->enumerate($this->api->getProjectGroupRoles(), $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::putProjectGroupRole}
*/
public function grantGroupRole(array $options)
{
$this->execute($this->api->putProjectGroupRole(), ['projectId' => $this->id] + $options);
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::headProjectGroupRole}
*/
public function checkGroupRole(array $options): bool
{
try {
$this->execute($this->api->headProjectGroupRole(), ['projectId' => $this->id] + $options);
return true;
} catch (BadResponseError $e) {
return false;
}
}
/**
* @param array $options {@see \OpenStack\Identity\v3\Api::deleteProjectGroupRole}
*/
public function revokeGroupRole(array $options)
{
$this->execute($this->api->deleteProjectGroupRole(), ['projectId' => $this->id] + $options);
}
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Role extends OperatorResource implements Creatable, Listable, Deletable
{
/** @var string */
public $id;
/** @var string */
public $name;
/** @var array */
public $links;
protected $resourceKey = 'role';
protected $resourcesKey = 'roles';
/**
* @param array $data {@see \OpenStack\Identity\v3\Api::postRoles}
*/
public function create(array $data): Creatable
{
$response = $this->execute($this->api->postRoles(), $data);
return $this->populateFromResponse($response);
}
public function delete()
{
$this->executeWithState($this->api->deleteRole());
}
}
@@ -0,0 +1,109 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Alias;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Resource\Updateable;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Service extends OperatorResource implements Creatable, Listable, Retrievable, Updateable, Deletable
{
/** @var string */
public $id;
/** @var string */
public $name;
/** @var string */
public $type;
/** @var string */
public $description;
/** @var []Endpoint */
public $endpoints;
/** @var array */
public $links;
protected $resourceKey = 'service';
protected $resourcesKey = 'services';
protected function getAliases(): array
{
return parent::getAliases() + [
'endpoints' => new Alias('endpoints', Endpoint::class, true),
];
}
/**
* @param array $data {@see \OpenStack\Identity\v3\Api::postServices}
*/
public function create(array $data): Creatable
{
$response = $this->execute($this->api->postServices(), $data);
return $this->populateFromResponse($response);
}
public function retrieve()
{
$response = $this->executeWithState($this->api->getService());
$this->populateFromResponse($response);
}
public function update()
{
$response = $this->executeWithState($this->api->patchService());
$this->populateFromResponse($response);
}
public function delete()
{
$this->executeWithState($this->api->deleteService());
}
private function nameMatches(string $value): bool
{
return $this->name && $this->name == $value;
}
private function typeMatches(string $value): bool
{
return $this->type && $this->type == $value;
}
/**
* Retrieve the base URL for a service.
*
* @param string $name the name of the service as it appears in the catalog
* @param string $type the type of the service as it appears in the catalog
* @param string $region the region of the service as it appears in the catalog
* @param string $interface the interface of the service as it appears in the catalog
*
* @return string|false
*/
public function getUrl(string $name, string $type, string $region, string $interface)
{
if (!$this->nameMatches($name) || !$this->typeMatches($type)) {
return false;
}
foreach ($this->endpoints as $endpoint) {
if ($endpoint->regionMatches($region) && $endpoint->interfaceMatches($interface)) {
return $endpoint->url;
}
}
return false;
}
}
@@ -0,0 +1,150 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use InvalidArgumentException;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Resource\Alias;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Transport\Utils;
use Psr\Http\Message\ResponseInterface;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Token extends OperatorResource implements Creatable, Retrievable, \OpenStack\Common\Auth\Token
{
/** @var array */
public $methods;
/** @var Role[] */
public $roles;
/** @var \DateTimeImmutable */
public $expires;
/** @var Project */
public $project;
/** @var Catalog */
public $catalog;
public $extras;
/** @var User */
public $user;
/** @var \DateTimeImmutable */
public $issued;
/** @var string */
public $id;
protected $resourceKey = 'token';
protected $resourcesKey = 'tokens';
protected $cachedToken;
protected function getAliases(): array
{
return parent::getAliases() + [
'roles' => new Alias('roles', Role::class, true),
'expires_at' => new Alias('expires', \DateTimeImmutable::class),
'project' => new Alias('project', Project::class),
'catalog' => new Alias('catalog', Catalog::class),
'user' => new Alias('user', User::class),
'issued_at' => new Alias('issued', \DateTimeImmutable::class),
];
}
public function populateFromResponse(ResponseInterface $response)
{
parent::populateFromResponse($response);
$this->id = $response->getHeaderLine('X-Subject-Token');
return $this;
}
public function getId(): string
{
return $this->id;
}
/**
* @return bool TRUE if the token has expired (and is invalid); FALSE otherwise
*/
public function hasExpired(): bool
{
return $this->expires <= new \DateTimeImmutable('now', $this->expires->getTimezone());
}
public function retrieve()
{
$response = $this->execute($this->api->getTokens(), ['tokenId' => $this->id]);
$this->populateFromResponse($response);
}
/**
* @param array $userOptions {@see \OpenStack\Identity\v3\Api::postTokens}
*/
public function create(array $userOptions): Creatable
{
if (isset($userOptions['user'])) {
$userOptions['methods'] = ['password'];
if (!isset($userOptions['user']['id']) && empty($userOptions['user']['domain'])) {
throw new InvalidArgumentException('When authenticating with a username, you must also provide either the domain name '.'or domain ID to which the user belongs to. Alternatively, if you provide a user ID instead, '.'you do not need to provide domain information.');
}
} elseif (isset($userOptions['application_credential'])) {
$userOptions['methods'] = ['application_credential'];
if (!isset($userOptions['application_credential']['id']) || !isset($userOptions['application_credential']['secret'])) {
throw new InvalidArgumentException('When authenticating with a application_credential, you must provide application credential ID '.' and application credential secret.');
}
} elseif (isset($userOptions['tokenId'])) {
$userOptions['methods'] = ['token'];
} else {
throw new InvalidArgumentException('Either a user, tokenId or application_credential must be provided.');
}
$response = $this->execute($this->api->postTokens(), $userOptions);
$token = $this->populateFromResponse($response);
// Cache response as an array to export if needed.
// Added key `id` which is auth token from HTTP header X-Subject-Token
$this->cachedToken = Utils::flattenJson(Utils::jsonDecode($response), $this->resourceKey);
$this->cachedToken['id'] = $token->id;
return $token;
}
/**
* Returns a serialized representation of an authentication token.
*
* Initialize OpenStack object using $params['cachedToken'] to reduce the amount of HTTP calls.
*
* This array is a modified version of response from `/auth/tokens`. Do not manually modify this array.
*/
public function export(): array
{
return $this->cachedToken;
}
/**
* Checks if the token is valid.
*
* @return bool TRUE if the token is valid; FALSE otherwise
*/
public function validate(): bool
{
try {
$this->execute($this->api->headTokens(), ['tokenId' => $this->id]);
return true;
} catch (BadResponseError $e) {
return false;
}
}
}
@@ -0,0 +1,113 @@
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Resource\Updateable;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class User extends OperatorResource implements Creatable, Listable, Retrievable, Updateable, Deletable
{
/** @var string */
public $domainId;
/** @var string */
public $defaultProjectId;
/** @var string */
public $id;
/** @var string */
public $email;
/** @var bool */
public $enabled;
/** @var string */
public $description;
/** @var array */
public $links;
/** @var string */
public $name;
protected $aliases = [
'domain_id' => 'domainId',
'default_project_id' => 'defaultProjectId',
];
protected $resourceKey = 'user';
protected $resourcesKey = 'users';
/**
* @param array $data {@see \OpenStack\Identity\v3\Api::postUsers}
*/
public function create(array $data): Creatable
{
$response = $this->execute($this->api->postUsers(), $data);
return $this->populateFromResponse($response);
}
public function retrieve()
{
$response = $this->execute($this->api->getUser(), ['id' => $this->id]);
$this->populateFromResponse($response);
}
public function update()
{
$response = $this->executeWithState($this->api->patchUser());
$this->populateFromResponse($response);
}
public function delete()
{
$this->execute($this->api->deleteUser(), ['id' => $this->id]);
}
/**
* @return \Generator<mixed, \OpenStack\Identity\v3\Models\Group>
*/
public function listGroups(): \Generator
{
return $this->model(Group::class)->enumerate($this->api->getUserGroups(), ['id' => $this->id]);
}
/**
* @return \Generator<mixed, \OpenStack\Identity\v3\Models\Project>
*/
public function listProjects(): \Generator
{
return $this->model(Project::class)->enumerate($this->api->getUserProjects(), ['id' => $this->id]);
}
/**
* Creates a new application credential according to the provided options.
*
* @param array $options {@see \OpenStack\Identity\v3\Api::postApplicationCredential}
*/
public function createApplicationCredential(array $options): ApplicationCredential
{
return $this->model(ApplicationCredential::class)->create(['userId' => $this->id] + $options);
}
/**
* Retrieves an application credential object and populates its unique identifier object. This operation will not
* perform a GET or HEAD request by default; you will need to call retrieve() if you want to pull in remote state
* from the API.
*/
public function getApplicationCredential(string $id): ApplicationCredential
{
return $this->model(ApplicationCredential::class, ['id' => $id, 'userId' => $this->id]);
}
}