Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support to RDS Proxies #77

Merged
merged 3 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Commands/DatabaseDeleteProxyCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Laravel\VaporCli\Commands;

use Laravel\VaporCli\Helpers;
use Symfony\Component\Console\Input\InputArgument;

class DatabaseDeleteProxyCommand extends Command
{
/**
* Configure the command options.
*
* @return void
*/
protected function configure()
{
$this
->setName('database:delete-proxy')
->addArgument('database', InputArgument::REQUIRED, 'The name of the database')
->setDescription('Delete the proxy associated to the database.');
}

/**
* Execute the command.
*
* @return void
*/
public function handle()
{
Helpers::ensure_api_token_is_available();

$databases = $this->vapor->databases();

if (!is_numeric($databaseId = $this->argument('database'))) {
$databaseId = $this->findIdByName($databases, $databaseId);
}

if (is_null($databaseId)) {
Helpers::abort('Unable to find a database with that name / ID.');
}

$response = $this->vapor->deleteDatabaseProxy(
$databaseId
);

Helpers::info('Database proxy deleted successfully.');
}
}
3 changes: 2 additions & 1 deletion src/Commands/DatabaseListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle()
Helpers::ensure_api_token_is_available();

$this->table([
'ID', 'Provider', 'Name', 'Region', 'Type', 'Class', 'Storage', 'Status',
'ID', 'Provider', 'Name', 'Region', 'Type', 'Class', 'Storage', 'Status', 'Proxy',
], collect($this->vapor->databases())->map(function ($database) {
return [
$database['id'],
Expand All @@ -40,6 +40,7 @@ public function handle()
$database['instance_class'],
$database['storage'].'GB',
Str::title(str_replace('_', ' ', $database['status'])),
$database['proxy'] ? Str::title(str_replace('_', ' ', $database['proxy']['status'])) : 'No',
];
})->all());
}
Expand Down
48 changes: 48 additions & 0 deletions src/Commands/DatabaseProxyCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Laravel\VaporCli\Commands;

use Laravel\VaporCli\Helpers;
use Symfony\Component\Console\Input\InputArgument;

class DatabaseProxyCommand extends Command
{
/**
* Configure the command options.
*
* @return void
*/
protected function configure()
{
$this
->setName('database:proxy')
->addArgument('database', InputArgument::REQUIRED, 'The name of the database')
->setDescription('Create an proxy for a database');
}

/**
* Execute the command.
*
* @return void
*/
public function handle()
{
Helpers::ensure_api_token_is_available();

$databases = $this->vapor->databases();

if (!is_numeric($databaseId = $this->argument('database'))) {
$databaseId = $this->findIdByName($databases, $databaseId);
}

if (is_null($databaseId)) {
Helpers::abort('Unable to find a database with that name / ID.');
}

$response = $this->vapor->createDatabaseProxy(
$databaseId
);

Helpers::info('Database proxy created successfully.');
}
}
24 changes: 24 additions & 0 deletions src/ConsoleVaporClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,30 @@ public function dropDatabaseUser($databaseUserId)
$this->requestWithErrorHandling('delete', '/api/database-users/'.$databaseUserId);
}

/**
* Create a new database proxy.
*
* @param string $databaseId
*
* @return array
*/
public function createDatabaseProxy($databaseId)
{
return $this->requestWithErrorHandling('post', '/api/databases/'.$databaseId.'/proxy');
}

/**
* Delete the proxy associated to the given database.
*
* @param string $databaseId
*
* @return void
*/
public function deleteDatabaseProxy($databaseId)
{
$this->requestWithErrorHandling('delete', '/api/databases/'.$databaseId.'/proxy');
}

/**
* Rotate the given database's password.
*
Expand Down
2 changes: 2 additions & 0 deletions vapor
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ $app->add(new Commands\DatabaseCommand);
$app->add(new Commands\DatabaseShowCommand);
$app->add(new Commands\DatabaseScaleCommand);
$app->add(new Commands\DatabasePasswordCommand);
$app->add(new Commands\DatabaseProxyCommand);
$app->add(new Commands\DatabaseDeleteProxyCommand);
$app->add(new Commands\DatabaseRestoreCommand);
$app->add(new Commands\DatabaseMetricsCommand);
$app->add(new Commands\DatabaseUsersCommand);
Expand Down