Skip to content

Commit c51346d

Browse files
Sven Wiltinksvenwiltink
authored andcommitted
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.
1 parent 42e2d09 commit c51346d

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

src/Identity/v3/Api.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ public function postCredentials(): array
691691
return [
692692
'method' => 'POST',
693693
'path' => 'credentials',
694+
'jsonKey' => 'credential',
694695
'params' => [
695696
'blob' => $this->params->blob(),
696697
'projectId' => $this->params->projectId(),
@@ -709,6 +710,15 @@ public function getCredentials(): array
709710
];
710711
}
711712

713+
public function getUserCredentials(): array
714+
{
715+
return [
716+
'method' => 'GET',
717+
'path' => 'credentials',
718+
'params' => ['userId' => $this->params->userIdQueryUnderscore()],
719+
];
720+
}
721+
712722
public function getCredential(): array
713723
{
714724
return [

src/Identity/v3/Models/Credential.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class Credential extends OperatorResource implements Creatable, Updateable, Retr
3939
'user_id' => 'userId',
4040
];
4141

42+
protected $resourceKey = 'credential';
43+
4244
/**
4345
* {@inheritdoc}
4446
*/

src/Identity/v3/Models/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,9 @@ public function listProjects(): \Generator
9797
{
9898
return $this->model(Project::class)->enumerate($this->api->getUserProjects(), ['id' => $this->id]);
9999
}
100+
101+
public function listCredentials(): \Generator
102+
{
103+
return $this->model(Credential::class)->enumerate($this->api->getUserCredentials(), ['userId' => $this->id]);
104+
}
100105
}

src/Identity/v3/Params.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ public function userIdQuery(): array
195195
];
196196
}
197197

198+
public function userIdQueryUnderscore(): array
199+
{
200+
return [
201+
'sentAs' => 'user_id',
202+
'location' => 'query',
203+
'description' => 'Filter by user ID',
204+
];
205+
}
206+
198207
public function domain(): array
199208
{
200209
return [

src/Identity/v3/Service.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ public function listCredentials(): \Generator
330330
return $this->model(Models\Credential::class)->enumerate($this->api->getCredentials());
331331
}
332332

333+
/**
334+
* Returns a generator which will yield a collection of credential objects. The elements which generators yield can
335+
* be accessed using a foreach loop. Often the API will not return the full state of the resource in collections;
336+
* you will need to use retrieve() to pull in the full state of the remote resource from the API.
337+
*/
338+
public function listUserCredentials(array $options): \Generator
339+
{
340+
return $this->model(Models\Credential::class)->enumerate($this->api->getUserCredentials(), $options);
341+
}
342+
333343
/**
334344
* Retrieves a credential object and populates its unique identifier object. This operation will not perform a GET
335345
* or HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API.

0 commit comments

Comments
 (0)