feat(builds): check if function is blocked before building

This commit is contained in:
Fabian Gruber 2025-02-10 13:12:13 +01:00
parent 2902b1bde8
commit f2ae6e07cb

View file

@ -54,8 +54,10 @@ class Builds extends Action
->inject('cache') ->inject('cache')
->inject('dbForProject') ->inject('dbForProject')
->inject('deviceForFunctions') ->inject('deviceForFunctions')
->inject('isResourceBlocked')
->inject('log') ->inject('log')
->callback(fn ($message, Document $project, Database $dbForPlatform, Event $queueForEvents, Func $queueForFunctions, StatsUsage $usage, Cache $cache, Database $dbForProject, Device $deviceForFunctions, Log $log) => $this->action($message, $project, $dbForPlatform, $queueForEvents, $queueForFunctions, $usage, $cache, $dbForProject, $deviceForFunctions, $log)); ->callback(fn ($message, Document $project, Database $dbForPlatform, Event $queueForEvents, Func $queueForFunctions, StatsUsage $usage, Cache $cache, Database $dbForProject, Device $deviceForFunctions, callable $isResourceBlocked, Log $log) =>
$this->action($message, $project, $dbForPlatform, $queueForEvents, $queueForFunctions, $usage, $cache, $dbForProject, $deviceForFunctions, $isResourceBlocked, $log));
} }
/** /**
@ -72,7 +74,7 @@ class Builds extends Action
* @return void * @return void
* @throws \Utopia\Database\Exception * @throws \Utopia\Database\Exception
*/ */
public function action(Message $message, Document $project, Database $dbForPlatform, Event $queueForEvents, Func $queueForFunctions, StatsUsage $queueForStatsUsage, Cache $cache, Database $dbForProject, Device $deviceForFunctions, Log $log): void public function action(Message $message, Document $project, Database $dbForPlatform, Event $queueForEvents, Func $queueForFunctions, StatsUsage $queueForStatsUsage, Cache $cache, Database $dbForProject, Device $deviceForFunctions, callable $isResourceBlocked, Log $log): void
{ {
$payload = $message->getPayload() ?? []; $payload = $message->getPayload() ?? [];
@ -93,7 +95,7 @@ class Builds extends Action
case BUILD_TYPE_RETRY: case BUILD_TYPE_RETRY:
Console::info('Creating build for deployment: ' . $deployment->getId()); Console::info('Creating build for deployment: ' . $deployment->getId());
$github = new GitHub($cache); $github = new GitHub($cache);
$this->buildDeployment($deviceForFunctions, $queueForFunctions, $queueForEvents, $queueForStatsUsage, $dbForPlatform, $dbForProject, $github, $project, $resource, $deployment, $template, $log); $this->buildDeployment($deviceForFunctions, $queueForFunctions, $queueForEvents, $queueForStatsUsage, $dbForPlatform, $dbForProject, $github, $project, $resource, $deployment, $template, $isResourceBlocked, $log);
break; break;
default: default:
@ -118,7 +120,7 @@ class Builds extends Action
* @throws \Utopia\Database\Exception * @throws \Utopia\Database\Exception
* @throws Exception * @throws Exception
*/ */
protected function buildDeployment(Device $deviceForFunctions, Func $queueForFunctions, Event $queueForEvents, StatsUsage $queueForStatsUsage, Database $dbForPlatform, Database $dbForProject, GitHub $github, Document $project, Document $function, Document $deployment, Document $template, Log $log): void protected function buildDeployment(Device $deviceForFunctions, Func $queueForFunctions, Event $queueForEvents, StatsUsage $queueForStatsUsage, Database $dbForPlatform, Database $dbForProject, GitHub $github, Document $project, Document $function, Document $deployment, Document $template, callable $isResourceBlocked, Log $log): void
{ {
$executor = new Executor(System::getEnv('_APP_EXECUTOR_HOST')); $executor = new Executor(System::getEnv('_APP_EXECUTOR_HOST'));
@ -130,6 +132,10 @@ class Builds extends Action
throw new \Exception('Function not found', 404); throw new \Exception('Function not found', 404);
} }
if ($isResourceBlocked($project, RESOURCE_TYPE_FUNCTIONS, $functionId)) {
throw new \Exception('Function blocked', 403);
}
$deploymentId = $deployment->getId(); $deploymentId = $deployment->getId();
$log->addTag('deploymentId', $deploymentId); $log->addTag('deploymentId', $deploymentId);