Skip to content

Commit

Permalink
Don't allow node environments
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Apr 25, 2024
1 parent d6225c5 commit a920d0f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
24 changes: 11 additions & 13 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ private function promptChooseDatabases(
return [$environmentDatabases[$chosenDatabaseIndex]];
}

protected function determineEnvironment(InputInterface $input, OutputInterface $output, bool $allowProduction = FALSE): array|string|EnvironmentResponse {
protected function determineEnvironment(InputInterface $input, OutputInterface $output, bool $allowProduction = FALSE, bool $allowNode = TRUE): array|string|EnvironmentResponse {

Check warning on line 577 in src/Command/CommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "FalseValue": --- Original +++ New @@ @@ $chosenDatabaseIndex = array_search($chosenDatabaseLabel, $choices, TRUE); return [$environmentDatabases[$chosenDatabaseIndex]]; } - protected function determineEnvironment(InputInterface $input, OutputInterface $output, bool $allowProduction = FALSE, bool $allowNode = TRUE) : array|string|EnvironmentResponse + protected function determineEnvironment(InputInterface $input, OutputInterface $output, bool $allowProduction = true, bool $allowNode = TRUE) : array|string|EnvironmentResponse { if ($input->getArgument('environmentId')) { $environmentId = $input->getArgument('environmentId');

Check warning on line 577 in src/Command/CommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "TrueValue": --- Original +++ New @@ @@ $chosenDatabaseIndex = array_search($chosenDatabaseLabel, $choices, TRUE); return [$environmentDatabases[$chosenDatabaseIndex]]; } - protected function determineEnvironment(InputInterface $input, OutputInterface $output, bool $allowProduction = FALSE, bool $allowNode = TRUE) : array|string|EnvironmentResponse + protected function determineEnvironment(InputInterface $input, OutputInterface $output, bool $allowProduction = FALSE, bool $allowNode = false) : array|string|EnvironmentResponse { if ($input->getArgument('environmentId')) { $environmentId = $input->getArgument('environmentId');
if ($input->getArgument('environmentId')) {
$environmentId = $input->getArgument('environmentId');
$chosenEnvironment = $this->getCloudEnvironment($environmentId);
Expand All @@ -584,20 +584,22 @@ protected function determineEnvironment(InputInterface $input, OutputInterface $
$cloudApplication = $this->getCloudApplication($cloudApplicationUuid);
$output->writeln('Using Cloud Application <options=bold>' . $cloudApplication->name . '</>');
$acquiaCloudClient = $this->cloudApiClientService->getClient();
$chosenEnvironment = $this->promptChooseEnvironmentConsiderProd($acquiaCloudClient, $cloudApplicationUuid, $allowProduction);
$chosenEnvironment = $this->promptChooseEnvironmentConsiderProd($acquiaCloudClient, $cloudApplicationUuid, $allowProduction, $allowNode);
}
$this->logger->debug("Using environment $chosenEnvironment->label $chosenEnvironment->uuid");

return $chosenEnvironment;
}

// Todo: obviously combine this with promptChooseEnvironment.
private function promptChooseEnvironmentConsiderProd(Client $acquiaCloudClient, string $applicationUuid, bool $allowProduction = FALSE): EnvironmentResponse {
private function promptChooseEnvironmentConsiderProd(Client $acquiaCloudClient, string $applicationUuid, bool $allowProduction = FALSE, bool $allowNode = TRUE): EnvironmentResponse {

Check warning on line 595 in src/Command/CommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "FalseValue": --- Original +++ New @@ @@ return $chosenEnvironment; } // Todo: obviously combine this with promptChooseEnvironment. - private function promptChooseEnvironmentConsiderProd(Client $acquiaCloudClient, string $applicationUuid, bool $allowProduction = FALSE, bool $allowNode = TRUE) : EnvironmentResponse + private function promptChooseEnvironmentConsiderProd(Client $acquiaCloudClient, string $applicationUuid, bool $allowProduction = true, bool $allowNode = TRUE) : EnvironmentResponse { $environmentResource = new Environments($acquiaCloudClient); $applicationEnvironments = iterator_to_array($environmentResource->getAll($applicationUuid));

Check warning on line 595 in src/Command/CommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "TrueValue": --- Original +++ New @@ @@ return $chosenEnvironment; } // Todo: obviously combine this with promptChooseEnvironment. - private function promptChooseEnvironmentConsiderProd(Client $acquiaCloudClient, string $applicationUuid, bool $allowProduction = FALSE, bool $allowNode = TRUE) : EnvironmentResponse + private function promptChooseEnvironmentConsiderProd(Client $acquiaCloudClient, string $applicationUuid, bool $allowProduction = FALSE, bool $allowNode = false) : EnvironmentResponse { $environmentResource = new Environments($acquiaCloudClient); $applicationEnvironments = iterator_to_array($environmentResource->getAll($applicationUuid));
$environmentResource = new Environments($acquiaCloudClient);
$applicationEnvironments = iterator_to_array($environmentResource->getAll($applicationUuid));
$choices = [];
foreach ($applicationEnvironments as $key => $environment) {
if (!$allowProduction && $environment->flags->production) {
$productionNotAllowed = !$allowProduction && $environment->flags->production;
$nodeNotAllowed = !$allowNode && $environment->type === 'node';

Check warning on line 601 in src/Command/CommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalNot": --- Original +++ New @@ @@ $choices = []; foreach ($applicationEnvironments as $key => $environment) { $productionNotAllowed = !$allowProduction && $environment->flags->production; - $nodeNotAllowed = !$allowNode && $environment->type === 'node'; + $nodeNotAllowed = $allowNode && $environment->type === 'node'; if ($productionNotAllowed || $nodeNotAllowed) { unset($applicationEnvironments[$key]); // Re-index array so keys match those in $choices.
if ($productionNotAllowed || $nodeNotAllowed) {

Check warning on line 602 in src/Command/CommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalOr": --- Original +++ New @@ @@ foreach ($applicationEnvironments as $key => $environment) { $productionNotAllowed = !$allowProduction && $environment->flags->production; $nodeNotAllowed = !$allowNode && $environment->type === 'node'; - if ($productionNotAllowed || $nodeNotAllowed) { + if ($productionNotAllowed && $nodeNotAllowed) { unset($applicationEnvironments[$key]); // Re-index array so keys match those in $choices. $applicationEnvironments = array_values($applicationEnvironments);
unset($applicationEnvironments[$key]);
// Re-index array so keys match those in $choices.
$applicationEnvironments = array_values($applicationEnvironments);
Expand Down Expand Up @@ -1682,17 +1684,17 @@ private function getAnyAhEnvironment(string $cloudAppUuid, callable $filter): En
* Get the first non-prod environment for a given Cloud application.
*/
protected function getAnyNonProdAhEnvironment(string $cloudAppUuid): EnvironmentResponse|false {
return $this->getAnyAhEnvironment($cloudAppUuid, function (mixed $environment) {
return !$environment->flags->production;
return $this->getAnyAhEnvironment($cloudAppUuid, function (EnvironmentResponse $environment) {
return !$environment->flags->production && $environment->type === 'drupal';

Check warning on line 1688 in src/Command/CommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ protected function getAnyNonProdAhEnvironment(string $cloudAppUuid) : EnvironmentResponse|false { return $this->getAnyAhEnvironment($cloudAppUuid, function (EnvironmentResponse $environment) { - return !$environment->flags->production && $environment->type === 'drupal'; + return !$environment->flags->production || $environment->type === 'drupal'; }); } /**
});
}

/**
* Get the first prod environment for a given Cloud application.
*/
protected function getAnyProdAhEnvironment(string $cloudAppUuid): EnvironmentResponse|false {
return $this->getAnyAhEnvironment($cloudAppUuid, function (mixed $environment) {
return $environment->flags->production;
return $this->getAnyAhEnvironment($cloudAppUuid, function (EnvironmentResponse $environment) {
return $environment->flags->production && $environment->type === 'drupal';
});
}

Expand Down Expand Up @@ -1848,11 +1850,7 @@ protected function promptChooseDrupalSite(EnvironmentResponse $environment): str
return $this->promptChooseAcsfSite($environment);
}

if ($environment->type === 'drupal') {
return $this->promptChooseCloudSite($environment);
}

throw new AcquiaCliException('Environment type {type} is not supported', ['type' => $environment->type]);
return $this->promptChooseCloudSite($environment);
}

}
2 changes: 1 addition & 1 deletion src/Command/Pull/PullDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// $noImport implies $noScripts.
$noScripts = $noImport || $noScripts;
$this->setDirAndRequireProjectCwd($input);
$sourceEnvironment = $this->determineEnvironment($input, $output, TRUE);
$sourceEnvironment = $this->determineEnvironment($input, $output, TRUE, FALSE);

Check warning on line 43 in src/Command/Pull/PullDatabaseCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "FalseValue": --- Original +++ New @@ @@ // $noImport implies $noScripts. $noScripts = $noImport || $noScripts; $this->setDirAndRequireProjectCwd($input); - $sourceEnvironment = $this->determineEnvironment($input, $output, TRUE, FALSE); + $sourceEnvironment = $this->determineEnvironment($input, $output, TRUE, true); $this->pullDatabase($input, $output, $sourceEnvironment, $onDemand, $noImport, $multipleDbs); if (!$noScripts) { $this->runDrushCacheClear($this->getOutputCallback($output, $this->checklist), $this->checklist);
$this->pullDatabase($input, $output, $sourceEnvironment, $onDemand, $noImport, $multipleDbs);
if (!$noScripts) {
$this->runDrushCacheClear($this->getOutputCallback($output, $this->checklist), $this->checklist);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Pull/PullFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function configure(): void {

protected function execute(InputInterface $input, OutputInterface $output): int {
$this->setDirAndRequireProjectCwd($input);
$sourceEnvironment = $this->determineEnvironment($input, $output, TRUE);
$sourceEnvironment = $this->determineEnvironment($input, $output, TRUE, FALSE);

Check warning on line 25 in src/Command/Pull/PullFilesCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "TrueValue": --- Original +++ New @@ @@ protected function execute(InputInterface $input, OutputInterface $output) : int { $this->setDirAndRequireProjectCwd($input); - $sourceEnvironment = $this->determineEnvironment($input, $output, TRUE, FALSE); + $sourceEnvironment = $this->determineEnvironment($input, $output, false, FALSE); $this->pullFiles($input, $output, $sourceEnvironment); return Command::SUCCESS; } }
$this->pullFiles($input, $output, $sourceEnvironment);

return Command::SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Push/PushDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function configure(): void {
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$destinationEnvironment = $this->determineEnvironment($input, $output);
$destinationEnvironment = $this->determineEnvironment($input, $output, FALSE, FALSE);
$acquiaCloudClient = $this->cloudApiClientService->getClient();
$databases = $this->determineCloudDatabases($acquiaCloudClient, $destinationEnvironment, $input->getArgument('site'));
// We only support pushing a single database.
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Push/PushFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function configure(): void {

protected function execute(InputInterface $input, OutputInterface $output): int {
$this->setDirAndRequireProjectCwd($input);
$destinationEnvironment = $this->determineEnvironment($input, $output);
$destinationEnvironment = $this->determineEnvironment($input, $output, FALSE, FALSE);
$chosenSite = $input->getArgument('site');
if (!$chosenSite) {
$chosenSite = $this->promptChooseDrupalSite($destinationEnvironment);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Remote/DrushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function configure(): void {
}

protected function execute(InputInterface $input, OutputInterface $output): ?int {
$environment = $this->determineEnvironment($input, $output);
$environment = $this->determineEnvironment($input, $output, FALSE, FALSE);
$alias = self::getEnvironmentAlias($environment);
$acliArguments = $input->getArguments();
$drushArguments = (array) $acliArguments['drush_command'];
Expand Down

0 comments on commit a920d0f

Please sign in to comment.