Skip to content

Commit

Permalink
Merge pull request #68 from fourkitchens/platform-uli-command
Browse files Browse the repository at this point in the history
Get a one time login URL for any environment
  • Loading branch information
rigoucr authored Jan 28, 2025
2 parents 8f48847 + c698ac8 commit 46b0dfd
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ Example:
**2. Full:** It replaces all existing code and allows you to write the command from scratch.

You can also create a new command, just choice the "Custom" option at the prompt when it ask you for for the command you want to overwrite, then respond to the questions, now a new command should have been created in the custom path, by default only a task is added to cleans the Drupal cache, but from this file, you can add your custom tasks.

- `platform:uli`: This command allows you to generate a one-time login URL for any environment hosted on Pantheon, Acquia, or Platform.sh.

Alias: `puli`

## Configuration
Into your project root create a file called: `fire.yml` and iside of it speficify your global project settings.
Expand Down
91 changes: 91 additions & 0 deletions src/Robo/Plugin/Commands/PlatformUliCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Fire\Robo\Plugin\Commands;

use Robo\Symfony\ConsoleIO;
use Robo\Robo;

/**
* Provides a wrapper for Terminus, Acquia CLI, and Platform.sh CLI to get login URLs.
*/
class PlatformUliCommand extends FireCommandBase {

/**
* Get the login URL for a site and environment.
*
* Usage Example: fire platform:uli pr-123
*
* @command platform:uli
* @aliases puli
* @usage fire platform:uli <env>
*
* @param $args The environment.
*/
public function uli(ConsoleIO $io, array $args) {
// Ensure the correct number of arguments are passed
if (count($args) < 1) {
$io->note('Usage: fire platform:uli <env>');
return;
}

// Assign environment variable directly from arguments
$env = $args[0]; // First argument: environment (e.g., pr-123)

// Get platform and site name information (Pantheon, Acquia, Platform.sh)
$platform = Robo::config()->get('remote_platform'); // Set in Robo config for your project
$remoteSiteName = Robo::config()->get('remote_sitename'); // Get the remote site name from the config

// Check CLI tool status
$cliStatus = $this->checkCliTools($platform);

if (!$cliStatus) {
$io->note('Required CLI tools are not installed or configured properly.');
return;
}

// Determine the command based on the platform
switch ($platform) {
case 'pantheon':
$command = "terminus drush $remoteSiteName.$env -- uli";
break;

case 'acquia':
$command = "acli drush $remoteSiteName.$env -- uli";
break;

case 'platformsh':
$command = "platform ssh --site=$remoteSiteName --env=$env drush uli";
break;

default:
$io->note('Unknown platform or missing configuration for platform detection.');
return;
}

// Execute the command
$tasks = $this->collectionBuilder($io);
$tasks->addTask($this->taskExec($command)->printOutput(TRUE));

return $tasks;
}

/**
* Checks if the necessary CLI tools are installed for the given platform.
*
* @param string $platform The platform (pantheon, acquia, platformsh).
*
* @return bool True if the CLI tools are found, false otherwise.
*/
private function checkCliTools(string $platform) {
switch ($platform) {
case 'pantheon':
return $this->getCliToolStatus('terminus');
case 'acquia':
return $this->getCliToolStatus('acli');
case 'platformsh':
return $this->getCliToolStatus('platform');
default:
return false;
}
}
}

0 comments on commit 46b0dfd

Please sign in to comment.