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

WIP: Provisioning service #1678

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e1c2b10
feat: Add service and command for provisioning of servers
pizkaz Dec 6, 2024
7026944
feat(provisioning): Provision server pools
pizkaz Dec 10, 2024
5fc591e
feat(provisioning): Provision room types
pizkaz Dec 10, 2024
b8722a8
test(provisioning): Add tests for server provisioning
pizkaz Dec 10, 2024
7ae0cd2
impr(provisioning): Use Laravel validators for input validation
pizkaz Dec 11, 2024
83c103e
test(provisioning): Add server deletion tests
pizkaz Dec 12, 2024
2f99a3a
test(provisioning): Add server pool create + delete tests
pizkaz Dec 14, 2024
13de4b6
test(provisioning): Add room type create + delete tests
pizkaz Dec 14, 2024
55ba2b0
feat(provisioning): Implement role provisioning
pizkaz Dec 16, 2024
b4b9752
feat(provisioning): Implement user provisioning
pizkaz Dec 16, 2024
e8e7b99
feat(provisioning): Implemment settings provisioning
pizkaz Dec 16, 2024
a9c2766
test(provisioning): Add integration test for provisioning command
pizkaz Dec 16, 2024
1c5651f
fix(provisioning): Adding missing migration to ensure the uniqueness …
SamuelWei Dec 19, 2024
f91d7ce
impr(provisioning): Harden input validations
pizkaz Jan 6, 2025
6919297
doc(provisioning): Update changelog
pizkaz Jan 6, 2025
365a677
impr(provisioning): Use models' getLogLabel() function; add it where …
pizkaz Jan 6, 2025
f9edfd5
impr(provisioning): Add helper function for creation log messages
pizkaz Jan 6, 2025
c585423
impr(provisioning): Make all role permissions optional
pizkaz Jan 6, 2025
ba1e2b8
doc(provisioning): Add documentation
pizkaz Jan 6, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Artisan command for provisioning via JSON file ([#1636], [#1678])

## [v4.2.0] - 2025-01-06

### Added
Expand Down
89 changes: 89 additions & 0 deletions app/Console/Commands/ProvisionCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace App\Console\Commands;

use App\Services\ProvisioningService;
use Illuminate\Console\Command;
use Log;

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')));

// 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
Log::notice('Provisioning {n} servers', ['n' => count($data->servers->add)]);
foreach ($data->servers->add as $item) {
$this->provision->server->create($item);
}

Log::notice('Provisioning {n} server pools', ['n' => count($data->server_pools->add)]);
foreach ($data->server_pools->add as $item) {
$this->provision->serverPool->create($item);
}

Log::notice('Provisioning {n} room types', ['n' => count($data->room_types->add)]);
foreach ($data->room_types->add as $item) {
$this->provision->roomType->create($item);
}

Log::notice('Provisioning {n} roles', ['n' => count($data->roles->add)]);
foreach ($data->roles->add as $item) {
$item->permissions = (array) $item->permissions;
$this->provision->role->create($item);
}

Log::notice('Provisioning {n} users', ['n' => count($data->users->add)]);
foreach ($data->users->add as $item) {
$this->provision->user->create($item);
}

$n = count(get_object_vars($data->settings->general))
+ count(get_object_vars($data->settings->recording));
Log::notice('Provisioning {n} settings', ['n' => $n]);
foreach (get_object_vars($data->settings) as $section => $settings) {
$data->settings->{$section} = (array) $settings;
}
$this->provision->settings->set($data->settings);
}
}
5 changes: 5 additions & 0 deletions app/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public function scopeWithName(Builder $query, $name)
{
return $query->whereLike('name', '%'.$name.'%');
}

public function getLogLabel()
{
return $this->name.' ('.$this->id.')';
}
}
5 changes: 5 additions & 0 deletions app/Models/RoomType.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public function serverPool()
{
return $this->belongsTo(ServerPool::class);
}

public function getLogLabel()
{
return $this->name.' ('.$this->id.')';
}
}
5 changes: 5 additions & 0 deletions app/Models/ServerPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ public function scopeWithName(Builder $query, $name)
{
return $query->whereLike('name', '%'.$name.'%');
}

public function getLogLabel()
{
return $this->name.' ('.$this->id.')';
}
}
Loading