Skip to content

Commit a5ee59b

Browse files
authored
[DEVX-5263] Modify commands to properly not work for eVCS/Node. (#2699)
* Base work and remove info from connection:info command. * Modify EnvInfo command. * Modify localClone command. * Modify localCommitAndPush command. * Modify multidevCreate command. * Modify multidevDelete command. * Modify lockInfo command. * Modify sshBase commands. * Modify envWake command. * Fix linting. * Update src/Commands/Local/CommitAndPushCommand.php
1 parent 780d007 commit a5ee59b

File tree

10 files changed

+124
-3
lines changed

10 files changed

+124
-3
lines changed

src/Commands/Env/InfoCommand.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Pantheon\Terminus\Commands\StructuredListTrait;
88
use Pantheon\Terminus\Site\SiteAwareInterface;
99
use Pantheon\Terminus\Site\SiteAwareTrait;
10+
use Pantheon\Terminus\Models\TerminusModel;
1011

1112
/**
1213
* Class InfoCommand.
@@ -49,4 +50,24 @@ public function info($site_env)
4950

5051
return $this->getPropertyList($this->getEnv($site_env));
5152
}
53+
54+
/**
55+
* @param TerminusModel $model A model with data to extract
56+
* @return PropertyList A PropertyList-type object with applied filters
57+
*/
58+
public function getPropertyList(TerminusModel $model)
59+
{
60+
$properties = $model->serialize();
61+
if ($model->isEvcsSite()) {
62+
// Remove properties that are not applicable to EVCS sites
63+
unset($properties['connection_mode']);
64+
}
65+
if ($model->getSite()->isNodejs()) {
66+
// Remove properties that are not applicable to Node.js sites
67+
unset($properties['drush_version']);
68+
unset($properties['php_version']);
69+
unset($properties['locked']);
70+
}
71+
return new PropertyList($properties);
72+
}
5273
}

src/Commands/Env/WakeCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function wake($site_env, $options = [
5151
]);
5252
throw new TerminusException('Could not reach {target}', $wakeStatus);
5353
}
54+
if ($env->getSite()->isNodejs()) {
55+
// We do not expect a 'styx' header for Node.js sites so if we make it here, we assume success.
56+
$this->log()->notice('OK >> {target} responded', $wakeStatus);
57+
return;
58+
}
5459
if (empty($wakeStatus['styx'])) {
5560
throw new TerminusException('Pantheon headers missing, which is not quite right.');
5661
}

src/Commands/Local/CloneCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Pantheon\Terminus\Site\SiteAwareInterface;
1010
use Pantheon\Terminus\Site\SiteAwareTrait;
1111
use Robo\Contract\ConfigAwareInterface;
12+
use Pantheon\Terminus\Exceptions\TerminusException;
1213

1314
/**
1415
* Class CloneCommand.
@@ -47,6 +48,13 @@ public function clone(
4748
array $options = ['site_dir' => null, 'override' => null, 'branch' => 'master']
4849
): string {
4950
$site = $this->getSiteById($site_id);
51+
52+
if ($site->isEvcs()) {
53+
throw new TerminusException(
54+
'This command is not supported for sites with external vcs. Please clone from your external repository.'
55+
);
56+
}
57+
5058
$env = $site->getEnvironments()->get('dev');
5159

5260
$gitUrl = $env->connectionInfo()['git_url'] ?? null;

src/Commands/Local/CommitAndPushCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ public function commitAndPushCommand($site): string
5454
);
5555
}
5656
}
57+
58+
if ($siteData->isEvcs()) {
59+
throw new TerminusException(
60+
'This command is not supported for sites with external vcs. Please push to your external repository.'
61+
);
62+
}
63+
5764
$git = new \CzProject\GitPhp\Git();
5865
$repo = $git->open($siteData->getLocalCopyDir());
5966
$repo->addAllChanges();

src/Commands/Lock/InfoCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Pantheon\Terminus\Commands\StructuredListTrait;
88
use Pantheon\Terminus\Site\SiteAwareInterface;
99
use Pantheon\Terminus\Site\SiteAwareTrait;
10+
use Pantheon\Terminus\Exceptions\TerminusException;
1011

1112
/**
1213
* Class InfoCommand.
@@ -40,6 +41,12 @@ class InfoCommand extends TerminusCommand implements SiteAwareInterface
4041
*/
4142
public function info($site_env)
4243
{
43-
return $this->getPropertyList($this->getEnv($site_env)->getLock());
44+
$env = $this->getEnv($site_env);
45+
if ($env->getSite()->isNodejs()) {
46+
throw new TerminusException(
47+
'Locking is not supported for Node.js sites.'
48+
);
49+
}
50+
return $this->getPropertyList($env->getLock());
4451
}
4552
}

src/Commands/Multidev/CreateCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public function create(
5656
) {
5757
$this->requireSiteIsNotFrozen($site_env);
5858
$site = $this->getSiteById($site_env);
59+
60+
if ($site->isEvcs()) {
61+
throw new \Pantheon\Terminus\Exceptions\TerminusException(
62+
'Multidev environments should be created from your external repository for this site.'
63+
);
64+
}
65+
5966
$env = $this->getEnv($site_env);
6067

6168
if (strlen($multidev) > 11) {

src/Commands/Multidev/DeleteCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ public function deleteMultidev($site_env, $options = ['delete-branch' => false,]
4848
return;
4949
}
5050

51+
if ($options['delete-branch'] && $env->isEvcsSite()) {
52+
$this->log()->warning(
53+
'Cannot delete the branch for {env} because it is an external version control site.',
54+
['env' => $env->getName()]
55+
);
56+
$options['delete-branch'] = false;
57+
}
58+
5159
$workflow = $env->delete(['delete_branch' => $options['delete-branch'] ?? false]);
5260
$this->processWorkflow($workflow);
5361
$this->log()->notice(

src/Commands/Remote/SSHBaseCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ protected function prepareEnvironment($site_env)
5151
{
5252
$this->site = $this->getSiteById($site_env);
5353
$this->environment = $this->getEnv($site_env);
54+
55+
if ($this->site->isNodejs()) {
56+
throw new TerminusProcessException(
57+
'This command is not supported for Node.js sites.'
58+
);
59+
}
5460
}
5561

5662
/**

src/Models/Environment.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function connectionInfo()
258258
);
259259

260260
// Can only Use Git on dev/multidev environments
261-
if (!in_array($this->id, ['test', 'live',])) {
261+
if (!in_array($this->id, ['test', 'live',]) && !$this->isEvcsSite()) {
262262
$git_info = $this->gitConnectionInfo();
263263
$info = array_merge(
264264
array_combine(
@@ -271,6 +271,13 @@ public function connectionInfo()
271271
);
272272
}
273273

274+
if (empty($info)) {
275+
throw new TerminusException(
276+
'No connection information available for {env} environment for this site.',
277+
['env' => $this->id,]
278+
);
279+
}
280+
274281
return $info;
275282
}
276283

@@ -281,6 +288,10 @@ public function connectionInfo()
281288
*/
282289
public function cacheserverConnectionInfo()
283290
{
291+
if ($this->getSite()->isNodejs()) {
292+
// No database for Node.js sites
293+
return [];
294+
}
284295
$env_vars = $this->fetchEnvironmentVars();
285296
$port = $env_vars['CACHE_PORT'] ?? null;
286297
$password = $env_vars['CACHE_PASSWORD'] ?? null;
@@ -327,6 +338,10 @@ public function fetchEnvironmentVars(): array
327338
*/
328339
public function databaseConnectionInfo()
329340
{
341+
if ($this->getSite()->isNodejs()) {
342+
// No database for Node.js sites
343+
return [];
344+
}
330345
$env_vars = $this->fetchEnvironmentVars();
331346
$domain = "dbserver.{$this->id}.{$this->getSite()->id}.drush.in";
332347
$port = $env_vars['DB_PORT'] ?? null;
@@ -965,6 +980,10 @@ public function setHttpsCertificate($certificate = [])
965980
*/
966981
public function sftpConnectionInfo()
967982
{
983+
if ($this->isEvcsSite()) {
984+
// No SFTP for EVCS sites
985+
return [];
986+
}
968987
$site = $this->getSite();
969988
if (!empty($ssh_host = $this->getConfig()->get('ssh_host'))) {
970989
$username = "appserver.{$this->id}.{$site->id}";
@@ -1021,12 +1040,18 @@ function ($domain) {
10211040
$success = false;
10221041
$lastError = null;
10231042

1043+
$wakeUrl = "https://{$domain->id}/pantheon_healthcheck";
1044+
if ($this->getSite()->isNodejs()) {
1045+
// For Node.js sites, we use the root path for the health check.
1046+
$wakeUrl = "https://{$domain->id}";
1047+
}
1048+
10241049
while ($attempt < $maxRetries && !$success) {
10251050
$lastError = null;
10261051
$attempt++;
10271052
try {
10281053
$response = $this->request()->request(
1029-
"https://{$domain->id}/pantheon_healthcheck"
1054+
$wakeUrl,
10301055
);
10311056
$success = ($response['status_code'] === 200);
10321057
if ($success) {

src/Models/Site.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,4 +589,31 @@ public function getWorkflowLogs(): WorkflowLogsCollection
589589
->addArgument($this);
590590
return $this->getContainer()->get($nickname)->fetch();
591591
}
592+
593+
/**
594+
* @return bool
595+
* @throws TerminusException
596+
*/
597+
public function isEvcs(): bool
598+
{
599+
// We are using a variable that we retrieve at environment level,
600+
// so we need to retrieve dev environment first.
601+
$env = $this->getEnvironments()->get('dev');
602+
if (empty($env)) {
603+
throw new TerminusException(
604+
'Site {site} does not have a dev environment.',
605+
['site' => $this->getName()]
606+
);
607+
}
608+
return $env->isEvcsSite();
609+
}
610+
611+
/**
612+
* @return bool
613+
* @throws TerminusException
614+
*/
615+
public function isNodejs(): bool
616+
{
617+
return $this->get('framework') === 'nodejs';
618+
}
592619
}

0 commit comments

Comments
 (0)