From ea5dcebe452d0803c3eed6b3f5eb01f97967321e Mon Sep 17 00:00:00 2001 From: Harry Bayliss Date: Thu, 22 May 2025 13:38:56 +0100 Subject: [PATCH] service credentials --- app/Actions/Services/CreateService.php | 6 ++++-- app/Drivers/Caddy/Caddy2Driver.php | 5 ++++- app/Drivers/Driver.php | 2 +- app/Drivers/GatewayDriver.php | 2 +- app/Models/Service.php | 12 +++++++++--- resources/js/pages/services/Create.vue | 24 ++++++++++-------------- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app/Actions/Services/CreateService.php b/app/Actions/Services/CreateService.php index 8064ffa..9307443 100644 --- a/app/Actions/Services/CreateService.php +++ b/app/Actions/Services/CreateService.php @@ -27,8 +27,10 @@ class CreateService 'status' => ServiceStatus::NOT_INSTALLED, ]); - $service->credentials = $service->driver()->defaultCredentials(); - $service->save(); + if (method_exists($service->driver(), 'defaultCredentials')) { + $service->credentials = $service->driver()->defaultCredentials(); + $service->save(); + } dispatch(new DeployService($service)); diff --git a/app/Drivers/Caddy/Caddy2Driver.php b/app/Drivers/Caddy/Caddy2Driver.php index d026f88..8714103 100644 --- a/app/Drivers/Caddy/Caddy2Driver.php +++ b/app/Drivers/Caddy/Caddy2Driver.php @@ -31,6 +31,7 @@ class Caddy2Driver extends GatewayDriver $script->push('cd services'); $script->push("test -d {$this->service->id} || mkdir {$this->service->id}"); $script->push("cd {$this->service->id}"); + return $script->join("\n"); } ), new Step( @@ -49,7 +50,9 @@ class Caddy2Driver extends GatewayDriver } $runCommand .= ' -p 80:80 -p 443:443 caddy:2'; - return $runCommand; + $script->push($runCommand); + + return $script->join("\n"); } ), ]); diff --git a/app/Drivers/Driver.php b/app/Drivers/Driver.php index 27277c9..218e56b 100644 --- a/app/Drivers/Driver.php +++ b/app/Drivers/Driver.php @@ -18,6 +18,6 @@ abstract class Driver abstract public function __construct( ?string $containerName = null, ?string $containerId = null, - ?int $service = null, + ?Service $service = null, ); } diff --git a/app/Drivers/GatewayDriver.php b/app/Drivers/GatewayDriver.php index c70f833..a71c757 100644 --- a/app/Drivers/GatewayDriver.php +++ b/app/Drivers/GatewayDriver.php @@ -15,4 +15,4 @@ abstract class GatewayDriver extends Driver ?string $containerId = null, ?Service $service = null, ); -} \ No newline at end of file +} diff --git a/app/Models/Service.php b/app/Models/Service.php index 77d1166..84221be 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Drivers\DatabaseDriver; use App\Drivers\Driver; use App\Enums\ServiceCategory; use App\Enums\ServiceStatus; @@ -57,11 +58,16 @@ class Service extends Model throw new \Exception("Driver class {$class} not found"); } - return new $class( + $driver = new $class( containerName: $this->container_name, containerId: $this->container_id, - serviceId: $this->id, - credentials: $this->credentials + service: $this, ); + + if ($driver instanceof DatabaseDriver) { + $driver->credentials = $this->credentials; + } + + return $driver; } } diff --git a/resources/js/pages/services/Create.vue b/resources/js/pages/services/Create.vue index 3a9e0a1..2aeb9a6 100644 --- a/resources/js/pages/services/Create.vue +++ b/resources/js/pages/services/Create.vue @@ -17,7 +17,7 @@ const props = defineProps({ const form = useForm({ name: null, category: null, - service: null, + type: null, version: null, }); @@ -45,8 +45,8 @@ function generateServiceName() { str += form.category.toLowerCase() + '-'; } - if (form.service) { - str += form.service.toLowerCase() + '-'; + if (form.type) { + str += form.type.toLowerCase() + '-'; } if (form.version) { @@ -56,7 +56,7 @@ function generateServiceName() { return str; } -watch([() => form.category, () => form.service, () => form.version], () => { +watch([() => form.category, () => form.type, () => form.version], () => { form.name = generateServiceName(); }); @@ -98,20 +98,14 @@ watch([() => form.category, () => form.service, () => form.version], () => {
- +

{{ service.name }}

-
+
form.category, () => form.service, () => form.version], () => {
- +