Skip to content

Commit 8d4227e

Browse files
committed
fix: add warnings when dealing with users on a private database
1 parent 04ebe6f commit 8d4227e

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/Command/Database/CreateDatabaseUserCommand.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,30 @@ protected function configure()
4343
*/
4444
protected function perform(InputInterface $input, ConsoleOutput $output)
4545
{
46-
$databaseId = $this->determineDatabaseServer('On which database server would you like to create the new database user?', $input, $output);
4746
$databases = [];
47+
$databaseServer = $this->apiClient->getDatabaseServer($this->determineDatabaseServer('On which database server would you like to create the new database user?', $input, $output));
4848
$username = $this->getStringArgument($input, 'username');
4949

5050
if (empty($username) && $input->isInteractive()) {
5151
$username = $output->ask('What is the username of the new database user');
5252
}
5353

54-
if (!$output->confirm('Do you want to the new user to have access to all databases?', false)) {
55-
$databases = $output->multichoice('Please enter the comma-separated list of databases that you want the user to have access to', $this->apiClient->getDatabases($databaseId)->all());
54+
if ($databaseServer['publicly_accessible'] && !$output->confirm('Do you want to the new user to have access to all databases?', false)) {
55+
$databases = $output->multichoice('Please enter the comma-separated list of databases that you want the user to have access to', $this->apiClient->getDatabases($databaseServer['id'])->all());
5656
}
5757

58-
$user = $this->apiClient->createDatabaseUser($databaseId, $username, $databases);
58+
$user = $this->apiClient->createDatabaseUser($databaseServer['id'], $username, $databases);
5959

6060
$output->horizontalTable(
6161
['Username', 'Password'],
6262
[[$user['username'], $user['password']]]
6363
);
6464

6565
$output->info('Database user created');
66+
67+
if (!$databaseServer['publicly_accessible']) {
68+
$output->newLine();
69+
$output->warn('The database user needs to be manually created on the database server because it isn\'t public');
70+
}
6671
}
6772
}

src/Command/Database/DeleteDatabaseUserCommand.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ protected function configure()
4444
*/
4545
protected function perform(InputInterface $input, ConsoleOutput $output)
4646
{
47-
$databaseId = $this->determineDatabaseServer('On which database server would you like to delete a database user?', $input, $output);
47+
$databaseServer = $this->apiClient->getDatabaseServer($this->determineDatabaseServer('On which database server would you like to create the new database user?', $input, $output));
4848
$username = $this->getStringArgument($input, 'username');
49-
$users = $this->apiClient->getDatabaseUsers($databaseId);
49+
$users = $this->apiClient->getDatabaseUsers($databaseServer['id']);
5050

5151
if ($users->isEmpty()) {
5252
throw new InvalidArgumentException('The database server doesn\'t have any managed database users');
@@ -64,8 +64,13 @@ protected function perform(InputInterface $input, ConsoleOutput $output)
6464
return;
6565
}
6666

67-
$this->apiClient->deleteDatabaseUser($databaseId, $user['id']);
67+
$this->apiClient->deleteDatabaseUser($databaseServer['id'], $user['id']);
6868

6969
$output->info('Database user deleted');
70+
71+
if (!$databaseServer['publicly_accessible']) {
72+
$output->newLine();
73+
$output->warn('The database user needs to be manually deleted on the database server because it isn\'t public');
74+
}
7075
}
7176
}

0 commit comments

Comments
 (0)