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

Adds ssh portal support #9

Closed
wants to merge 2 commits into from
Closed
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
53 changes: 52 additions & 1 deletion src/LagoonCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,53 @@ public function aliases() {
}
}

/**
* Alters aliases to support ssh-portal.
*
* @hook pre-init *
*/
public function alter($input, $annotationData) {
$self = $this->siteAliasManager()->getSelf();
if ($self->isRemote()) {
if (empty($this->jwt_token)) {
$this->jwt_token = $this->getJwtToken();
}
$response = $this->getLagoonEnvs();
// Check if the query returned any data for the requested project.
if (empty($response->data->project->environments)) {
$this->logger()->warning(
"API request didn't return any environments for the given project '$this->projectName'."
);
// there's nothing for us to do, so we ...
return;
}

$alias = $self->name();
$matchEnv = NULL;
foreach ($response->data->project->environments as $environment) {
$envAlias = "@lagoon.$this->projectName-$environment->name";
if ($envAlias == $alias) {
$matchEnv = $environment;
}
}

if (empty($matchEnv)) {
return;
}

$config = $this->getConfig();
if (!empty($matchEnv->openshift->sshHost)) {
$config->set('host', $matchEnv->openshift->sshHost);
}
if (!empty($matchEnv->openshift->sshPort)) {
$config->set(
'ssh.options',
sprintf("-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p %s", $matchEnv->openshift->sshPort)
);
}
}
}

/**
* Generate a JWT token for the lagoon API.
*
Expand Down Expand Up @@ -213,7 +260,11 @@ public function getLagoonEnvs() {
standbyAlias,
environments {
name,
openshiftProjectName
openshiftProjectName,
openshift {
sshHost,
sshPort
}
}
}
}', $this->projectName);
Expand Down