-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(provisioning): Adding missing migration to ensure the uniqueness of server names at DB level * feat: Add service and command for provisioning of servers * feat(provisioning): Provision server pools * feat(provisioning): Provision room types * test(provisioning): Add tests for server provisioning * impr(provisioning): Use Laravel validators for input validation * test(provisioning): Add server deletion tests * test(provisioning): Add server pool create + delete tests * test(provisioning): Add room type create + delete tests * feat(provisioning): Implement role provisioning * feat(provisioning): Implement user provisioning * feat(provisioning): Implemment settings provisioning * test(provisioning): Add integration test for provisioning command * impr(provisioning): Harden input validations * doc(provisioning): Update changelog * impr(provisioning): Use models' getLogLabel() function; add it where necessary * impr(provisioning): Add helper function for creation log messages * impr(provisioning): Make all role permissions optional * doc(provisioning): Add documentation * impr(provisioning): Use constructors to configure provisioners * impr(provisioning): Optimize DB query in destroy wrapper function * impr(provisioning): Simplify server status enum mapping * clean(provisioning): Remove check made obsolete by input validation * fix(provisioning): Repair "distinct" validations and add tests * impr(ProvisionCommand): Wrap provisioning in DB transaction * impr(provisioning): Properly validate user locale and timezone * fix(provisioning): Sort permissions in user creation test * impr(provisioning): Use UpdateSettings validation rules; fix test data * impr(provisioning): Use constructor property promotion * impr(provisioning): Enforce hex color * doc(provision): Update and clarify documentation * impr(provisioning): Use laravel prompt helpers for log messages --------- Co-authored-by: Samuel Weirich <[email protected]>
- Loading branch information
Showing
11 changed files
with
1,391 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Services\ProvisioningService; | ||
use Exception; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
use function Laravel\Prompts\error; | ||
use function Laravel\Prompts\info; | ||
|
||
class ProvisionCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'provision:all {path : path to a JSON file containing provisioning data}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Provision this PILOS instance'; | ||
|
||
public function __construct(protected ProvisioningService $provision) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$data = json_decode(file_get_contents($this->argument('path'))); | ||
|
||
try { | ||
DB::beginTransaction(); | ||
|
||
// Wipe existing data (order is important!) | ||
if ($data->room_types->wipe) { | ||
$this->provision->roomType->destroy(); | ||
} | ||
if ($data->server_pools->wipe) { | ||
$this->provision->serverPool->destroy(); | ||
} | ||
if ($data->servers->wipe) { | ||
$this->provision->server->destroy(); | ||
} | ||
if ($data->roles->wipe) { | ||
$this->provision->role->destroy(); | ||
} | ||
if ($data->users->wipe) { | ||
$this->provision->user->destroy(); | ||
} | ||
|
||
// Add new instances | ||
$n = count($data->servers->add); | ||
info("Provisioning $n servers"); | ||
foreach ($data->servers->add as $item) { | ||
$this->provision->server->create($item); | ||
} | ||
|
||
$n = count($data->server_pools->add); | ||
info("Provisioning $n server pools"); | ||
foreach ($data->server_pools->add as $item) { | ||
$this->provision->serverPool->create($item); | ||
} | ||
|
||
$n = count($data->room_types->add); | ||
info("Provisioning $n room types"); | ||
foreach ($data->room_types->add as $item) { | ||
$this->provision->roomType->create($item); | ||
} | ||
|
||
$n = count($data->roles->add); | ||
info("Provisioning $n roles"); | ||
foreach ($data->roles->add as $item) { | ||
$item->permissions = (array) $item->permissions; | ||
$this->provision->role->create($item); | ||
} | ||
|
||
$n = count($data->users->add); | ||
info("Provisioning $n users"); | ||
foreach ($data->users->add as $item) { | ||
$this->provision->user->create($item); | ||
} | ||
|
||
$n = array_sum(array_map(fn ($v) => count(get_object_vars($v)), get_object_vars($data->settings))); | ||
info("Provisioning $n settings"); | ||
foreach (get_object_vars($data->settings) as $section => $settings) { | ||
$data->settings->{$section} = (array) $settings; | ||
} | ||
$this->provision->settings->set($data->settings); | ||
|
||
DB::commit(); | ||
} catch (Exception $err) { | ||
error("Provisioning failed, aborting transaction: {$err->getMessage()}"); | ||
DB::rollBack(); | ||
|
||
return 1; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.