diff --git a/app/Commands/SshConfigureCommand.php b/app/Commands/SshConfigureCommand.php
index 208bd94..ae23bcc 100644
--- a/app/Commands/SshConfigureCommand.php
+++ b/app/Commands/SshConfigureCommand.php
@@ -12,7 +12,8 @@ class SshConfigureCommand extends Command
protected $signature = 'ssh:configure
{server? : The server name}
{--key= : The path to the public key}
- {--name= : The key name on Forge}';
+ {--name= : The key name on Forge}
+ {--user= : The server username}';
/**
* The description of the command.
@@ -38,7 +39,7 @@ public function handle()
$key = $this->getKey();
- $privateKey = $this->ensureKeyExists($this->getKeyName($key), $key);
+ $privateKey = $this->ensureKeyExists($this->getKeyName($key), $key, $this->getServerUsername());
$this->callSilently('ssh:test', ['--key' => $privateKey]);
@@ -50,9 +51,10 @@ public function handle()
*
* @param string $name
* @param string|null $key
+ * @param string $username
* @return string
*/
- protected function ensureKeyExists($name, $key = null)
+ protected function ensureKeyExists($name, $key = null, $username = 'forge')
{
$server = $this->currentServer();
@@ -66,7 +68,7 @@ protected function ensureKeyExists($name, $key = null)
$this->step('Adding Key ['.$localName.']'.' With The Name ['.$name.'] To Server ['.$server->name.']');
- $this->forge->createSSHKey($server->id, ['key' => $key, 'name' => $name], true);
+ $this->forge->createSSHKey($server->id, ['key' => $key, 'name' => $name, 'username' => $username], true);
return $this->keys->keysPath().'/'.basename($localName, '.pub');
}
@@ -111,4 +113,16 @@ protected function getKeyName($key)
return $this->option('name') ?: $this->askStep($question, get_current_user());
}
-}
+
+ /**
+ * Prompt for a "server user".
+ *
+ * @return string
+ */
+ protected function getServerUsername()
+ {
+ $question = 'What username should we use for the selected server';
+
+ return $this->option('user') ?: $this->askStep($question, 'forge');
+ }
+}
\ No newline at end of file
diff --git a/tests/Feature/SshConfigureCommandTest.php b/tests/Feature/SshConfigureCommandTest.php
index b110771..e96abb4 100644
--- a/tests/Feature/SshConfigureCommandTest.php
+++ b/tests/Feature/SshConfigureCommandTest.php
@@ -32,6 +32,7 @@
$this->forge->shouldReceive('createSSHKey')->with(1, [
'name' => 'driesvints',
'key' => 'MY KEY Content',
+ 'username' => 'morales2k',
], true)->once();
$this->remote->shouldReceive('resolvePrivateKeyUsing')->once();
@@ -41,6 +42,7 @@
->expectsQuestion('‣> Which Server Would You Like To Configure The SSH Key Based Secure Authentication>', 1)
->expectsQuestion('‣> Which Key Would You Like To Use>', 0)
->expectsQuestion('‣> What Should The SSH Key Be Named>', 'driesvints')
+ ->expectsQuestion('‣> What Username Should We Use For The Selected Server>', 'morales2k')
->expectsOutput('==> Creating Key [driesvints_rsa.pub]')
->expectsOutput('==> Adding Key [driesvints_rsa.pub] With The Name [driesvints] To Server [production]')
->expectsOutput('==> SSH Key Based Secure Authentication Configured Successfully');
@@ -78,6 +80,7 @@
$this->forge->shouldReceive('createSSHKey')->with(2, [
'name' => 'driesvints',
'key' => 'MY KEY Content',
+ 'username' => 'morales2k',
], true)->once();
$this->remote->shouldReceive('resolvePrivateKeyUsing')->once();
@@ -86,6 +89,7 @@
$this->artisan('ssh:configure', ['server' => 2])
->expectsQuestion('‣> Which Key Would You Like To Use>', 1)
->expectsQuestion('‣> What Should The SSH Key Be Named In Forge>', 'driesvints')
+ ->expectsQuestion('‣> What Username Should We Use For The Selected Server>', 'morales2k')
->expectsOutput('==> Adding Key [id_rsa.pub] With The Name [driesvints] To Server [production]')
->expectsOutput('==> SSH Key Based Secure Authentication Configured Successfully');
-});
+});
\ No newline at end of file