From 4cce45258948c35ae622f282dadca326e6551271 Mon Sep 17 00:00:00 2001 From: Sven Wiltink Date: Tue, 5 Jul 2022 14:38:45 +0200 Subject: [PATCH] Correctly implement the POST credentials method https://docs.openstack.org/api-ref/identity/v3/index.html?expanded=authenticating-with-an-application-credential-detail,create-credential-detail#credentials specifies that the credentials endpoint expects a credential object and returns one. This patch ensures the data is properly encoded and decoded. --- src/Identity/v3/Api.php | 10 ++++++++++ src/Identity/v3/Models/Credential.php | 2 ++ src/Identity/v3/Models/User.php | 5 +++++ src/Identity/v3/Params.php | 9 +++++++++ src/Identity/v3/Service.php | 10 ++++++++++ 5 files changed, 36 insertions(+) diff --git a/src/Identity/v3/Api.php b/src/Identity/v3/Api.php index 325e3ac17..1079d3d87 100644 --- a/src/Identity/v3/Api.php +++ b/src/Identity/v3/Api.php @@ -691,6 +691,7 @@ public function postCredentials(): array return [ 'method' => 'POST', 'path' => 'credentials', + 'jsonKey' => 'credential', 'params' => [ 'blob' => $this->params->blob(), 'projectId' => $this->params->projectId(), @@ -709,6 +710,15 @@ public function getCredentials(): array ]; } + public function getUserCredentials(): array + { + return [ + 'method' => 'GET', + 'path' => 'credentials', + 'params' => ['userId' => $this->params->userIdQueryUnderscore()], + ]; + } + public function getCredential(): array { return [ diff --git a/src/Identity/v3/Models/Credential.php b/src/Identity/v3/Models/Credential.php index ab844b3e4..ccfaa4f6c 100644 --- a/src/Identity/v3/Models/Credential.php +++ b/src/Identity/v3/Models/Credential.php @@ -39,6 +39,8 @@ class Credential extends OperatorResource implements Creatable, Updateable, Retr 'user_id' => 'userId', ]; + protected $resourceKey = 'credential'; + /** * {@inheritdoc} */ diff --git a/src/Identity/v3/Models/User.php b/src/Identity/v3/Models/User.php index 81aa561e6..a4e87a0f0 100644 --- a/src/Identity/v3/Models/User.php +++ b/src/Identity/v3/Models/User.php @@ -97,4 +97,9 @@ public function listProjects(): \Generator { return $this->model(Project::class)->enumerate($this->api->getUserProjects(), ['id' => $this->id]); } + + public function listCredentials(): \Generator + { + return $this->model(Credential::class)->enumerate($this->api->getUserCredentials(), ['userId' => $this->id]); + } } diff --git a/src/Identity/v3/Params.php b/src/Identity/v3/Params.php index f001d3c48..b649c9aa0 100644 --- a/src/Identity/v3/Params.php +++ b/src/Identity/v3/Params.php @@ -195,6 +195,15 @@ public function userIdQuery(): array ]; } + public function userIdQueryUnderscore(): array + { + return [ + 'sentAs' => 'user_id', + 'location' => 'query', + 'description' => 'Filter by user ID', + ]; + } + public function domain(): array { return [ diff --git a/src/Identity/v3/Service.php b/src/Identity/v3/Service.php index ca16aac59..cbca4395f 100644 --- a/src/Identity/v3/Service.php +++ b/src/Identity/v3/Service.php @@ -330,6 +330,16 @@ public function listCredentials(): \Generator return $this->model(Models\Credential::class)->enumerate($this->api->getCredentials()); } + /** + * Returns a generator which will yield a collection of credential objects. The elements which generators yield can + * be accessed using a foreach loop. Often the API will not return the full state of the resource in collections; + * you will need to use retrieve() to pull in the full state of the remote resource from the API. + */ + public function listUserCredentials(array $options): \Generator + { + return $this->model(Models\Credential::class)->enumerate($this->api->getUserCredentials(), $options); + } + /** * Retrieves a 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.