Skip to content

Commit

Permalink
Merge branch 'main' into GL-2039
Browse files Browse the repository at this point in the history
  • Loading branch information
akashkska authored Feb 21, 2024
2 parents 60bf6c6 + 6bc2749 commit 34b0461
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 92 deletions.
4 changes: 3 additions & 1 deletion .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
use AcquiaCloudApi\Response\ApplicationResponse;
use AcquiaCloudApi\Response\ApplicationsResponse;
use AcquiaCloudApi\Response\DatabasesResponse;
use AcquiaCloudApi\Response\EnvironmentResponse;
use AcquiaCloudApi\Response\EnvironmentsResponse;

override(\Acquia\Cli\Tests\TestBase::mockRequest(), map([
'getAccount' => AccountResponse::class,
'getApplications' => ApplicationsResponse::class,
'getApplicationByUuid' => ApplicationResponse::class,
'getApplicationEnvironments' => EnvironmentsResponse::class,
'getEnvironmentsDatabases' => DatabasesResponse::class
'getEnvironmentsDatabases' => DatabasesResponse::class,
'getEnvironment' => EnvironmentResponse::class
]));

}
20 changes: 10 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />

<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="echo" value="null"/>
</property>
</properties>
</rule>
</ruleset>
4 changes: 2 additions & 2 deletions src/Command/App/LogTailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ protected function configure(): void {
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$environmentId = $this->determineCloudEnvironment();
$environment = $this->determineEnvironment($input, $output);
$acquiaCloudClient = $this->cloudApiClientService->getClient();
$logs = $this->promptChooseLogs();
$logTypes = array_map(static function (mixed $log) {
return $log['type'];
}, $logs);
$logsResource = new Logs($acquiaCloudClient);
$stream = $logsResource->stream($environmentId);
$stream = $logsResource->stream($environment->uuid);
$this->logstreamManager->setParams($stream->logstream->params);
$this->logstreamManager->setColourise(TRUE);
$this->logstreamManager->setLogTypeFilter($logTypes);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CodeStudio/CodeStudioWizardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'codestudio:wizard', description: 'Create and/or configure a new Code Studio project for a given Acquia Cloud application', aliases: ['cs:wizard'])]
#[AsCommand(name: 'codestudio:wizard', description: 'Create and/or configure a new Code Studio project for a given Cloud Platform application', aliases: ['cs:wizard'])]
final class CodeStudioWizardCommand extends WizardCommandBase {

use CodeStudioCommandTrait;
Expand Down
49 changes: 14 additions & 35 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
use stdClass;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\Table;
Expand Down Expand Up @@ -475,9 +474,10 @@ protected function rsyncFiles(string $sourceDir, string $destinationDir, ?callab
}

protected function getCloudFilesDir(EnvironmentResponse $chosenEnvironment, string $site): string {
$sitegroup = self::getSiteGroupFromSshUrl($chosenEnvironment->sshUrl);
$sitegroup = self::getSitegroup($chosenEnvironment);
$envAlias = self::getEnvironmentAlias($chosenEnvironment);
if ($this->isAcsfEnv($chosenEnvironment)) {
return '/mnt/files/' . $sitegroup . '.' . $chosenEnvironment->name . '/sites/g/files/' . $site . '/files';
return "/mnt/files/$envAlias/sites/g/files/$site/files";
}
return $this->getCloudSitesPath($chosenEnvironment, $sitegroup) . "/$site/files";
}
Expand All @@ -502,7 +502,7 @@ protected function determineCloudDatabases(Client $acquiaCloudClient, Environmen
if ($site && !$multipleDbs) {
if ($site === 'default') {
$this->logger->debug('Site is set to default. Assuming default database');
$site = self::getSiteGroupFromSshUrl($chosenEnvironment->sshUrl);
$site = self::getSitegroup($chosenEnvironment);
}
$databaseNames = array_column((array) $databases, 'name');
$databaseKey = array_search($site, $databaseNames, TRUE);
Expand Down Expand Up @@ -776,28 +776,6 @@ protected function inferCloudAppFromLocalGitConfig(
return NULL;
}

/**
* Determine the Cloud environment.
*
* @return string The environment UUID.
*/
protected function determineCloudEnvironment(): string {
if ($this->input->hasArgument('environmentId') && $this->input->getArgument('environmentId')) {
return $this->input->getArgument('environmentId');
}

if (!$this->input->isInteractive()) {
throw new RuntimeException('Not enough arguments (missing: "environmentId").');
}

$applicationUuid = $this->determineCloudApplication();
$acquiaCloudClient = $this->cloudApiClientService->getClient();
/** @var EnvironmentResponse $environment */
$environment = $this->promptChooseEnvironment($acquiaCloudClient, $applicationUuid);

return $environment->uuid;
}

/**
* @return array<mixed>
*/
Expand Down Expand Up @@ -1316,12 +1294,13 @@ protected function convertNotificationToUuid(InputInterface $input, string $argu
}
}

/**
* @param string $sshUrl The SSH URL to the server.
* @return string The sitegroup. E.g., eemgrasmick.
*/
public static function getSiteGroupFromSshUrl(string $sshUrl): string {
$sshUrlParts = explode('.', $sshUrl);
public static function getSitegroup(EnvironmentResponse $environment): string {
$sshUrlParts = explode('.', $environment->sshUrl);
return reset($sshUrlParts);
}

public static function getEnvironmentAlias(EnvironmentResponse $environment): string {
$sshUrlParts = explode('@', $environment->sshUrl);
return reset($sshUrlParts);
}

Expand All @@ -1342,8 +1321,8 @@ protected function isAcsfEnv(mixed $cloudEnvironment): bool {
* @return array<mixed>
*/
protected function getAcsfSites(EnvironmentResponse $cloudEnvironment): array {
$sitegroup = self::getSiteGroupFromSshUrl($cloudEnvironment->sshUrl);
$command = ['cat', "/var/www/site-php/$sitegroup.{$cloudEnvironment->name}/multisite-config.json"];
$envAlias = self::getEnvironmentAlias($cloudEnvironment);
$command = ['cat', "/var/www/site-php/$envAlias/multisite-config.json"];
$process = $this->sshHelper->executeCommand($cloudEnvironment, $command, FALSE);
if ($process->isSuccessful()) {
return json_decode($process->getOutput(), TRUE, 512, JSON_THROW_ON_ERROR);
Expand All @@ -1355,7 +1334,7 @@ protected function getAcsfSites(EnvironmentResponse $cloudEnvironment): array {
* @return array<mixed>
*/
private function getCloudSites(EnvironmentResponse $cloudEnvironment): array {
$sitegroup = self::getSiteGroupFromSshUrl($cloudEnvironment->sshUrl);
$sitegroup = self::getSitegroup($cloudEnvironment);
$command = ['ls', $this->getCloudSitesPath($cloudEnvironment, $sitegroup)];
$process = $this->sshHelper->executeCommand($cloudEnvironment, $command, FALSE);
$sites = array_filter(explode("\n", trim($process->getOutput())));
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Env/EnvCertCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function configure(): void {

protected function execute(InputInterface $input, OutputInterface $output): int {
$acquiaCloudClient = $this->cloudApiClientService->getClient();
$envUuid = $this->determineCloudEnvironment();
$environment = $this->determineEnvironment($input, $output);
$certificate = $input->getArgument('certificate');
$privateKey = $input->getArgument('private-key');
$label = $this->determineOption('label');
Expand All @@ -42,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$sslCertificates = new SslCertificates($acquiaCloudClient);
$response = $sslCertificates->create(
$envUuid,
$environment->uuid,
$label,
$this->localMachineHelper->readFile($certificate),
$this->localMachineHelper->readFile($privateKey),
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Env/EnvCopyCronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\Console\Output\OutputInterface;

#[RequireAuth]
#[AsCommand(name: 'env:cron-copy', description: 'Copy all cron tasks from one Acquia Cloud Platform environment to another')]
#[AsCommand(name: 'env:cron-copy', description: 'Copy all cron tasks from one Cloud Platform environment to another')]
final class EnvCopyCronCommand extends CommandBase {

protected function configure(): void {
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Push/PushDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private function uploadDatabaseDump(
string $localFilepath,
callable $outputCallback
): string {
$sitegroup = self::getSiteGroupFromSshUrl($environment->sshUrl);
$remoteFilepath = "/mnt/tmp/{$sitegroup}.{$environment->name}/" . basename($localFilepath);
$envAlias = self::getEnvironmentAlias($environment);
$remoteFilepath = "/mnt/tmp/$envAlias/" . basename($localFilepath);
$this->logger->debug("Uploading database dump to $remoteFilepath on remote machine");
$this->localMachineHelper->checkRequiredBinariesExist(['rsync']);
$command = [
Expand Down
13 changes: 5 additions & 8 deletions src/Command/Remote/DrushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,25 @@
* A command to proxy Drush commands on an environment using SSH.
*/
#[RequireAuth]
#[AsCommand(name: 'remote:drush', description: 'Run a Drush command remotely on a application\'s environment', aliases: ['drush', 'dr'])]
#[AsCommand(name: 'remote:drush', description: 'Run a Drush command remotely on a Cloud Platform environment', aliases: ['drush', 'dr'])]
final class DrushCommand extends SshBaseCommand {

protected function configure(): void {
$this
->setHelp('<fg=black;bg=cyan>Pay close attention to the argument syntax! Note the usage of <options=bold;bg=cyan>--</> to separate the drush command arguments and options.</>')
->addArgument('alias', InputArgument::REQUIRED, 'Alias for application & environment in the format `app-name.env`')
->acceptEnvironmentId()
->addArgument('drush_command', InputArgument::IS_ARRAY, 'Drush command')
->addUsage('<app>.<env> -- <command>')
->addUsage('myapp.dev -- uli 1')
->addUsage('myapp.dev -- status --fields=db-status');
}

protected function execute(InputInterface $input, OutputInterface $output): ?int {
$alias = $input->getArgument('alias');
$alias = $this->normalizeAlias($alias);
$alias = self::validateEnvironmentAlias($alias);
$environment = $this->getEnvironmentFromAliasArg($alias);

$environment = $this->determineEnvironment($input, $output);
$alias = self::getEnvironmentAlias($environment);
$acliArguments = $input->getArguments();
$drushCommandArguments = [
"cd /var/www/html/{$alias}/docroot; ",
"cd /var/www/html/$alias/docroot; ",
'drush',
implode(' ', (array) $acliArguments['drush_command']),
];
Expand Down
11 changes: 0 additions & 11 deletions tests/phpunit/src/Application/ExceptionApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ public function testNoAvailableIdes(): void {
self::assertStringContainsString('Delete an existing IDE', $buffer);
}

/**
* @group serial
*/
public function testMissingEnvironmentUuid(): void {
$this->setInput([
'command' => 'log:tail',
]);
$buffer = $this->runApp();
self::assertStringContainsString('can also be a site alias.', $buffer);
}

/**
* @group serial
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/src/Application/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ private function getEnd(): string {
auth:logout [logout] Remove Cloud Platform API credentials
codestudio
codestudio:php-version Change the PHP version in Code Studio
codestudio:wizard [cs:wizard] Create and/or configure a new Code Studio project for a given Acquia Cloud application
codestudio:wizard [cs:wizard] Create and/or configure a new Code Studio project for a given Cloud Platform application
email
email:configure [ec] Configure Platform email for one or more applications
email:info Print information related to Platform Email set up in a subscription.
env
env:certificate-create Install an SSL certificate.
env:create Create a new Continuous Delivery Environment (CDE)
env:cron-copy Copy all cron tasks from one Acquia Cloud Platform environment to another
env:cron-copy Copy all cron tasks from one Cloud Platform environment to another
env:delete Delete a Continuous Delivery Environment (CDE)
env:mirror Makes one environment identical to another in terms of code, database, files, and configuration.
ide
Expand All @@ -98,7 +98,7 @@ private function getEnd(): string {
remote
remote:aliases:download Download Drush aliases for the Cloud Platform
remote:aliases:list [aliases|sa] List all aliases for the Cloud Platform environments
remote:drush [drush|dr] Run a Drush command remotely on a application's environment
remote:drush [drush|dr] Run a Drush command remotely on a Cloud Platform environment
remote:ssh [ssh] Use SSH to open a shell or run a command in a Cloud Platform environment
self
self:clear-caches [cc|cr] Clears local Acquia CLI caches
Expand Down
5 changes: 3 additions & 2 deletions tests/phpunit/src/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ protected function mockGetAcsfSites(mixed $sshHelper): array {
$acsfMultisiteFetchProcess->getOutput()->willReturn($multisiteConfig)->shouldBeCalled();
$sshHelper->executeCommand(
Argument::type('object'),
['cat', '/var/www/site-php/profserv2.dev/multisite-config.json'],
['cat', '/var/www/site-php/profserv2.01dev/multisite-config.json'],
FALSE
)->willReturn($acsfMultisiteFetchProcess->reveal())->shouldBeCalled();
return json_decode($multisiteConfig, TRUE);
Expand All @@ -274,7 +274,8 @@ protected function mockGetAcsfSites(mixed $sshHelper): array {
protected function mockGetCloudSites(mixed $sshHelper, mixed $environment): void {
$cloudMultisiteFetchProcess = $this->mockProcess();
$cloudMultisiteFetchProcess->getOutput()->willReturn("\nbar\ndefault\nfoo\n")->shouldBeCalled();
$sitegroup = CommandBase::getSiteGroupFromSshUrl($environment->ssh_url);
$parts = explode('.', $environment->ssh_url);
$sitegroup = reset($parts);
$sshHelper->executeCommand(
Argument::type('object'),
['ls', "/mnt/files/$sitegroup.{$environment->name}/sites"],
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/src/Commands/App/LogTailCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function testLogTailCommand(): void {
}

public function testLogTailCommandWithEnvArg(): void {
$this->mockRequest('getEnvironment', '24-a47ac10b-58cc-4372-a567-0e02b2c3d470');
$this->mockLogStreamRequest();
$this->executeCommand(
['environmentId' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d470'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ protected function mockExecuteMySqlImport(
}

protected function mockDownloadMySqlDump(ObjectProphecy $localMachineHelper, mixed $success): void {
$process = $this->mockProcess($success);
$this->mockProcess($success);
$localMachineHelper->writeFile(
Argument::containingString("dev-profserv2-profserv201dev-something.sql.gz"),
'backupfilecontents'
Expand Down
5 changes: 3 additions & 2 deletions tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testRefreshAcsfFiles(): void {
$this->mockGetAcsfSites($sshHelper);
$localMachineHelper = $this->mockLocalMachineHelper();
$this->mockGetFilesystem($localMachineHelper);
$this->mockExecuteRsync($localMachineHelper, $selectedEnvironment, '/mnt/files/profserv2.dev/sites/g/files/jxr5000596dev/files/', $this->projectDir . '/docroot/sites/jxr5000596dev/files');
$this->mockExecuteRsync($localMachineHelper, $selectedEnvironment, '/mnt/files/profserv2.01dev/sites/g/files/jxr5000596dev/files/', $this->projectDir . '/docroot/sites/jxr5000596dev/files');

$this->command->sshHelper = $sshHelper->reveal();

Expand Down Expand Up @@ -78,7 +78,8 @@ public function testRefreshCloudFiles(): void {
$this->mockGetCloudSites($sshHelper, $selectedEnvironment);
$localMachineHelper = $this->mockLocalMachineHelper();
$this->mockGetFilesystem($localMachineHelper);
$sitegroup = CommandBase::getSiteGroupFromSshUrl($selectedEnvironment->ssh_url);
$parts = explode('.', $selectedEnvironment->ssh_url);
$sitegroup = reset($parts);
$this->mockExecuteRsync($localMachineHelper, $selectedEnvironment, '/mnt/files/' . $sitegroup . '.' . $selectedEnvironment->name . '/sites/bar/files/', $this->projectDir . '/docroot/sites/bar/files');

$this->command->sshHelper = $sshHelper->reveal();
Expand Down
Loading

0 comments on commit 34b0461

Please sign in to comment.