8
8
* file that was distributed with this source code.
9
9
*/
10
10
11
- namespace Deployer \Component \ Ssh ;
11
+ namespace Deployer \Ssh ;
12
12
13
13
use Deployer \Component \ProcessRunner \Printer ;
14
- use Deployer \Exception \Exception ;
15
14
use Deployer \Exception \RunException ;
16
15
use Deployer \Exception \TimeoutException ;
17
16
use Deployer \Host \Host ;
20
19
use Symfony \Component \Process \Exception \ProcessTimedOutException ;
21
20
use Symfony \Component \Process \Process ;
22
21
23
- use function Deployer \Support \parse_home_dir ;
24
-
25
- class Client
22
+ class SshClient
26
23
{
27
- /**
28
- * @var OutputInterface
29
- */
30
- private $ output ;
31
-
32
- /**
33
- * @var Printer
34
- */
35
- private $ pop ;
36
-
37
- /**
38
- * @var Logger
39
- */
40
- private $ logger ;
24
+ private OutputInterface $ output ;
25
+ private Printer $ pop ;
26
+ private Logger $ logger ;
41
27
42
28
public function __construct (OutputInterface $ output , Printer $ pop , Logger $ logger )
43
29
{
@@ -46,9 +32,6 @@ public function __construct(OutputInterface $output, Printer $pop, Logger $logge
46
32
$ this ->logger = $ logger ;
47
33
}
48
34
49
- /**
50
- * @throws RunException|TimeoutException|Exception
51
- */
52
35
public function run (Host $ host , string $ command , array $ config = []): string
53
36
{
54
37
$ defaults = [
@@ -59,7 +42,7 @@ public function run(Host $host, string $command, array $config = []): string
59
42
];
60
43
$ config = array_merge ($ defaults , $ config );
61
44
62
- $ shellId = bin2hex (random_bytes (10 ));
45
+ $ shellId = ' id$ ' . bin2hex (random_bytes (10 ));
63
46
$ shellCommand = $ host ->getShell ();
64
47
if ($ host ->has ('become ' ) && !empty ($ host ->get ('become ' ))) {
65
48
$ shellCommand = "sudo -H -u {$ host ->get ('become ' )} " . $ shellCommand ;
@@ -84,7 +67,7 @@ public function run(Host $host, string $command, array $config = []): string
84
67
85
68
$ process = new Process ($ ssh );
86
69
$ process
87
- ->setInput (" ( $ command ); printf '[exit_code:%s]' $?; " )
70
+ ->setInput ($ command )
88
71
->setTimeout ((null === $ config ['timeout ' ]) ? null : (float ) $ config ['timeout ' ])
89
72
->setIdleTimeout ((null === $ config ['idle_timeout ' ]) ? null : (float ) $ config ['idle_timeout ' ]);
90
73
@@ -106,8 +89,8 @@ public function run(Host $host, string $command, array $config = []): string
106
89
);
107
90
}
108
91
109
- $ output = $ this -> pop -> filterOutput ( $ process ->getOutput () );
110
- $ exitCode = $ this -> parseExitStatus ( $ process );
92
+ $ output = $ process ->getOutput ();
93
+ $ exitCode = $ process -> getExitCode ( );
111
94
112
95
if ($ exitCode !== 0 && !$ config ['no_throw ' ]) {
113
96
throw new RunException (
0 commit comments