Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Co-authored-by: Aditya Tripathi <aditya@climactic.co>
This commit is contained in:
Andras Bacsai
2026-11-06 14:25:02 +01:00
committed by GitHub
co-authored by Claude Opus 5.5 peaklabs-dev Aditya Tripathi
parent b7dc2e435b
commit 033f0c84da
581 changed files with 58626 additions and 2456 deletions
@@ -0,0 +1,55 @@
<?php
namespace App\Actions\ImageScan;
use App\Jobs\PrepareImageScannerJob;
use App\Models\InstanceSettings;
use App\Models\Server;
use App\Services\ImageScan\ImageScanningRefused;
use Illuminate\Support\Facades\Cache;
use Lorisleiva\Actions\Concerns\AsAction;
/**
* Turns image scanning of a server on or off. Turning it on gets the scanner on the server.
*/
class SetServerImageScanning
{
use AsAction;
/**
* @throws ImageScanningRefused When the instance does not allow scanning or another instance manages the server.
*/
public function handle(Server $server, bool $enabled): void
{
if (! $enabled) {
$server->settings->update(['is_image_scan_enabled' => false]);
PrepareImageScannerJob::forget($server);
return;
}
self::ensureManagedHere($server);
if (! InstanceSettings::get()->is_image_scanning_allowed) {
throw new ImageScanningRefused('Image scanning is turned off for this Coolify instance.');
}
$server->settings->update(['is_image_scan_enabled' => true]);
self::prepareScanner($server);
}
/**
* Gets the scanner on the server again, for a server that scans images.
*/
public static function prepareScanner(Server $server): void
{
Cache::put(PrepareImageScannerJob::stateCacheKey($server), PrepareImageScannerJob::STATE_PULLING, now()->addHour());
PrepareImageScannerJob::dispatch($server);
}
public static function ensureManagedHere(Server $server): void
{
if ($server->isTransferredAway()) {
throw new ImageScanningRefused('This server is managed by another Coolify instance.');
}
}
}