Skip to content

Commit bd75c3e

Browse files
committed
Add support for 2FA and increase deploy timeout
1 parent b0cc4f8 commit bd75c3e

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

app/Commands/DeployCommand.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
namespace App\Commands;
44

55
use App\Support\Configuration;
6+
use Carbon\CarbonInterval;
67
use Illuminate\Console\Scheduling\Schedule;
78
use Laravel\Forge\Forge;
89
use LaravelZero\Framework\Commands\Command;
910

1011
class DeployCommand extends ForgeCommand
1112
{
12-
protected $signature = 'deploy {environment=production} {--update-script}';
13+
protected $signature = 'deploy {environment=production} {--update-script} {--no-wait}';
1314

1415
protected $description = 'Deploy the current project to Forge';
1516

1617
public function handle(Forge $forge, Configuration $configuration)
1718
{
18-
if (! $this->ensureHasToken()) {
19+
if (!$this->ensureHasToken()) {
1920
return 1;
2021
}
21-
if (! $this->ensureHasForgeConfiguration()) {
22+
if (!$this->ensureHasForgeConfiguration()) {
2223
return 1;
2324
}
2425

@@ -39,16 +40,20 @@ public function handle(Forge $forge, Configuration $configuration)
3940

4041
$forge->deploySite($serverId, $siteId);
4142

42-
$forge->retry($forge->timeout, function () use ($serverId, $siteId, $forge) {
43-
$site = $forge->site($serverId, $siteId);
43+
if (!$this->option('no-wait')) {
44+
$forge->retry(CarbonInterval::minutes(10)->totalSeconds, function () use ($serverId, $siteId, $forge) {
45+
$site = $forge->site($serverId, $siteId);
4446

45-
return is_null($site->deploymentStatus);
46-
}, 5);
47+
return is_null($site->deploymentStatus);
48+
}, 5);
49+
}
4750

4851
$this->info('The site has been deployed');
4952

50-
$this->call('deploy:log', [
51-
'environment' => $environment,
52-
]);
53+
if (!$this->option('no-wait')) {
54+
$this->call('deploy:log', [
55+
'environment' => $environment,
56+
]);
57+
}
5358
}
5459
}

app/Commands/LoginCommand.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
class LoginCommand extends Command
1818
{
1919
const LOGIN_URL = 'https://forge.laravel.com/auth/login';
20+
const TWO_FACTOR_AUTH_URL = 'https://forge.laravel.com/auth/token';
2021

2122
const TOKEN_URL = 'https://forge.laravel.com/oauth/personal-access-tokens';
2223

@@ -59,7 +60,17 @@ protected function login($email, $password)
5960

6061
$uri = $browser->getHistory()->current()->getUri();
6162

62-
if ($uri === static::LOGIN_URL) {
63+
if ($uri === static::TWO_FACTOR_AUTH_URL) {
64+
$token = $this->ask('What is your 2FA token?');
65+
66+
$browser->submitForm('Verify', [
67+
'token' => $token,
68+
]);
69+
70+
$uri = $browser->getHistory()->current()->getUri();
71+
}
72+
73+
if ($uri === static::LOGIN_URL || $uri === static::TWO_FACTOR_AUTH_URL) {
6374
$this->error('Invalid credentials.');
6475
exit();
6576
}

builds/forge

121 Bytes
Binary file not shown.

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
|
2727
*/
2828

29-
'version' => '1.0.5',
29+
'version' => '1.1.0',
3030

3131
/*
3232
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)