Skip to content
Closed
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
6 changes: 6 additions & 0 deletions doc/services/identity/v3/roles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ List role assignments

.. sample:: identity/v3/roles/list_assignments.php
.. refdoc:: OpenStack/Identity/v3/Models/Project.html#method_listRoleAssignments

Show role details
---------------------

.. sample:: identity/v3/roles/get_role.php
.. refdoc:: OpenStack/Identity/v3/Models/Project.html#method_getRole
22 changes: 22 additions & 0 deletions samples/identity/v3/roles/get_role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => [
'id' => '{userId}',
'password' => '{password}'
],
'scope' => [
'project' => [
'id' => '{projectId}'
]
]
]);

$identity = $openstack->identityV3();

$role = $identity->getRole('{id}');
$role->retrieve();
9 changes: 9 additions & 0 deletions src/Identity/v3/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,15 @@ public function getRoles(): array
];
}

public function getRole(): array
{
return [
'method' => 'GET',
'path' => 'roles/{id}',
'params' => ['id' => $this->params->idUrl('role')],
];
}

public function deleteRole(): array
{
return [
Expand Down
12 changes: 11 additions & 1 deletion src/Identity/v3/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\Retrievable;

/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Role extends OperatorResource implements Creatable, Listable, Deletable
class Role extends OperatorResource implements Creatable, Listable, Deletable, Retrievable
{
/** @var string */
public $id;
Expand Down Expand Up @@ -45,4 +46,13 @@ public function delete()
{
$this->executeWithState($this->api->deleteRole());
}

/**
* {@inheritdoc}
*/
public function retrieve()
{
$response = $this->executeWithState($this->api->getRole());
$this->populateFromResponse($response);
}
}
13 changes: 13 additions & 0 deletions src/Identity/v3/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,19 @@ public function listRoles(array $options = []): \Generator
return $this->model(Models\Role::class)->enumerate($this->api->getRoles(), $options);
}

/**
* Retrieves a role 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.
*
* @param string $id The unique ID of the role
*
* @return Models\Role
*/
public function getRole(string $id): Models\Role
{
return $this->model(Models\Role::class, ['id' => $id]);
}

/**
* Returns a generator which will yield a collection of role assignment 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
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/Identity/v3/Models/RoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ public function test_it_deletes()

$this->role->delete();
}

public function test_it_retrieves()
{
$this->setupMock('GET', 'roles/ROLE_ID', null, [], 'role');

$this->role->retrieve();
}
}
5 changes: 5 additions & 0 deletions tests/unit/Identity/v3/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,11 @@ public function test_it_lists_roles()
$this->listTest($this->createFn($this->service, 'listRoles', []), 'roles', 'Role');
}

public function test_it_gets_role()
{
$this->getTest($this->createFn($this->service, 'getRole', 'id'), 'role');
}

public function test_it_lists_role_assignments()
{
$fn = $this->createFn($this->service, 'listRoleAssignments', []);
Expand Down