Skip to content

Commit

Permalink
Merge branch 'main' into CLI-1292
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell authored Mar 20, 2024
2 parents 6ef589d + ec62a12 commit d62cd5c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 58 deletions.
82 changes: 41 additions & 41 deletions composer.lock

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

5 changes: 5 additions & 0 deletions src/Command/Auth/AuthLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Acquia\Cli\Command\Auth;

use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Exception\AcquiaCliException;
use AcquiaCloudApi\Endpoints\Account;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand All @@ -25,6 +26,10 @@ protected function configure(): void {
protected function execute(InputInterface $input, OutputInterface $output): int {
$keys = $this->datastoreCloud->get('keys');
$activeKey = $this->datastoreCloud->get('acli_key');
// @todo this validation should really be enforced as a schema on the datastore.
if (is_array($keys) && !array_key_exists($activeKey, $keys)) {
throw new AcquiaCliException('Invalid key in Cloud datastore; run acli auth:logout && acli auth:login to fix');
}
if ($activeKey) {
$activeKeyLabel = $keys[$activeKey]['label'];
$output->writeln("The following Cloud Platform API key is active: <options=bold>$activeKeyLabel</>");
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ protected function waitForNotificationToComplete(Client $acquiaCloudClient, stri
$this->writeCompletedMessage($notification);
};
}
LoopHelper::getLoopy($this->output, $this->io, $this->logger, $message, $checkNotificationStatus, $success);
LoopHelper::getLoopy($this->output, $this->io, $message, $checkNotificationStatus, $success);
return $notification->status === 'completed';
}

Expand Down
4 changes: 2 additions & 2 deletions src/Command/Ide/IdeCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function waitForDnsPropagation(string $ideUrl): int {
$checkIdeStatus = function () use (&$ideCreated, $ideUrl) {
// Ideally we'd set $ideUrl as the Guzzle base_url, but that requires creating a client factory.
// @see https://stackoverflow.com/questions/28277889/guzzlehttp-client-change-base-url-dynamically
$response = $this->httpClient->request('GET', "$ideUrl/health");
$response = $this->httpClient->request('GET', "$ideUrl/health", ['http_errors' => FALSE]);
// Mutating this will result in an infinite loop and timeout.
// @infection-ignore-all
if ($response->getStatusCode() === 200) {
Expand All @@ -119,7 +119,7 @@ private function waitForDnsPropagation(string $ideUrl): int {
$this->writeIdeLinksToScreen();
};
$spinnerMessage = 'Waiting for the IDE to be ready. This usually takes 2 - 15 minutes.';
LoopHelper::getLoopy($this->output, $this->io, $this->logger, $spinnerMessage, $checkIdeStatus, $doneCallback);
LoopHelper::getLoopy($this->output, $this->io, $spinnerMessage, $checkIdeStatus, $doneCallback);

return Command::SUCCESS;
}
Expand Down
19 changes: 6 additions & 13 deletions src/Helpers/LoopHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Acquia\Cli\Helpers;

use Acquia\Cli\Output\Spinner\Spinner;
use Exception;
use Psr\Log\LoggerInterface;
use React\EventLoop\Loop;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand All @@ -16,7 +14,7 @@ class LoopHelper {
/**
* @param callable $statusCallback A TRUE return value will cause the loop to exit and call $doneCallback.
*/
public static function getLoopy(OutputInterface $output, SymfonyStyle $io, LoggerInterface $logger, string $spinnerMessage, callable $statusCallback, callable $doneCallback): void {
public static function getLoopy(OutputInterface $output, SymfonyStyle $io, string $spinnerMessage, callable $statusCallback, callable $doneCallback): void {
$timers = [];
$spinner = new Spinner($output, 4);
$spinner->setMessage($spinnerMessage);
Expand All @@ -28,16 +26,11 @@ public static function getLoopy(OutputInterface $output, SymfonyStyle $io, Logge
$timers = [];
$spinner->finish();
};
$periodicCallback = static function () use ($logger, $statusCallback, $doneCallback, $cancelTimers): void {
try {
// @infection-ignore-all
if ($statusCallback()) {
$cancelTimers();
$doneCallback();
}
}
catch (Exception $e) {
$logger->debug($e->getMessage());
$periodicCallback = static function () use ($statusCallback, $doneCallback, $cancelTimers): void {
// @infection-ignore-all
if ($statusCallback()) {
$cancelTimers();
$doneCallback();
}
};

Expand Down
13 changes: 13 additions & 0 deletions tests/phpunit/src/Commands/Auth/AuthLoginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Config\CloudDataConfig;
use Acquia\Cli\DataStore\CloudDataStore;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\CommandTestBase;
use AcquiaCloudApi\Connector\Connector;
use Generator;
Expand Down Expand Up @@ -68,6 +69,18 @@ public function testAuthLoginInvalidInputCommand(array $inputs, array $args): vo
$this->executeCommand($args, $inputs);
}

public function testAuthLoginInvalidDatastore(): void {
$this->clientServiceProphecy->isMachineAuthenticated()->willReturn(FALSE);
$this->removeMockCloudConfigFile();
$this->createDataStores();
$this->datastoreCloud->set('keys', ['key1']);
$this->datastoreCloud->set('acli_key', 'key2');
$this->command = $this->createCommand();
$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage('Invalid key in Cloud datastore; run acli auth:logout && acli auth:login to fix');
$this->executeCommand();
}

protected function assertInteractivePrompts(string $output): void {
// Your machine has already been authenticated with the Cloud Platform API, would you like to re-authenticate?
$this->assertStringContainsString('You will need a Cloud Platform API token from https://cloud.acquia.com/a/profile/tokens', $output);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/src/Commands/Ide/IdeCreateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testCreate(): void {
/** @var \Prophecy\Prophecy\ObjectProphecy|\GuzzleHttp\Psr7\Response $guzzleResponse */
$guzzleResponse = $this->prophet->prophesize(Response::class);
$guzzleResponse->getStatusCode()->willReturn(200);
$this->httpClientProphecy->request('GET', 'https://215824ff-272a-4a8c-9027-df32ed1d68a9.ides.acquia.com/health')->willReturn($guzzleResponse->reveal())->shouldBeCalled();
$this->httpClientProphecy->request('GET', 'https://215824ff-272a-4a8c-9027-df32ed1d68a9.ides.acquia.com/health', ['http_errors' => FALSE])->willReturn($guzzleResponse->reveal())->shouldBeCalled();

$inputs = [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
Expand Down

0 comments on commit d62cd5c

Please sign in to comment.