Skip to content

Commit

Permalink
Configure Command Test (#10)
Browse files Browse the repository at this point in the history
* Finally write a happy path test for the configure command. #8 & #9
* Apply fixes from StyleCI
  • Loading branch information
aarondfrancis authored May 24, 2021
1 parent 9c2d332 commit cf0c530
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


## 0.1.2 - 2021-05-24

- Fix other `sidecar:configure` AWS errors. ([#8](https://github.com/hammerstonedev/sidecar/issues/8) & ([#9](https://github.com/hammerstonedev/sidecar/issues/9))

## 0.1.1 - 2021-05-24

- Fix undefined `choice` ([#7](https://github.com/hammerstonedev/sidecar/issues/7))
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/Actions/CreateBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Aws\S3\S3Client;
use Illuminate\Support\Str;
use Throwable;

class CreateBucket extends BaseAction
{
Expand All @@ -27,7 +28,7 @@ public function invoke()
{
$this->client = $this->command->client(S3Client::class);

$this->bucket = config('sidecar.aws_bucket', $this->defaultBucketName());
$this->bucket = config('sidecar.aws_bucket') ?? $this->defaultBucketName();

$this->ensureBucketIsPrefixed();

Expand Down
8 changes: 5 additions & 3 deletions src/Commands/Actions/CreateDeploymentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Hammerstone\Sidecar\Commands\Actions;

use Aws\Iam\IamClient;
use Illuminate\Support\Arr;
use Throwable;

class CreateDeploymentUser extends BaseAction
{
Expand Down Expand Up @@ -113,7 +115,7 @@ protected function issueCredentials()
'UserName' => 'sidecar-deployment-user',
]);

if (!$keys->count()) {
if (!count($keys)) {
return $this->createAccessKey();
}

Expand Down Expand Up @@ -149,8 +151,8 @@ protected function createAccessKey()
]);

return [
'key' => $result->search('AccessKey.AccessKeyId'),
'secret' => $result->search('AccessKey.SecretAccessKey'),
'key' => Arr::get($result, 'AccessKey.AccessKeyId'),
'secret' => Arr::get($result, 'AccessKey.SecretAccessKey'),
];
}
}
4 changes: 3 additions & 1 deletion src/Commands/Actions/CreateExecutionRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Hammerstone\Sidecar\Commands\Actions;

use Aws\Iam\IamClient;
use Illuminate\Support\Arr;
use Throwable;

class CreateExecutionRole extends BaseAction
{
Expand All @@ -20,7 +22,7 @@ public function invoke()

$this->client = $this->command->client(IamClient::class);

$role = $this->findOrCreateRole()->search('Role.Arn');
$role = Arr::get($this->findOrCreateRole(), 'Role.Arn');

$this->attachPolicy();

Expand Down
16 changes: 13 additions & 3 deletions src/Commands/Actions/DestroyAdminKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@
namespace Hammerstone\Sidecar\Commands\Actions;

use Aws\Iam\IamClient;
use Throwable;

class DestroyAdminKeys extends BaseAction
{
public function invoke($key)
public $key;

public function setKey($key)
{
$this->key = $key;

return $this;
}

public function invoke()
{
$client = $this->command->client(IamClient::class);

Expand All @@ -25,15 +35,15 @@ public function invoke($key)
"Now that everything is setup, would you like to remove the admin access keys for user `$name` from AWS? \n" .
' Sidecar no longer needs them.';

if (!$this->confirm($question, $default = true)) {
if (!$this->command->confirm($question, $default = true)) {
return;
}

$this->progress('Deleting admin keys...');

try {
$client->deleteAccessKey([
'AccessKeyId' => $key,
'AccessKeyId' => $this->key,
'UserName' => $name,
]);
} catch (Throwable $e) {
Expand Down
16 changes: 9 additions & 7 deletions src/Commands/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function handle()

$credentials = $this->action(CreateDeploymentUser::class)->invoke();

$this->action(DestroyAdminKeys::class)->invoke($this->key);
$this->action(DestroyAdminKeys::class)->setKey($this->key)->invoke();

$this->line(' ');
$this->info('Done! Here are your environment variables:');
Expand All @@ -84,12 +84,14 @@ public function text($text)

public function client($class)
{
return new $class([
'region' => $this->region,
'version' => 'latest',
'credentials' => [
'key' => $this->key,
'secret' => $this->secret
return app()->make($class, [
'args' => [
'region' => $this->region,
'version' => 'latest',
'credentials' => [
'key' => $this->key,
'secret' => $this->secret
]
]
]);
}
Expand Down
Loading

0 comments on commit cf0c530

Please sign in to comment.