From f49d8655a75f78419596da7b22e9e878ec52797c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Wed, 31 Oct 2018 18:03:18 +0000 Subject: [PATCH 1/4] Add GetRole function to Role Resource --- doc/services/identity/v3/roles.rst | 6 ++++++ samples/identity/v3/roles/get_role.php | 22 ++++++++++++++++++++++ src/Identity/v3/Api.php | 9 +++++++++ src/Identity/v3/Models/Role.php | 12 +++++++++++- src/Identity/v3/Service.php | 14 ++++++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 samples/identity/v3/roles/get_role.php 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..fe65b230 100644 --- a/src/Identity/v3/Service.php +++ b/src/Identity/v3/Service.php @@ -423,6 +423,20 @@ 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 From 095632d5da365b5b41c89284bc0cdbd9762051b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Wed, 31 Oct 2018 18:09:11 +0000 Subject: [PATCH 2/4] Fix php-cs-fixer errors --- src/Identity/v3/Service.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Identity/v3/Service.php b/src/Identity/v3/Service.php index fe65b230..a1b62d34 100644 --- a/src/Identity/v3/Service.php +++ b/src/Identity/v3/Service.php @@ -436,7 +436,6 @@ 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 From 1000631f2a4fceb9ab13ecb1ef26f21e7d3cd488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Wed, 31 Oct 2018 18:24:57 +0000 Subject: [PATCH 3/4] Add getRole Test --- tests/unit/Identity/v3/ServiceTest.php | 5 +++++ 1 file changed, 5 insertions(+) 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', []); From ed1c1a0e78d87a6c6a00b70d3c1cd75b17da9bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Wed, 31 Oct 2018 18:36:14 +0000 Subject: [PATCH 4/4] Add test to Retrieve Role --- tests/unit/Identity/v3/Models/RoleTest.php | 7 +++++++ 1 file changed, 7 insertions(+) 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(); + } }