diff --git a/src/Server/Builder.php b/src/Server/Builder.php index b9405b5a..15f71940 100644 --- a/src/Server/Builder.php +++ b/src/Server/Builder.php @@ -80,6 +80,17 @@ class Builder $this->config->setPemFile($pemFile); return $this; } + + /** + * Using forward agent to authentication + * + * @return \Deployer\Server\Builder + */ + public function forwardAgent() + { + $this->config->setAuthenticationMethod(Configuration::AUTH_BY_AGENT); + return $this; + } /** * @param string $name diff --git a/src/Server/Configuration.php b/src/Server/Configuration.php index 46ab0752..6b54ff80 100644 --- a/src/Server/Configuration.php +++ b/src/Server/Configuration.php @@ -16,6 +16,8 @@ class Configuration const AUTH_BY_PUBLIC_KEY = 2; const AUTH_BY_PEM_FILE = 3; + + const AUTH_BY_AGENT = 4; /** * Type of authentication. diff --git a/src/Server/Remote/PhpSecLib.php b/src/Server/Remote/PhpSecLib.php index f014d324..a6690485 100644 --- a/src/Server/Remote/PhpSecLib.php +++ b/src/Server/Remote/PhpSecLib.php @@ -11,6 +11,7 @@ use Deployer\Server\Configuration; use Deployer\Server\ServerInterface; use phpseclib\Crypt\RSA; use phpseclib\Net\SFTP; +use \phpseclib\System\SSH\Agent; class PhpSecLib implements ServerInterface { @@ -71,6 +72,13 @@ class PhpSecLib implements ServerInterface break; + case Configuration::AUTH_BY_AGENT: + + $key = new Agent(); + $this->sftp->login($serverConfig->getUser(), $key); + + break; + default: throw new \RuntimeException('You need to specify authentication method.'); } diff --git a/src/Server/Remote/SshExtension.php b/src/Server/Remote/SshExtension.php index c5ba8d9d..7c5f632d 100644 --- a/src/Server/Remote/SshExtension.php +++ b/src/Server/Remote/SshExtension.php @@ -81,6 +81,10 @@ class SshExtension implements ServerInterface case Configuration::AUTH_BY_PEM_FILE: throw new \RuntimeException('If you want to use pem file, switch to using PhpSecLib.'); + + case Configuration::AUTH_BY_AGENT: + + throw new \RuntimeException('If you want to use forward agent function, switch to using PhpSecLib.'); default: throw new \RuntimeException('You need to specify authentication method.'); diff --git a/test/src/Server/BuilderTest.php b/test/src/Server/BuilderTest.php index 424003a5..9154af5a 100644 --- a/test/src/Server/BuilderTest.php +++ b/test/src/Server/BuilderTest.php @@ -101,4 +101,17 @@ class BuilderTest extends \PHPUnit_Framework_TestCase $b = new Builder($config, $env); $b->env('name', 'value'); } + + public function testForwardAgent() + { + $config = $this->getMockBuilder('Deployer\Server\Configuration')->disableOriginalConstructor()->getMock(); + $config->expects($this->once()) + ->method('setAuthenticationMethod') + ->with(Configuration::AUTH_BY_AGENT) + ->will($this->returnSelf()); + $env = $this->getMock('Deployer\Server\Environment'); + + $b = new Builder($config, $env); + $b->forwardAgent(); + } }