Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Symfony Process() usage #11

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/LagoonCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use GuzzleHttp\Client;
use Symfony\Component\Process\Process;
use Symfony\Component\Yaml\Yaml;
use \Symfony\Component\HttpKernel\Kernel;

/**
* Drush integration for Lagoon.
Expand Down Expand Up @@ -184,14 +185,29 @@ public function getLagoonYml() {
public function getJwtToken() {
[$ssh_host, $ssh_port] = explode(":", $this->endpoint);

$args = "-o ConnectTimeout=5 -o LogLevel=FATAL -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no";
$args = [
"-p", $ssh_port,
"-o", "ConnectTimeout=5",
"-o", "LogLevel=FATAL",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
];

if ($this->sshKey) {
$args .= " -i $this->sshKey";
$args += ["-i", $this->sshKey];
}

$cmd = ["ssh", ...$args, "lagoon@$ssh_host", "token", "2>&1"];

$this->logger()->debug("Retrieving token via SSH -" . implode(" ", $cmd));
if (version_compare(Kernel::VERSION, "4.2", "<")) {
// Symfony >= 4.2 only allows the array form of the command parameter
$ssh = new Process(implode(" ", $cmd));
}
else {
$ssh = new Process($cmd);
}
$cmd = "ssh -p $ssh_port $args lagoon@$ssh_host token 2>&1";
$this->logger()->debug("Retrieving token via SSH - $cmd");

$ssh = new Process($cmd);
$ssh->setTimeout($this->sshTimeout);
$ssh->mustRun();

Expand Down