From 8a12d98705f5017e14bf3930fafc020fb4168bf5 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Mon, 13 Jul 2026 17:11:52 +0530 Subject: [PATCH] Hide VCS factory behind DI closures --- app/init/resources.php | 4 ++++ .../Platform/Modules/Console/Http/Variables/Get.php | 7 +++---- .../Platform/Modules/VCS/Http/GitHub/Events/Create.php | 7 +++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/init/resources.php b/app/init/resources.php index d0c7bc07be..37705c48fe 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -378,10 +378,14 @@ $container->set('promiseAdapter', fn ($register) => $register->get('promiseAdapt $container->set('vcsFactory', fn (Cache $cache) => new VcsFactory($cache), ['cache']); +$container->set('vcsProviders', fn (VcsFactory $vcsFactory) => fn () => $vcsFactory->getProviders(), ['vcsFactory']); + $container->set('vcsForInstallation', fn (VcsFactory $vcsFactory) => fn (Document $installation) => $vcsFactory->fromInstallation($installation), ['vcsFactory']); $container->set('vcsForProvider', fn (VcsFactory $vcsFactory) => fn (string $provider) => $vcsFactory->fromProvider($provider), ['vcsFactory']); +$container->set('vcsWebhookSecret', fn (VcsFactory $vcsFactory) => fn (string $provider) => $vcsFactory->getWebhookSecret($provider), ['vcsFactory']); + $container->set('plan', fn () => []); $container->set('smsRates', fn () => []); diff --git a/src/Appwrite/Platform/Modules/Console/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Console/Http/Variables/Get.php index f1beaeb276..0ab83d27d2 100644 --- a/src/Appwrite/Platform/Modules/Console/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Console/Http/Variables/Get.php @@ -7,7 +7,6 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; -use Appwrite\Vcs\Factory; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Domains\Domain; @@ -47,7 +46,7 @@ class Get extends Action ], contentType: ContentType::JSON )) - ->inject('vcsFactory') + ->inject('vcsProviders') ->inject('response') ->inject('platform') ->inject('dbForProject') @@ -55,7 +54,7 @@ class Get extends Action } public function action( - Factory $vcsFactory, + callable $vcsProviders, Response $response, array $platform, Database $dbForProject @@ -72,7 +71,7 @@ class Get extends Action $isDomainEnabled = $isAAAAValid || $isAValid || $isCNAMEValid; - $isVcsEnabled = !empty($vcsFactory->getProviders()); + $isVcsEnabled = !empty($vcsProviders()); $isAssistantEnabled = !empty(System::getEnv('_APP_ASSISTANT_OPENAI_API_KEY', '')); diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index ac7e90b8a7..687214bd93 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -8,7 +8,6 @@ use Appwrite\Platform\Action; use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; -use Appwrite\Vcs\Factory as VcsFactory; use OpenRuntimes\Orchestrator\Jobs; use Utopia\Console; use Utopia\Database\Database; @@ -37,7 +36,7 @@ class Create extends Action ->desc('Create event') ->groups(['api', 'vcs']) ->label('scope', 'public') - ->inject('vcsFactory') + ->inject('vcsWebhookSecret') ->inject('vcsForProvider') ->inject('vcsForInstallation') ->inject('request') @@ -52,7 +51,7 @@ class Create extends Action } public function action( - VcsFactory $vcsFactory, + callable $vcsWebhookSecret, callable $vcsForProvider, callable $vcsForInstallation, Request $request, @@ -73,7 +72,7 @@ class Create extends Action $payload = $request->getRawPayload(); $signature = $request->getHeaderLine('x-hub-signature-256', ''); - $secretKey = $vcsFactory->getWebhookSecret('github'); + $secretKey = $vcsWebhookSecret('github'); $valid = empty($secretKey) ? true : $vcs->validateWebhookEvent($payload, $signature, $secretKey); Span::add('vcs.github.event.signature.valid', $valid);