Skip to content

Commit b211d67

Browse files
committed
Support for resolving private key from callable
1 parent 644de19 commit b211d67

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Commands/TaskMakeCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class TaskMakeCommand extends GeneratorCommand
1818
*/
1919
protected $name = 'make:task';
2020

21+
/**
22+
* The type of class being generated.
23+
*
24+
* @var string
25+
*/
26+
protected $type = 'Task';
27+
2128
/**
2229
* The name of the console command.
2330
*

src/Connection.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,17 @@ public static function fromArray(array $config): static
8686
: "/home/{$username}/.laravel-task-runner";
8787
}
8888

89+
$privateKey = $config['private_key'] ?? null;
90+
91+
if(is_callable($privateKey)) {
92+
$privateKey = $privateKey();
93+
}
94+
8995
return new static(
9096
host: $config['host'] ?: null,
9197
port: $config['port'] ?: null,
9298
username: $username ?: null,
93-
privateKey: $config['private_key'] ?? null,
99+
privateKey: $privateKey,
94100
scriptPath: $scriptPath,
95101
proxyJump: $config['proxy_jump'] ?? null,
96102
);

tests/ConnectionTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use ProtoneMedia\LaravelTaskRunner\Connection;
4+
5+
function addConnectionToConfig()
6+
{
7+
config(['task-runner.connections.production' => [
8+
'host' => '1.1.1.1',
9+
'port' => '21',
10+
'username' => 'root',
11+
'private_key' => fn() => 'secret',
12+
'passphrase' => 'password',
13+
'script_path' => '',
14+
]]);
15+
}
16+
17+
it('can resolve a private key from a callable', function () {
18+
addConnectionToConfig();
19+
20+
$connection = Connection::fromConfig('production');
21+
22+
expect($connection->privateKey)->toBe('secret');
23+
});

0 commit comments

Comments
 (0)