Skip to content

Commit bd32715

Browse files
committed
Do not require SSH permission to list mounts
1 parent 7273878 commit bd32715

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

src/Command/Mount/MountListCommand.php

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace Platformsh\Cli\Command\Mount;
44

55
use Platformsh\Cli\Command\CommandBase;
6-
use Platformsh\Cli\Model\AppConfig;
76
use Platformsh\Cli\Model\Host\LocalHost;
7+
use Platformsh\Cli\Model\RemoteContainer\BrokenEnv;
8+
use Platformsh\Cli\Model\RemoteContainer\Worker;
89
use Platformsh\Cli\Service\Table;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Input\InputOption;
@@ -36,23 +37,48 @@ protected function configure()
3637
*/
3738
protected function execute(InputInterface $input, OutputInterface $output)
3839
{
39-
$host = $this->selectHost($input, getenv($this->config()->get('service.env_prefix') . 'APPLICATION'));
4040
/** @var \Platformsh\Cli\Service\Mount $mountService */
4141
$mountService = $this->getService('mount');
42-
if ($host instanceof LocalHost) {
43-
/** @var \Platformsh\Cli\Service\RemoteEnvVars $envVars */
44-
$envVars = $this->getService('remote_env_vars');
45-
$config = (new AppConfig($envVars->getArrayEnvVar('APPLICATION', $host)));
42+
if (($applicationEnv = getenv($this->config()->get('service.env_prefix') . 'APPLICATION'))
43+
&& !LocalHost::conflictsWithCommandLineOptions($input, $this->config()->get('service.env_prefix'))) {
44+
$this->debug('Selected host: localhost');
45+
$config = json_decode(base64_decode($applicationEnv), true) ?: [];
4646
$mounts = $mountService->mountsFromConfig($config);
47+
$appName = $config['name'];
48+
$appType = strpos($appName, '--') !== false ? 'worker' : 'app';
49+
if (empty($mounts)) {
50+
$this->stdErr->writeln(sprintf(
51+
'No mounts found in config variable: <info>%s</info>',
52+
$this->config()->get('service.env_prefix') . 'APPLICATION'
53+
));
54+
55+
return 0;
56+
}
4757
} else {
58+
$this->chooseEnvFilter = $this->filterEnvsMaybeActive();
59+
$this->validateInput($input);
60+
$environment = $this->getSelectedEnvironment();
4861
$container = $this->selectRemoteContainer($input);
62+
if ($container instanceof BrokenEnv) {
63+
$this->stdErr->writeln(sprintf(
64+
'Unable to find deployment information for the environment: %s',
65+
$this->api()->getEnvironmentLabel($environment, 'error')
66+
));
67+
return 1;
68+
}
4969
$mounts = $mountService->mountsFromConfig($container->getConfig());
50-
}
51-
52-
if (empty($mounts)) {
53-
$this->stdErr->writeln(sprintf('No mounts found on host: <info>%s</info>', $host->getLabel()));
70+
$appName = $container->getName();
71+
$appType = $container instanceof Worker ? 'worker' : 'app';
72+
if (empty($mounts)) {
73+
$this->stdErr->writeln(sprintf(
74+
'No mounts found on environment %s, %s <info>%s</info>',
75+
$this->api()->getEnvironmentLabel($environment),
76+
$appType,
77+
$appName
78+
));
5479

55-
return 1;
80+
return 0;
81+
}
5682
}
5783

5884
if ($input->getOption('paths')) {
@@ -70,7 +96,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
7096

7197
/** @var \Platformsh\Cli\Service\Table $table */
7298
$table = $this->getService('table');
73-
$this->stdErr->writeln(sprintf('Mounts on <info>%s</info>:', $host->getLabel()));
99+
if ($this->hasSelectedEnvironment()) {
100+
$this->stdErr->writeln(sprintf('Mounts on environment %s, %s <info>%s</info>:',
101+
$this->api()->getEnvironmentLabel($this->getSelectedEnvironment()),
102+
$appType,
103+
$appName
104+
));
105+
} else {
106+
$this->stdErr->writeln(sprintf('Mounts on %s <info>%s</info>:', $appType, $appName));
107+
}
74108
$table->render($rows, $this->tableHeader);
75109

76110
return 0;

0 commit comments

Comments
 (0)