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

Supports running drupal-integrations outside of Lagoon environments #24

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 29 additions & 2 deletions src/LagoonCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
use Drush\Commands\DrushCommands;
use Drush\Drush;
use Drush\Exceptions\CommandFailedException;
use Drush\SiteAlias\SiteAliasManagerAwareInterface;
use GuzzleHttp\Client;
use Symfony\Component\HttpKernel\Kernel;
Expand Down Expand Up @@ -64,8 +65,9 @@ class LagoonCommands extends DrushCommands implements SiteAliasManagerAwareInter
* {@inheritdoc}
*/
public function __construct() {
if (getenv('LAGOON')) {
// Get default config.
// Get default config.
if ($this->isLagoonEnvironment()) {
$this->isLagoonEnvironment = TRUE;
$lagoonyml = $this->getLagoonYml();
$this->api = $lagoonyml['api'] ?? 'https://api.lagoon.amazeeio.cloud/graphql';
$this->endpoint = $lagoonyml['ssh'] ?? 'ssh.lagoon.amazeeio.cloud:32222';
Expand All @@ -90,6 +92,7 @@ public function __construct() {
* @aliases la
*/
public function aliases() {
$this->preCommandChecks();
// Project still not defined, throw a warning.
if ($this->projectName === FALSE) {
$this->logger()->warning('ERROR: Could not discover project name, you should define it inside your .lagoon.yml file');
Expand Down Expand Up @@ -127,6 +130,7 @@ public function aliases() {
* @aliases jwt
*/
public function generateJwt() {
$this->preCommandChecks();
$this->io()->writeln($this->getJwtToken());
}

Expand All @@ -136,6 +140,7 @@ public function generateJwt() {
* @command lagoon:pre-rollout-tasks
*/
public function preRolloutTasks() {
$this->preCommandChecks();
$this->runRolloutTasks('pre');
}

Expand All @@ -145,6 +150,7 @@ public function preRolloutTasks() {
* @command lagoon:post-rollout-tasks
*/
public function postRolloutTasks() {
$this->preCommandChecks();
$this->runRolloutTasks('post');
}

Expand Down Expand Up @@ -264,4 +270,25 @@ public function getLagoonEnvs() {
return json_decode($response);
}

/**
* Will check whether the current environment is Lagoon or Lagoon dev envs.
*
* @return bool
* is a functional Lagoon env
*/
private function isLagoonEnvironment() {
return !empty(getenv("LAGOON"));
}

/**
* This should be run before any Lagoon commands.
*
* Checks whether we have a valid environment before running.
*/
private function preCommandChecks() {
if ($this->isLagoonEnvironment() == FALSE) {
throw new CommandFailedException(dt("Attempting to run a Lagoon command in a non-Lagoon environment."));
}
}

}