-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add own action class for "rotate database password" (#822)
- Loading branch information
Showing
6 changed files
with
89 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/Filament/Components/Forms/Actions/RotateDatabasePasswordAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Filament\Components\Forms\Actions; | ||
|
||
use App\Models\Database; | ||
use App\Services\Databases\DatabasePasswordService; | ||
use Exception; | ||
use Filament\Actions\StaticAction; | ||
use Filament\Forms\Components\Actions\Action; | ||
use Filament\Forms\Set; | ||
use Filament\Notifications\Notification; | ||
|
||
class RotateDatabasePasswordAction extends Action | ||
{ | ||
public static function getDefaultName(): ?string | ||
{ | ||
return 'rotate'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->label('Rotate'); | ||
|
||
$this->icon('tabler-refresh'); | ||
|
||
$this->authorize(fn (Database $database) => auth()->user()->can('update database', $database)); | ||
|
||
$this->modalHeading('Rotate Password'); | ||
|
||
$this->modalIconColor('warning'); | ||
|
||
$this->modalSubmitAction(fn (StaticAction $action) => $action->color('warning')); | ||
|
||
$this->requiresConfirmation(); | ||
|
||
$this->action(function (DatabasePasswordService $service, Database $database, Set $set) { | ||
try { | ||
$service->handle($database); | ||
|
||
$database->refresh(); | ||
|
||
$set('password', $database->password); | ||
$set('jdbc', $database->jdbc); | ||
|
||
Notification::make() | ||
->title('Password rotated') | ||
->success() | ||
->send(); | ||
} catch (Exception $exception) { | ||
Notification::make() | ||
->title('Password rotation failed') | ||
->body($exception->getMessage()) | ||
->danger() | ||
->send(); | ||
|
||
report($exception); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters