Skip to content

Commit

Permalink
Adds support to RDS Proxies (#77)
Browse files Browse the repository at this point in the history
* wip

* wip

* Apply fixes from StyleCI (#76)
  • Loading branch information
nunomaduro authored Oct 13, 2020
1 parent 51e0201 commit 30623f9
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 1 deletion.
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

0 comments on commit 30623f9

Please sign in to comment.