Skip to content

Commit cf0c530

Browse files
Configure Command Test (#10)
* Finally write a happy path test for the configure command. #8 & #9 * Apply fixes from StyleCI
1 parent 9c2d332 commit cf0c530

File tree

7 files changed

+351
-17
lines changed

7 files changed

+351
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

33

4+
## 0.1.2 - 2021-05-24
5+
6+
- Fix other `sidecar:configure` AWS errors. ([#8](https://github.com/hammerstonedev/sidecar/issues/8) & ([#9](https://github.com/hammerstonedev/sidecar/issues/9))
7+
48
## 0.1.1 - 2021-05-24
59

610
- Fix undefined `choice` ([#7](https://github.com/hammerstonedev/sidecar/issues/7))

src/Commands/Actions/CreateBucket.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Aws\S3\S3Client;
99
use Illuminate\Support\Str;
10+
use Throwable;
1011

1112
class CreateBucket extends BaseAction
1213
{
@@ -27,7 +28,7 @@ public function invoke()
2728
{
2829
$this->client = $this->command->client(S3Client::class);
2930

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

3233
$this->ensureBucketIsPrefixed();
3334

src/Commands/Actions/CreateDeploymentUser.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Hammerstone\Sidecar\Commands\Actions;
77

88
use Aws\Iam\IamClient;
9+
use Illuminate\Support\Arr;
10+
use Throwable;
911

1012
class CreateDeploymentUser extends BaseAction
1113
{
@@ -113,7 +115,7 @@ protected function issueCredentials()
113115
'UserName' => 'sidecar-deployment-user',
114116
]);
115117

116-
if (!$keys->count()) {
118+
if (!count($keys)) {
117119
return $this->createAccessKey();
118120
}
119121

@@ -149,8 +151,8 @@ protected function createAccessKey()
149151
]);
150152

151153
return [
152-
'key' => $result->search('AccessKey.AccessKeyId'),
153-
'secret' => $result->search('AccessKey.SecretAccessKey'),
154+
'key' => Arr::get($result, 'AccessKey.AccessKeyId'),
155+
'secret' => Arr::get($result, 'AccessKey.SecretAccessKey'),
154156
];
155157
}
156158
}

src/Commands/Actions/CreateExecutionRole.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Hammerstone\Sidecar\Commands\Actions;
77

88
use Aws\Iam\IamClient;
9+
use Illuminate\Support\Arr;
10+
use Throwable;
911

1012
class CreateExecutionRole extends BaseAction
1113
{
@@ -20,7 +22,7 @@ public function invoke()
2022

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

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

2527
$this->attachPolicy();
2628

src/Commands/Actions/DestroyAdminKeys.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@
66
namespace Hammerstone\Sidecar\Commands\Actions;
77

88
use Aws\Iam\IamClient;
9+
use Throwable;
910

1011
class DestroyAdminKeys extends BaseAction
1112
{
12-
public function invoke($key)
13+
public $key;
14+
15+
public function setKey($key)
16+
{
17+
$this->key = $key;
18+
19+
return $this;
20+
}
21+
22+
public function invoke()
1323
{
1424
$client = $this->command->client(IamClient::class);
1525

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

28-
if (!$this->confirm($question, $default = true)) {
38+
if (!$this->command->confirm($question, $default = true)) {
2939
return;
3040
}
3141

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

3444
try {
3545
$client->deleteAccessKey([
36-
'AccessKeyId' => $key,
46+
'AccessKeyId' => $this->key,
3747
'UserName' => $name,
3848
]);
3949
} catch (Throwable $e) {

src/Commands/Configure.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function handle()
6464

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

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

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

8585
public function client($class)
8686
{
87-
return new $class([
88-
'region' => $this->region,
89-
'version' => 'latest',
90-
'credentials' => [
91-
'key' => $this->key,
92-
'secret' => $this->secret
87+
return app()->make($class, [
88+
'args' => [
89+
'region' => $this->region,
90+
'version' => 'latest',
91+
'credentials' => [
92+
'key' => $this->key,
93+
'secret' => $this->secret
94+
]
9395
]
9496
]);
9597
}

0 commit comments

Comments
 (0)