new changes
This commit is contained in:
107
panel-api/app/Modules/Site/HostingCommandFactory.php
Normal file
107
panel-api/app/Modules/Site/HostingCommandFactory.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Site;
|
||||
|
||||
class HostingCommandFactory
|
||||
{
|
||||
public function buildCreateSite(string $tenantId, array $input, string $webserver): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'type' => 'SITE_CREATE',
|
||||
'idempotency_key' => $input['idempotency_key'] ?? uniqid('site_create_', true),
|
||||
'args' => [
|
||||
'server_id' => $input['server_id'] ?? null,
|
||||
'site_name' => $input['site_name'] ?? null,
|
||||
'domain' => $input['domain'] ?? null,
|
||||
'root_path' => $input['root_path'] ?? null,
|
||||
'webserver' => $webserver,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function buildUpdateSite(string $tenantId, string $siteId, array $input): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'type' => 'SITE_UPDATE',
|
||||
'idempotency_key' => $input['idempotency_key'] ?? uniqid('site_update_', true),
|
||||
'args' => [
|
||||
'site_id' => $siteId,
|
||||
'server_id' => $input['server_id'] ?? null,
|
||||
'changes' => $input['changes'] ?? [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function buildDeleteSite(string $tenantId, string $siteId, array $input): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'type' => 'SITE_DELETE',
|
||||
'idempotency_key' => $input['idempotency_key'] ?? uniqid('site_delete_', true),
|
||||
'args' => [
|
||||
'site_id' => $siteId,
|
||||
'server_id' => $input['server_id'] ?? null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function buildAddDomain(string $tenantId, string $siteId, array $input): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'type' => 'DOMAIN_ADD',
|
||||
'idempotency_key' => $input['idempotency_key'] ?? uniqid('domain_add_', true),
|
||||
'args' => [
|
||||
'site_id' => $siteId,
|
||||
'server_id' => $input['server_id'] ?? null,
|
||||
'domain' => $input['domain'] ?? null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function buildRemoveDomain(string $tenantId, string $siteId, string $domainId, array $input): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'type' => 'DOMAIN_REMOVE',
|
||||
'idempotency_key' => $input['idempotency_key'] ?? uniqid('domain_remove_', true),
|
||||
'args' => [
|
||||
'site_id' => $siteId,
|
||||
'domain_id' => $domainId,
|
||||
'server_id' => $input['server_id'] ?? null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function buildIssueSsl(string $tenantId, array $input): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'type' => 'SSL_ISSUE',
|
||||
'idempotency_key' => $input['idempotency_key'] ?? uniqid('ssl_issue_', true),
|
||||
'args' => $input,
|
||||
];
|
||||
}
|
||||
|
||||
public function buildApplySsl(string $tenantId, array $input): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'type' => 'SSL_APPLY',
|
||||
'idempotency_key' => $input['idempotency_key'] ?? uniqid('ssl_apply_', true),
|
||||
'args' => $input,
|
||||
];
|
||||
}
|
||||
|
||||
public function buildRenewSsl(string $tenantId, array $input): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'type' => 'SSL_RENEW',
|
||||
'idempotency_key' => $input['idempotency_key'] ?? uniqid('ssl_renew_', true),
|
||||
'args' => $input,
|
||||
];
|
||||
}
|
||||
}
|
||||
53
panel-api/app/Modules/Site/SiteController.php
Normal file
53
panel-api/app/Modules/Site/SiteController.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Site;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
public function __construct(private readonly SiteWorkflowService $workflow)
|
||||
{
|
||||
}
|
||||
|
||||
public function index(): JsonResponse { return response()->json(['data' => []]); }
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$tenantId = (string) $request->attributes->get('tenant_id', '');
|
||||
$result = $this->workflow->createSite($tenantId, $request->all());
|
||||
return response()->json(['data' => $result], 202);
|
||||
}
|
||||
|
||||
public function show(string $site): JsonResponse { return response()->json(['data' => ['id' => $site]]); }
|
||||
|
||||
public function update(Request $request, string $site): JsonResponse
|
||||
{
|
||||
$tenantId = (string) $request->attributes->get('tenant_id', '');
|
||||
$result = $this->workflow->updateSite($tenantId, $site, $request->all());
|
||||
return response()->json(['data' => $result], 202);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, string $site): JsonResponse
|
||||
{
|
||||
$tenantId = (string) $request->attributes->get('tenant_id', '');
|
||||
$result = $this->workflow->deleteSite($tenantId, $site, $request->all());
|
||||
return response()->json(['data' => $result], 202);
|
||||
}
|
||||
|
||||
public function addDomain(Request $request, string $site): JsonResponse
|
||||
{
|
||||
$tenantId = (string) $request->attributes->get('tenant_id', '');
|
||||
$result = $this->workflow->addDomain($tenantId, $site, $request->all());
|
||||
return response()->json(['data' => $result], 202);
|
||||
}
|
||||
|
||||
public function removeDomain(Request $request, string $site, string $domain): JsonResponse
|
||||
{
|
||||
$tenantId = (string) $request->attributes->get('tenant_id', '');
|
||||
$result = $this->workflow->removeDomain($tenantId, $site, $domain, $request->all());
|
||||
return response()->json(['data' => $result], 202);
|
||||
}
|
||||
}
|
||||
69
panel-api/app/Modules/Site/SiteWorkflowService.php
Normal file
69
panel-api/app/Modules/Site/SiteWorkflowService.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Site;
|
||||
|
||||
use App\Modules\Jobs\CommandOrchestrator;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class SiteWorkflowService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CommandOrchestrator $orchestrator,
|
||||
private readonly HostingCommandFactory $commandFactory,
|
||||
private readonly WebserverProfileResolver $webserverResolver
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function createSite(string $tenantId, array $input): array
|
||||
{
|
||||
$webserver = $this->webserverResolver->normalize((string) ($input['webserver'] ?? 'nginx'));
|
||||
$command = $this->commandFactory->buildCreateSite($tenantId, $input, $webserver);
|
||||
return $this->orchestrator->dispatch($command);
|
||||
}
|
||||
|
||||
public function updateSite(string $tenantId, string $siteId, array $input): array
|
||||
{
|
||||
$command = $this->commandFactory->buildUpdateSite($tenantId, $siteId, $input);
|
||||
return $this->orchestrator->dispatch($command);
|
||||
}
|
||||
|
||||
public function deleteSite(string $tenantId, string $siteId, array $input = []): array
|
||||
{
|
||||
$command = $this->commandFactory->buildDeleteSite($tenantId, $siteId, $input);
|
||||
return $this->orchestrator->dispatch($command);
|
||||
}
|
||||
|
||||
public function addDomain(string $tenantId, string $siteId, array $input): array
|
||||
{
|
||||
if (empty($input['domain'])) {
|
||||
throw new InvalidArgumentException('Domain is required');
|
||||
}
|
||||
$command = $this->commandFactory->buildAddDomain($tenantId, $siteId, $input);
|
||||
return $this->orchestrator->dispatch($command);
|
||||
}
|
||||
|
||||
public function removeDomain(string $tenantId, string $siteId, string $domainId, array $input = []): array
|
||||
{
|
||||
$command = $this->commandFactory->buildRemoveDomain($tenantId, $siteId, $domainId, $input);
|
||||
return $this->orchestrator->dispatch($command);
|
||||
}
|
||||
|
||||
public function issueSsl(string $tenantId, array $input): array
|
||||
{
|
||||
$command = $this->commandFactory->buildIssueSsl($tenantId, $input);
|
||||
return $this->orchestrator->dispatch($command);
|
||||
}
|
||||
|
||||
public function applySsl(string $tenantId, array $input): array
|
||||
{
|
||||
$command = $this->commandFactory->buildApplySsl($tenantId, $input);
|
||||
return $this->orchestrator->dispatch($command);
|
||||
}
|
||||
|
||||
public function renewSsl(string $tenantId, array $input): array
|
||||
{
|
||||
$command = $this->commandFactory->buildRenewSsl($tenantId, $input);
|
||||
return $this->orchestrator->dispatch($command);
|
||||
}
|
||||
}
|
||||
23
panel-api/app/Modules/Site/WebserverProfileResolver.php
Normal file
23
panel-api/app/Modules/Site/WebserverProfileResolver.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Site;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class WebserverProfileResolver
|
||||
{
|
||||
/**
|
||||
* Normalize webserver name to an allowed adapter key.
|
||||
*/
|
||||
public function normalize(string $webserver): string
|
||||
{
|
||||
$normalized = strtolower(trim($webserver));
|
||||
|
||||
return match ($normalized) {
|
||||
'nginx' => 'nginx',
|
||||
'apache', 'httpd' => 'apache',
|
||||
'openlitespeed', 'ols' => 'openlitespeed',
|
||||
default => throw new InvalidArgumentException('Unsupported webserver profile'),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user