Skip to content

Commit

Permalink
Merge branch '6.0' of https://github.com/krtcom/remote into krtcom-6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mlantz committed May 17, 2020
2 parents eaf69c5 + 514804d commit dbc68df
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
16 changes: 14 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,22 @@ public function task($task, Closure $callback = null)
* Run a set of commands against the connection.
*
* @param string|array $commands
* @param \Closure $callback
* @param \Closure $callback
*
* @param int|null $timeout
* @return void
*/
public function run($commands, Closure $callback = null)
public function run($commands, Closure $callback = null, int $timeout = null)
{
// First, we will initialize the SSH gateway, and then format the commands so
// they can be run. Once we have the commands formatted and the server is
// ready to go we will just fire off these commands against the server.
$gateway = $this->getGateway();

if ($timeout != null) {
$gateway->setTimeout($timeout);
}

$callback = $this->getCallback($callback);

$gateway->run($this->formatCommands($commands));
Expand Down Expand Up @@ -315,4 +320,11 @@ public function status()
{
return $this->gateway->status();
}

public function setTimeout($timeout) {

$this->getGateway()->setTimeout($timeout);

return $this;
}
}
8 changes: 8 additions & 0 deletions src/GatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,12 @@ public function nextLine();
* @return int|bool
*/
public function status();

/**
* Set timeout
*
* @param $timeout
* @return mixed
*/
public function setTimeout($timeout);
}
6 changes: 5 additions & 1 deletion src/SecLibGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,13 @@ public function getTimeout()
*
* @param int $timeout
*/
protected function setTimeout($timeout)
public function setTimeout($timeout)
{
$this->timeout = (int) $timeout;

if ($this->connection) {
$this->connection->setTimeout($this->timeout);
}
}

/**
Expand Down
7 changes: 4 additions & 3 deletions tests/RemoteSecLibTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function testHostAndPortSetCorrectly()
$gateway = $this->getGateway();
$this->assertEquals('127.0.0.1', $gateway->getHost());
$this->assertEquals(22, $gateway->getPort());
$this->assertEquals(10, $gateway->getTimeout());
}

public function testHostAndPortSetCorrectlyWithoutPort()
Expand Down Expand Up @@ -85,7 +86,7 @@ public function testConnectProperlyCallsLoginWithAuth()
public function testKeyTextCanBeSetManually()
{
$files = m::mock('Illuminate\Filesystem\Filesystem');
$gateway = m::mock('Collective\Remote\SecLibGateway', [
$gateway = m::mock('Collective\Remote\SecLibGateway[!setTimeout]', [
'127.0.0.1:22',
['username' => 'taylor', 'keytext' => 'keystuff'],
$files,
Expand All @@ -103,8 +104,8 @@ public function getGateway($host = '127.0.0.1:22')
{
$files = m::mock('Illuminate\Filesystem\Filesystem');
$files->shouldReceive('get')->with('keypath')->andReturn('keystuff');
$gateway = m::mock('Collective\Remote\SecLibGateway', [
$host,
$gateway = m::mock('Collective\Remote\SecLibGateway[!setTimeout]', [
'127.0.0.1:22',
['username' => 'taylor', 'key' => 'keypath', 'keyphrase' => 'keyphrase'],
$files,
10,
Expand Down

0 comments on commit dbc68df

Please sign in to comment.