Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly implement the POST credentials method #348

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not need to create a new definition there. We already have getCredentials() and can just reuse it by adding the userId parameter.

{
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 @@ -103,4 +103,9 @@ public function listProjects(): \Generator
{
return $this->model(Project::class)->enumerate($this->api->getUserProjects(), ['id' => $this->id]);
}

public function listCredentials(): \Generator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return \Generator<mixed, \OpenStack\Identity\v3\Models\Credential>

{
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why creating new function?
As far as I see https://docs.openstack.org/api-ref/identity/v3/#credentials
POST /v3/credentials and GET /v3/credentials are using the same parameter type user_id.

{
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 @@ -338,6 +338,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.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return \Generator<mixed, \OpenStack\Identity\v3\Models\Credential>

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
Loading