Implement Webhooks (#548)

* feat: First Webhook PoC draft

* feat: Dispatch Webhooks PoC

* fix: typo in webhook configuration scope

* Update 2024_04_21_162552_create_webhooks_table.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update 2024_04_21_162552_create_webhooks_table.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update 2024_04_21_162544_create_webhook_configurations_table.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update 2024_04_21_162544_create_webhook_configurations_table.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update DispatchWebhooks.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update DispatchWebhooksJob.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update DispatchWebhookForConfiguration.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update DispatchWebhookForConfiguration.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update DispatchWebhookForConfiguration.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update DispatchWebhooksJob.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update DispatchWebhooksJob.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* Update DispatchWebhooksJob.php

Co-authored-by: Lance Pioch <lancepioch@gmail.com>

* chore: Implement Webhook Event Discovery

* we got a test working for webhooks

* WIP

* Something is working!

* More tests

* clean up the tests now that they are passing

* WIP

* Don't use model specific events

* WIP

* WIP

* WIP

* WIP

* WIP

* Do it sync

* Reset these

* Don't need restored event type

* Deleted some unused jobs

* Find custom Events

* Remove observers

* Add custom event test

* Run Pint

* Add caching

* Don't cache every single event

* Fix tests

* Run Pint

* Phpstan fixes

* Pint fix

* Test fixes

* Middleware unit test fix

* Pint fixes

* Remove index not working for older dbs

* Use facade instead

---------

Co-authored-by: Pascale Beier <mail@pascalebeier.de>
Co-authored-by: Lance Pioch <lancepioch@gmail.com>
Co-authored-by: Vehikl <go@vehikl.com>
This commit is contained in:
Colin DeCarlo
2024-10-26 20:35:25 -04:00
committed by GitHub
parent 5f77deb1fd
commit 86c369d7ce
46 changed files with 781 additions and 536 deletions

View File

@@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\Node;
use App\Models\Server;
use App\Models\Allocation;
use Illuminate\Database\Eloquent\Factories\Factory;
@@ -23,6 +24,7 @@ class AllocationFactory extends Factory
return [
'ip' => $this->faker->unique()->ipv4(),
'port' => $this->faker->unique()->numberBetween(1024, 65535),
'node_id' => Node::factory(),
];
}

View File

@@ -22,6 +22,12 @@ class EggFactory extends Factory
{
return [
'uuid' => Uuid::uuid4()->toString(),
'author' => $this->faker->email(),
'docker_images' => ['a', 'b', 'c'],
'config_logs' => '{}',
'config_startup' => '{}',
'config_stop' => '{}',
'config_files' => '{}',
'name' => $this->faker->name(),
'description' => implode(' ', $this->faker->sentences()),
'startup' => 'java -jar test.jar',

View File

@@ -40,6 +40,7 @@ class NodeFactory extends Factory
'daemon_listen' => 8080,
'daemon_sftp' => 2022,
'daemon_base' => '/var/lib/panel/volumes',
'maintenance_mode' => false,
];
}
}

View File

@@ -2,6 +2,10 @@
namespace Database\Factories;
use App\Models\Allocation;
use App\Models\Egg;
use App\Models\Node;
use App\Models\User;
use Carbon\Carbon;
use Ramsey\Uuid\Uuid;
use Illuminate\Support\Str;
@@ -17,12 +21,28 @@ class ServerFactory extends Factory
*/
protected $model = Server::class;
public function withNode(?Node $node = null): static
{
$node ??= Node::factory()->create();
return $this->state(fn () => [
'node_id' => $node->id,
'allocation_id' => Allocation::factory([
'node_id' => $node->id,
]),
]);
}
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'owner_id' => User::factory(),
'node_id' => Node::factory(),
'allocation_id' => Allocation::factory(),
'egg_id' => Egg::factory(),
'uuid' => Uuid::uuid4()->toString(),
'uuid_short' => Str::lower(Str::random(8)),
'name' => $this->faker->firstName(),

View File

@@ -0,0 +1,20 @@
<?php
namespace Database\Factories;
use App\Models\WebhookConfiguration;
use Illuminate\Database\Eloquent\Factories\Factory;
class WebhookConfigurationFactory extends Factory
{
protected $model = WebhookConfiguration::class;
public function definition(): array
{
return [
'endpoint' => fake()->url(),
'description' => fake()->sentence(),
'events' => [],
];
}
}