Skip to content

Commit 4de1586

Browse files
committed
fix: can only create databases for public database servers
1 parent bc5bf33 commit 4de1586

9 files changed

Lines changed: 13 additions & 7 deletions

grumphp.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ grumphp:
2929
phplint: ~
3030
phpmd:
3131
exclude:
32+
- 'Command/Project/InitializeProjectCommand.php'
3233
- 'ApiClient.php'
3334
- 'activate-ymir-plugin.php'
3435
ruleset: ['phpmd.xml']

src/Command/AbstractCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Console\Output\OutputInterface;
2323
use Ymir\Cli\ApiClient;
2424
use Ymir\Cli\CliConfiguration;
25+
use Ymir\Cli\Command\Provider\ConnectProviderCommand;
2526
use Ymir\Cli\Console\ConsoleOutput;
2627
use Ymir\Cli\Exception\ApiClientException;
2728
use Ymir\Cli\Exception\CommandCancelledException;
@@ -80,6 +81,10 @@ protected function determineCloudProvider(string $question, InputInterface $inpu
8081
$providers = collect([$this->apiClient->getProject($this->projectConfiguration->getProjectId())->get('provider')]);
8182
}
8283

84+
if ($providers->isEmpty()) {
85+
throw new RuntimeException(sprintf('There are no cloud providers connected to currently active team. You can connect to one using the "%s" command.', ConnectProviderCommand::NAME));
86+
}
87+
8388
return 1 === count($providers) ? $providers[0]['id'] : $output->choiceWithId($question, $providers);
8489
}
8590

src/Command/Database/CreateDatabaseCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function configure()
3333
{
3434
$this
3535
->setName(self::NAME)
36-
->setDescription('Create a new database on a database server')
36+
->setDescription('Create a new database on a public database server')
3737
->addArgument('database', InputArgument::OPTIONAL, 'The ID or name of the database server where the database will be created')
3838
->addArgument('name', InputArgument::OPTIONAL, 'The username of the new database user');
3939
}

src/Command/Database/CreateDatabaseUserCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function configure()
3333
{
3434
$this
3535
->setName(self::NAME)
36-
->setDescription('Create a new user on a database server')
36+
->setDescription('Create a new user on a public database server')
3737
->addArgument('database', InputArgument::OPTIONAL, 'The ID or name of the database server where the user will be created')
3838
->addArgument('username', InputArgument::OPTIONAL, 'The username of the new database user');
3939
}

src/Command/Database/DeleteDatabaseCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function configure()
3333
{
3434
$this
3535
->setName(self::NAME)
36-
->setDescription('Delete a database on a database server')
36+
->setDescription('Delete a database on a public database server')
3737
->addArgument('database', InputArgument::OPTIONAL, 'The ID or name of the database server where the database will be deleted')
3838
->addArgument('name', InputArgument::OPTIONAL, 'The username of the new database user');
3939
}

src/Command/Database/DeleteDatabaseUserCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function configure()
3434
{
3535
$this
3636
->setName(self::NAME)
37-
->setDescription('Create a new user on a database')
37+
->setDescription('Create a new user on a public database')
3838
->addArgument('database', InputArgument::OPTIONAL, 'The ID or name of the database server where the database user will be deleted')
3939
->addArgument('username', InputArgument::OPTIONAL, 'The username of the new database user');
4040
}

src/Command/Database/ListDatabaseUsersCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function configure()
3434
{
3535
$this
3636
->setName(self::NAME)
37-
->setDescription('List all the managed users on a database server')
37+
->setDescription('List all the managed users on a public database server')
3838
->addArgument('database', InputArgument::OPTIONAL, 'The ID or name of the database server to list users from');
3939
}
4040

src/Command/Database/ListDatabasesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function configure()
3333
{
3434
$this
3535
->setName(self::NAME)
36-
->setDescription('List all the databases on a database server')
36+
->setDescription('List all the databases on a public database server')
3737
->addArgument('database', InputArgument::OPTIONAL, 'The ID or name of the database server to list users from');
3838
}
3939

src/Command/Project/InitializeProjectCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private function addEnvironmentDatabaseNodes(array $environments, ConsoleOutput
151151

152152
if (empty($databaseServer['name'])) {
153153
return $environments;
154-
} elseif ($output->confirm(sprintf('Would you like to create staging and production databases for your project on the "<comment>%s</comment>" database server?', $databaseServer['name']))) {
154+
} elseif (!empty($databaseServer['publicly_accessible']) && $output->confirm(sprintf('Would you like to create staging and production databases for your project on the "<comment>%s</comment>" database server?', $databaseServer['name']))) {
155155
$databasePrefix = $output->askSlug('What database prefix would you like to use for this project?', $projectName);
156156
}
157157

0 commit comments

Comments
 (0)