From 14873824ce88937f779b11f7f550f4dfa1dca930 Mon Sep 17 00:00:00 2001 From: Fabian Gruber Date: Tue, 20 May 2025 09:24:24 +0200 Subject: [PATCH 1/2] certificates: add domainType to certificate worker --- src/Appwrite/Certificates/Adapter.php | 4 ++-- src/Appwrite/Certificates/LetsEncrypt.php | 4 ++-- .../Platform/Modules/Proxy/Http/Rules/API/Create.php | 3 ++- .../Modules/Proxy/Http/Rules/Function/Create.php | 3 ++- .../Modules/Proxy/Http/Rules/Redirect/Create.php | 3 ++- .../Modules/Proxy/Http/Rules/Site/Create.php | 3 ++- src/Appwrite/Platform/Workers/Certificates.php | 12 ++++++++---- 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/Certificates/Adapter.php b/src/Appwrite/Certificates/Adapter.php index 711e4c09b9..ab673e9cfe 100644 --- a/src/Appwrite/Certificates/Adapter.php +++ b/src/Appwrite/Certificates/Adapter.php @@ -6,9 +6,9 @@ use Utopia\Logger\Log; interface Adapter { - public function issueCertificate(string $certName, string $domain): ?string; + public function issueCertificate(string $certName, string $domain, ?string $domainType): ?string; - public function isRenewRequired(string $domain, Log $log): bool; + public function isRenewRequired(string $domain, ?string $domainType, Log $log): bool; public function deleteCertificate(string $domain): void; } diff --git a/src/Appwrite/Certificates/LetsEncrypt.php b/src/Appwrite/Certificates/LetsEncrypt.php index 3896eab022..76638d9816 100644 --- a/src/Appwrite/Certificates/LetsEncrypt.php +++ b/src/Appwrite/Certificates/LetsEncrypt.php @@ -18,7 +18,7 @@ class LetsEncrypt implements Adapter } - public function issueCertificate(string $certName, string $domain): ?string + public function issueCertificate(string $certName, string $domain, ?string $domainType): ?string { $stdout = ''; $stderr = ''; @@ -84,7 +84,7 @@ class LetsEncrypt implements Adapter return DateTime::addSeconds($dt, -60 * 60 * 24 * 30); } - public function isRenewRequired(string $domain, Log $log): bool + public function isRenewRequired(string $domain, ?string $domainType, Log $log): bool { $certPath = APP_STORAGE_CERTIFICATES . '/' . $domain . '/cert.pem'; if (\file_exists($certPath)) { diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index 218ae4ce9b..8ae48ab345 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -173,7 +173,8 @@ class Create extends Action if ($rule->getAttribute('status', '') === 'verifying') { $queueForCertificates ->setDomain(new Document([ - 'domain' => $rule->getAttribute('domain') + 'domain' => $rule->getAttribute('domain'), + 'domainType' => 'api', ])) ->trigger(); } diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php index 4c98d3f0a2..15d58c7b29 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -191,7 +191,8 @@ class Create extends Action if ($rule->getAttribute('status', '') === 'verifying') { $queueForCertificates ->setDomain(new Document([ - 'domain' => $rule->getAttribute('domain') + 'domain' => $rule->getAttribute('domain'), + 'domainType' => 'function', ])) ->trigger(); } diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php index 37db1512d4..0ff41e5ac2 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -179,7 +179,8 @@ class Create extends Action if ($rule->getAttribute('status', '') === 'verifying') { $queueForCertificates ->setDomain(new Document([ - 'domain' => $rule->getAttribute('domain') + 'domain' => $rule->getAttribute('domain'), + 'domainType' => 'redirect', ])) ->trigger(); } diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php index 1d39df2b24..f5f6628d68 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -191,7 +191,8 @@ class Create extends Action if ($rule->getAttribute('status', '') === 'verifying') { $queueForCertificates ->setDomain(new Document([ - 'domain' => $rule->getAttribute('domain') + 'domain' => $rule->getAttribute('domain'), + 'domainType' => 'site', ])) ->trigger(); } diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index afa288849a..4e83497cdd 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -55,7 +55,7 @@ class Certificates extends Action ->inject('log') ->inject('certificates') ->inject('plan') - ->callback([$this, 'action']); + ->callback($this->action(...)); } /** @@ -96,11 +96,14 @@ class Certificates extends Action $log->addTag('domain', $domain->get()); - $this->execute($domain, $dbForPlatform, $queueForMails, $queueForEvents, $queueForWebhooks, $queueForFunctions, $queueForRealtime, $log, $certificates, $skipRenewCheck, $plan); + $domainType = $payload['domainType'] ?? null; + + $this->execute($domain, $domainType, $dbForPlatform, $queueForMails, $queueForEvents, $queueForWebhooks, $queueForFunctions, $queueForRealtime, $log, $certificates, $skipRenewCheck, $plan); } /** * @param Domain $domain + * @param ?string $domainType * @param Database $dbForPlatform * @param Mail $queueForMails * @param Event $queueForEvents @@ -115,6 +118,7 @@ class Certificates extends Action */ private function execute( Domain $domain, + ?string $domainType, Database $dbForPlatform, Mail $queueForMails, Event $queueForEvents, @@ -174,7 +178,7 @@ class Certificates extends Action $this->validateDomain($domain, $isMainDomain, $log); // If certificate exists already, double-check expiry date. Skip if job is forced - if (!$certificates->isRenewRequired($domain->get(), $log)) { + if (!$certificates->isRenewRequired($domain->get(), $domainType, $log)) { Console::info("Skipping, renew isn't required"); return; } @@ -182,7 +186,7 @@ class Certificates extends Action // Prepare unique cert name. Using this helps prevent miss-match in configuration when renewing certificates. $certName = ID::unique(); - $renewDate = $certificates->issueCertificate($certName, $domain->get()); + $renewDate = $certificates->issueCertificate($certName, $domain->get(), $domainType); // Command succeeded, store all data into document $certificate->setAttribute('logs', 'Certificate successfully generated.'); From d710b48ef58379b3a1dba0e10773e924e5dce2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 20 May 2025 10:40:21 +0200 Subject: [PATCH 2/2] Fix: flutter starter --- app/config/templates/site.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/templates/site.php b/app/config/templates/site.php index ab6d5c4d4d..eec129a7bf 100644 --- a/app/config/templates/site.php +++ b/app/config/templates/site.php @@ -478,7 +478,7 @@ return [ 'frameworks' => [ getFramework('FLUTTER', [ 'providerRootDirectory' => './', - 'buildCommand' => 'bash build.sh', + 'buildCommand' => 'bash prepare.sh && bash build.sh', ]), ], 'vcsProvider' => 'github',