Skip to content
Merged
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
2 changes: 1 addition & 1 deletion samples/Identity/v3/credentials/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@

$identity = $openstack->identityV3();

$credential = $identity->getCredential('credentialId');
$credential = $identity->getCredential('{credentialId}');
$credential->delete();
14 changes: 8 additions & 6 deletions src/Identity/v3/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,10 @@ public function headGroupUser(): array
public function postCredentials(): array
{
return [
'method' => 'POST',
'path' => 'credentials',
'params' => [
'method' => 'POST',
'path' => 'credentials',
'jsonKey' => 'credential',
'params' => [
'blob' => $this->params->blob(),
'projectId' => $this->params->projectId(),
'type' => $this->params->type('credential'),
Expand Down Expand Up @@ -724,9 +725,10 @@ public function getCredential(): array
public function patchCredential(): array
{
return [
'method' => 'PATCH',
'path' => 'credentials/{id}',
'params' => ['id' => $this->params->idUrl('credential')] + $this->postCredentials()['params'],
'method' => 'PATCH',
'path' => 'credentials/{id}',
'jsonKey' => 'credential',
'params' => ['id' => $this->params->idUrl('credential')] + $this->postCredentials()['params'],
];
}

Expand Down
3 changes: 3 additions & 0 deletions src/Identity/v3/Models/Credential.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Credential extends OperatorResource implements Creatable, Updateable, Retr
'user_id' => 'userId',
];

protected $resourceKey = 'credential';
protected $resourcesKey = 'credentials';

public function create(array $userOptions): Creatable
{
$response = $this->execute($this->api->postCredentials(), $userOptions);
Expand Down
107 changes: 107 additions & 0 deletions tests/sample/Identity/v3/CredentialTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace OpenStack\Sample\Identity\v3;

use OpenStack\Common\Error\BadResponseError;
use OpenStack\Identity\v3\Models\Credential;

class CredentialTest extends TestCase
{
public function testCreate(): Credential
{
/** @var $credential \OpenStack\Identity\v3\Models\Role */
require_once $this->sampleFile('credentials/create.php', [
'{blob}' => '{"access":"181920","secret":"secretKey"}',
'{type}' => 'ec2',
]);
$this->assertInstanceOf(Credential::class, $credential);

return $credential;
}

/**
* @depends testCreate
*/
public function testList(Credential $createdCredential): void
{
$found = false;
require_once $this->sampleFile(
'credentials/list.php',
[
'/** @var $credential \OpenStack\Identity\v3\Models\Credential */' => <<<'PHP'
/** @var $credential \OpenStack\Identity\v3\Models\Credential */
if ($credential->id === $createdCredential->id) {
$found = true;
}
PHP
,
]
);

$this->assertTrue($found);
}

/**
* @depends testCreate
*/
public function testRead(Credential $createdCredential)
{
/** @var $credential \OpenStack\Identity\v3\Models\Credential */
require_once $this->sampleFile(
'credentials/read.php',
['{credentialId}' => $createdCredential->id]
);

$this->assertInstanceOf(Credential::class, $credential);
$this->assertEquals($createdCredential->blob, $credential->blob);
$this->assertEquals($createdCredential->type, $credential->type);
}

/**
* @depends testCreate
*/
public function testUpdate(Credential $createdCredential)
{
$newBlob = '{"access":"181920","secret":"newSecretKey"}';

/** @var $credential \OpenStack\Identity\v3\Models\Credential */
require_once $this->sampleFile(
'credentials/update.php',
[
'{credentialId}' => $createdCredential->id,
'{blob}' => $newBlob,
'{type}' => 'ec3',
]
);

$this->assertInstanceOf(Credential::class, $credential);
$this->assertEquals($newBlob, $credential->blob);
$this->assertEquals('ec3', $credential->type);
}


/**
* @depends testCreate
*/
public function testDelete(Credential $createdCredential): void
{
require_once $this->sampleFile(
'credentials/delete.php',
[
'{credentialId}' => $createdCredential->id,
]
);

$found = false;
foreach ($this->getService()->listCredentials() as $credential) {
if ($credential->id === $createdCredential->id) {
$found = true;
}
}

$this->assertFalse($found);

$this->expectException(BadResponseError::class);
$createdCredential->retrieve();
}
}
6 changes: 3 additions & 3 deletions tests/sample/Identity/v3/RoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class RoleTest extends TestCase
{
public function testCeate(): Role
public function testCreate(): Role
{
/** @var $role \OpenStack\Identity\v3\Models\Role */
require_once $this->sampleFile('roles/create.php', ['{name}' => $this->randomStr()]);
Expand All @@ -16,7 +16,7 @@ public function testCeate(): Role
}

/**
* @depends testCeate
* @depends testCreate
*/
public function testList(Role $createdRole): void
{
Expand All @@ -38,7 +38,7 @@ public function testList(Role $createdRole): void
}

/**
* @depends testCeate
* @depends testCreate
*/
public function testListAssignments(Role $createdRole): void
{
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/Identity/v3/Models/CredentialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public function test_it_updates()
$this->credential->projectId = 'bar';

$expectedJson = [
'type' => 'foo',
'project_id' => 'bar',
'credential' => [
'type' => 'foo',
'project_id' => 'bar',
]
];

$this->mockRequest('PATCH', 'credentials/CRED_ID', 'cred', $expectedJson, []);
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/Identity/v3/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,16 @@ public function test_it_creates_credential()
'blob' => "{\"access\":\"--access-key--\",\"secret\":\"--secret-key--\"}",
'projectId' => 'project_id',
'type' => 'ec2',
'userId' => 'user_id'
'userId' => 'user_id',
];

$userJson = [
'blob' => $userOptions['blob'],
'project_id' => $userOptions['projectId'],
'type' => $userOptions['type'],
'user_id' => $userOptions['userId'],
'credential' => [
'blob' => $userOptions['blob'],
'project_id' => $userOptions['projectId'],
'type' => $userOptions['type'],
'user_id' => $userOptions['userId'],
],
];

$this->mockRequest('POST', 'credentials', 'cred', $userJson);
Expand Down
Loading