diff --git a/doc/services/identity/v3/roles.rst b/doc/services/identity/v3/roles.rst index 27d3458c..4c6fe45c 100644 --- a/doc/services/identity/v3/roles.rst +++ b/doc/services/identity/v3/roles.rst @@ -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 \ No newline at end of file diff --git a/samples/identity/v3/roles/get_role.php b/samples/identity/v3/roles/get_role.php new file mode 100644 index 00000000..26161c6b --- /dev/null +++ b/samples/identity/v3/roles/get_role.php @@ -0,0 +1,22 @@ + '{authUrl}', + 'region' => '{region}', + 'user' => [ + 'id' => '{userId}', + 'password' => '{password}' + ], + 'scope' => [ + 'project' => [ + 'id' => '{projectId}' + ] + ] +]); + +$identity = $openstack->identityV3(); + +$role = $identity->getRole('{id}'); +$role->retrieve(); diff --git a/src/Identity/v3/Api.php b/src/Identity/v3/Api.php index 325e3ac1..af223d06 100644 --- a/src/Identity/v3/Api.php +++ b/src/Identity/v3/Api.php @@ -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 [ diff --git a/src/Identity/v3/Models/Role.php b/src/Identity/v3/Models/Role.php index d694dccf..31e9d3ef 100644 --- a/src/Identity/v3/Models/Role.php +++ b/src/Identity/v3/Models/Role.php @@ -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; @@ -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); + } } diff --git a/src/Identity/v3/Service.php b/src/Identity/v3/Service.php index 6b11a0bd..a1b62d34 100644 --- a/src/Identity/v3/Service.php +++ b/src/Identity/v3/Service.php @@ -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 diff --git a/tests/unit/Identity/v3/Models/RoleTest.php b/tests/unit/Identity/v3/Models/RoleTest.php index 7b89fbd6..66d9c051 100644 --- a/tests/unit/Identity/v3/Models/RoleTest.php +++ b/tests/unit/Identity/v3/Models/RoleTest.php @@ -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(); + } } diff --git a/tests/unit/Identity/v3/ServiceTest.php b/tests/unit/Identity/v3/ServiceTest.php index 5f9c2f4b..7bbc1890 100644 --- a/tests/unit/Identity/v3/ServiceTest.php +++ b/tests/unit/Identity/v3/ServiceTest.php @@ -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', []);