Skip to content

Commit 175e3e9

Browse files
authored
Merge pull request #16 from pkboom/master
create ssh key
2 parents f21979b + 0d16585 commit 175e3e9

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use App\Support\Configuration;
6+
use Illuminate\Console\Scheduling\Schedule;
7+
use Laravel\Forge\Forge;
8+
9+
class CreateSshKeyCommand extends ForgeCommand
10+
{
11+
protected $signature = 'ssh {environment=production}';
12+
13+
protected $description = 'Create a new ssh key on Laravel Forge';
14+
15+
public function handle(Forge $forge, Configuration $configuration)
16+
{
17+
if (! $this->ensureHasToken()) {
18+
return 1;
19+
}
20+
if (! $this->ensureHasForgeConfiguration()) {
21+
return 1;
22+
}
23+
24+
$environment = $this->argument('environment');
25+
26+
$serverId = $configuration->get($environment, 'server');
27+
28+
$name = $this->ask('What is the key name', 'macbook');
29+
$path = $this->ask('Where is the public key file', ($_SERVER['HOME'] ?? $_SERVER['USERPROFILE'] ?? __DIR__).'/.ssh/id_rsa.pub');
30+
$username = $this->ask('What is the user name', 'forge');
31+
32+
$key = file_get_contents($path);
33+
34+
$forge->createSSHKey($serverId, compact('name', 'key', 'username'));
35+
36+
$this->info('The key has been created');
37+
}
38+
}

0 commit comments

Comments
 (0)