Skip to content

Commit

Permalink
Support for resolving private key from callable
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Aug 15, 2023
1 parent 644de19 commit b211d67
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Commands/TaskMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class TaskMakeCommand extends GeneratorCommand
*/
protected $name = 'make:task';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Task';

/**
* The name of the console command.
*
Expand Down
8 changes: 7 additions & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ public static function fromArray(array $config): static
: "/home/{$username}/.laravel-task-runner";
}

$privateKey = $config['private_key'] ?? null;

if(is_callable($privateKey)) {
$privateKey = $privateKey();
}

return new static(
host: $config['host'] ?: null,
port: $config['port'] ?: null,
username: $username ?: null,
privateKey: $config['private_key'] ?? null,
privateKey: $privateKey,
scriptPath: $scriptPath,
proxyJump: $config['proxy_jump'] ?? null,
);
Expand Down
23 changes: 23 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use ProtoneMedia\LaravelTaskRunner\Connection;

function addConnectionToConfig()
{
config(['task-runner.connections.production' => [
'host' => '1.1.1.1',
'port' => '21',
'username' => 'root',
'private_key' => fn() => 'secret',
'passphrase' => 'password',
'script_path' => '',
]]);
}

it('can resolve a private key from a callable', function () {
addConnectionToConfig();

$connection = Connection::fromConfig('production');

expect($connection->privateKey)->toBe('secret');
});

0 comments on commit b211d67

Please sign in to comment.