From 81a5f25e4ddbb0162a9708a7b2022e6f301d2cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 10 Sep 2025 15:29:59 +0200 Subject: [PATCH] add certificate valdiation override --- src/Appwrite/Event/Certificate.php | 29 ++++++++++++++++++- .../Platform/Workers/Certificates.php | 9 ++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Event/Certificate.php b/src/Appwrite/Event/Certificate.php index 827472ae37..00875c7a4a 100644 --- a/src/Appwrite/Event/Certificate.php +++ b/src/Appwrite/Event/Certificate.php @@ -9,6 +9,7 @@ class Certificate extends Event { protected bool $skipRenewCheck = false; protected ?Document $domain = null; + protected ?string $validationDomain = null; public function __construct(protected Publisher $publisher) { @@ -55,6 +56,30 @@ class Certificate extends Event return $this; } + + /** + * Set override for main domain used for validation + * + * @param string|null $validationDomain + * @return self + */ + public function setValidationDomain(?string $validationDomain): self + { + $this->validationDomain = $validationDomain; + + return $this; + } + + /** + * Get validation domain + * + * @return string|null + */ + public function getValidationDomain(): ?string + { + return $this->validationDomain; + } + /** * Return if the certificate needs be validated. * @@ -65,6 +90,7 @@ class Certificate extends Event return $this->skipRenewCheck; } + /** * Prepare the payload for the event * @@ -75,7 +101,8 @@ class Certificate extends Event return [ 'project' => $this->project, 'domain' => $this->domain, - 'skipRenewCheck' => $this->skipRenewCheck + 'skipRenewCheck' => $this->skipRenewCheck, + 'validationDomain' => $this->validationDomain ]; } } diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 2138e440b6..3a65dfed2b 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -93,12 +93,13 @@ class Certificates extends Action $document = new Document($payload['domain'] ?? []); $domain = new Domain($document->getAttribute('domain', '')); $skipRenewCheck = $payload['skipRenewCheck'] ?? false; + $validationDomain = $payload['validationDomain'] ?? null; $log->addTag('domain', $domain->get()); $domainType = $document->getAttribute('domainType'); - $this->execute($domain, $domainType, $dbForPlatform, $queueForMails, $queueForEvents, $queueForWebhooks, $queueForFunctions, $queueForRealtime, $log, $certificates, $skipRenewCheck, $plan); + $this->execute($domain, $domainType, $dbForPlatform, $queueForMails, $queueForEvents, $queueForWebhooks, $queueForFunctions, $queueForRealtime, $log, $certificates, $skipRenewCheck, $plan, $validationDomain); } /** @@ -112,6 +113,7 @@ class Certificates extends Action * @param CertificatesAdapter $certificates * @param bool $skipRenewCheck * @param array $plan + * @param string|null $validationDomain * @return void * @throws Throwable * @throws \Utopia\Database\Exception @@ -128,7 +130,8 @@ class Certificates extends Action Log $log, CertificatesAdapter $certificates, bool $skipRenewCheck = false, - array $plan = [] + array $plan = [], + ?string $validationDomain = null ): void { /** * 1. Read arguments and validate domain @@ -173,7 +176,7 @@ class Certificates extends Action try { // Validate domain and DNS records. Skip if job is forced if (!$skipRenewCheck) { - $mainDomain = $this->getMainDomain(); + $mainDomain = $validationDomain ?? $this->getMainDomain(); $isMainDomain = !isset($mainDomain) || $domain->get() === $mainDomain; $this->validateDomain($domain, $isMainDomain, $log);