Skip to content

Commit

Permalink
Correctly implement the POST credentials method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Sven Wiltink authored and k0ka committed Dec 7, 2023
1 parent b49c6a6 commit 4cce452
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Identity/v3/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ public function postCredentials(): array
return [
'method' => 'POST',
'path' => 'credentials',
'jsonKey' => 'credential',
'params' => [
'blob' => $this->params->blob(),
'projectId' => $this->params->projectId(),
Expand All @@ -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 [
Expand Down
2 changes: 2 additions & 0 deletions src/Identity/v3/Models/Credential.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Credential extends OperatorResource implements Creatable, Updateable, Retr
'user_id' => 'userId',
];

protected $resourceKey = 'credential';

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Identity/v3/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
9 changes: 9 additions & 0 deletions src/Identity/v3/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
10 changes: 10 additions & 0 deletions src/Identity/v3/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4cce452

Please sign in to comment.