-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathConfigure.php
More file actions
130 lines (107 loc) · 4.25 KB
/
Configure.php
File metadata and controls
130 lines (107 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
declare(strict_types=1);
/**
* @author Aaron Francis <aaron@hammerstone.dev>
*/
namespace Hammerstone\Sidecar\Commands;
use Exception;
use Hammerstone\Sidecar\Commands\Actions\CreateBucket;
use Hammerstone\Sidecar\Commands\Actions\CreateDeploymentUser;
use Hammerstone\Sidecar\Commands\Actions\CreateExecutionRole;
use Hammerstone\Sidecar\Commands\Actions\DestroyAdminKeys;
use Hammerstone\Sidecar\Commands\Actions\DetermineRegion;
use Illuminate\Console\Command;
use Throwable;
class Configure extends Command
{
protected $signature = 'sidecar:configure';
protected $description = 'Interactively configure your Sidecar AWS environment variables';
protected ?string $key = null;
protected ?string $secret = null;
protected ?string $region = null;
protected int $width = 75;
/**
* @throws Exception
* @throws Throwable
*/
public function handle()
{
$this->askForAdminCredentials();
$this->region = $this->action(DetermineRegion::class)->invoke();
$bucket = $this->action(CreateBucket::class)->invoke();
$role = $this->action(CreateExecutionRole::class)->invoke();
$credentials = $this->action(CreateDeploymentUser::class)->invoke();
$this->action(DestroyAdminKeys::class)->setKey($this->key)->invoke();
$this->line(' ');
$this->info('Done! Here are your environment variables:');
$this->line('SIDECAR_ACCESS_KEY_ID=' . $credentials['key']);
$this->line('SIDECAR_SECRET_ACCESS_KEY=' . $credentials['secret']);
$this->line('SIDECAR_REGION=' . $this->region);
$this->line('SIDECAR_ARTIFACT_BUCKET_NAME=' . $bucket);
$this->line('SIDECAR_EXECUTION_ROLE=' . $role);
$this->line(' ');
$this->info('They will work in any environment.');
}
public function text($text)
{
$this->line(wordwrap($text, $this->width));
}
public function client($class)
{
return app()->make($class, [
'args' => [
'region' => $this->region,
'version' => 'latest',
'credentials' => [
'key' => $this->key,
'secret' => $this->secret,
],
],
]);
}
protected function action($class)
{
return app()->make($class, [
'region' => $this->region,
'command' => $this,
]);
}
protected function askForAdminCredentials()
{
$this->line(str_repeat('-', $this->width));
$this->text('This interactive command will help you set up your Sidecar credentials for all your environments.');
$this->line('');
$this->text('To start, Sidecar needs a set of AWS Credentials with Administrator Access.');
$this->line('');
$this->text('We will only use these for this session, then they will be forgotten.');
$this->line('');
$this->text('Visit this link: https://console.aws.amazon.com/iam/home#/users');
$this->text(' --> Click "Create user"');
$this->text(' ');
$this->text(' --> Enter "sidecar-cli-helper" as the name.');
$this->text(' --> Click "Next"');
$this->text(' ');
$this->text(' --> Choose "Attach policies directly"');
$this->text(' --> Select "AdministratorAccess"');
$this->text(' ');
$this->text(' --> Click "Next"');
$this->text(' ');
$this->text(' --> Click "Create user"');
$this->text(' ');
$this->text(' --> Navigate to the "sidecar-cli-helper" user.');
$this->text(' --> Click "Security Credentials."');
$this->text(' --> Scroll down to "Access keys" and click "Create access key"');
$this->text(' --> Select "Application running outside AWS"');
$this->text(' --> Click "Next"');
$this->text(' ');
$this->text(' --> Click "Create access key"');
$this->line(str_repeat('-', $this->width));
$this->key = $this->ask('Enter the Access key');
$this->secret = $this->secret('Enter the Secret access key');
if ($this->key && $this->secret) {
$this->text('Got it! We will start creating resources now...');
} else {
throw new Exception('Key or secret not entered.');
}
}
}