diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 5a9d8017ac..7640ea0faa 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -1186,7 +1186,7 @@ return [ 'filters' => [], ], [ - '$id' => ID::custom('verificationLogs'), + '$id' => ID::custom('logs'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 65535, 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 23fcf795e1..a4a05a26b8 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -167,7 +167,7 @@ class Create extends Action $this->verifyRule($rule, $log); $rule->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE); } catch (Exception $err) { - $rule->setAttribute('verificationLogs', $err->getMessage()); + $rule->setAttribute('logs', $err->getMessage()); } } @@ -188,6 +188,22 @@ class Create extends Action $queueForEvents->setParam('ruleId', $rule->getId()); + $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); + + // Merge logs: priority to certificate logs if both have values, otherwise use whichever is not empty + $ruleLogs = $rule->getAttribute('logs', ''); + $certificateLogs = $certificate->getAttribute('logs', ''); + $logs = ''; + if (!empty($certificateLogs) && !empty($ruleLogs)) { + $logs = $certificateLogs; // Certificate logs have priority + } elseif (!empty($certificateLogs)) { + $logs = $certificateLogs; + } elseif (!empty($ruleLogs)) { + $logs = $ruleLogs; + } + $rule->setAttribute('logs', $logs); + $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($rule, Response::MODEL_PROXY_RULE); 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 80b7e8483c..8e1feaf7fe 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -188,7 +188,7 @@ class Create extends Action $this->verifyRule($rule, $log); $rule->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE); } catch (Exception $err) { - $rule->setAttribute('verificationLogs', $err->getMessage()); + $rule->setAttribute('logs', $err->getMessage()); } } @@ -209,6 +209,22 @@ class Create extends Action $queueForEvents->setParam('ruleId', $rule->getId()); + $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); + + // Merge logs: priority to certificate logs if both have values, otherwise use whichever is not empty + $ruleLogs = $rule->getAttribute('logs', ''); + $certificateLogs = $certificate->getAttribute('logs', ''); + $logs = ''; + if (!empty($certificateLogs) && !empty($ruleLogs)) { + $logs = $certificateLogs; // Certificate logs have priority + } elseif (!empty($certificateLogs)) { + $logs = $certificateLogs; + } elseif (!empty($ruleLogs)) { + $logs = $ruleLogs; + } + $rule->setAttribute('logs', $logs); + $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($rule, Response::MODEL_PROXY_RULE); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php index 97b668a943..4b7e66affb 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php @@ -66,7 +66,19 @@ class Get extends Action // Fill response model $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); - $rule->setAttribute('logs', $certificate->getAttribute('logs', '')); + + // Merge logs: priority to certificate logs if both have values, otherwise use whichever is not empty + $ruleLogs = $rule->getAttribute('logs', ''); + $certificateLogs = $certificate->getAttribute('logs', ''); + $logs = ''; + if (!empty($certificateLogs) && !empty($ruleLogs)) { + $logs = $certificateLogs; // Certificate logs have priority + } elseif (!empty($certificateLogs)) { + $logs = $certificateLogs; + } elseif (!empty($ruleLogs)) { + $logs = $ruleLogs; + } + $rule->setAttribute('logs', $logs); $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); $certificateHasUpdatedAt = $certificate->getUpdatedAt() !== null; 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 096c0e80f8..50d297a7e8 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -194,7 +194,7 @@ class Create extends Action $this->verifyRule($rule, $log); $rule->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE); } catch (Exception $err) { - $rule->setAttribute('verificationLogs', $err->getMessage()); + $rule->setAttribute('logs', $err->getMessage()); } } @@ -215,6 +215,22 @@ class Create extends Action $queueForEvents->setParam('ruleId', $rule->getId()); + $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); + + // Merge logs: priority to certificate logs if both have values, otherwise use whichever is not empty + $ruleLogs = $rule->getAttribute('logs', ''); + $certificateLogs = $certificate->getAttribute('logs', ''); + $logs = ''; + if (!empty($certificateLogs) && !empty($ruleLogs)) { + $logs = $certificateLogs; // Certificate logs have priority + } elseif (!empty($certificateLogs)) { + $logs = $certificateLogs; + } elseif (!empty($ruleLogs)) { + $logs = $ruleLogs; + } + $rule->setAttribute('logs', $logs); + $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($rule, Response::MODEL_PROXY_RULE); 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 ed4ade3d5b..ebe73f59fd 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -188,7 +188,7 @@ class Create extends Action $this->verifyRule($rule, $log); $rule->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE); } catch (Exception $err) { - $rule->setAttribute('verificationLogs', $err->getMessage()); + $rule->setAttribute('logs', $err->getMessage()); } } @@ -209,6 +209,22 @@ class Create extends Action $queueForEvents->setParam('ruleId', $rule->getId()); + $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); + + // Merge logs: priority to certificate logs if both have values, otherwise use whichever is not empty + $ruleLogs = $rule->getAttribute('logs', ''); + $certificateLogs = $certificate->getAttribute('logs', ''); + $logs = ''; + if (!empty($certificateLogs) && !empty($ruleLogs)) { + $logs = $certificateLogs; // Certificate logs have priority + } elseif (!empty($certificateLogs)) { + $logs = $certificateLogs; + } elseif (!empty($ruleLogs)) { + $logs = $ruleLogs; + } + $rule->setAttribute('logs', $logs); + $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($rule, Response::MODEL_PROXY_RULE); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php index 5ff54c621b..959d43fe93 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php @@ -90,11 +90,11 @@ class Update extends Action try { $this->verifyRule($rule, $log); - $updates->setAttribute('verificationLogs', ''); + $updates->setAttribute('logs', ''); } catch (Exception $err) { $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ '$updatedAt' => DateTime::now(), - 'verificationLogs' => $err->getMessage(), + 'logs' => $err->getMessage(), ])); throw $err; } @@ -113,7 +113,19 @@ class Update extends Action // Fill response model $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); - $rule->setAttribute('logs', $certificate->getAttribute('logs', '')); + + // Merge logs: priority to certificate logs if both have values, otherwise use whichever is not empty + $ruleLogs = $rule->getAttribute('logs', ''); + $certificateLogs = $certificate->getAttribute('logs', ''); + $logs = ''; + if (!empty($certificateLogs) && !empty($ruleLogs)) { + $logs = $certificateLogs; + } elseif (!empty($certificateLogs)) { + $logs = $certificateLogs; + } elseif (!empty($ruleLogs)) { + $logs = $ruleLogs; + } + $rule->setAttribute('logs', $logs); $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); $certificateHasUpdatedAt = $certificate->getUpdatedAt() !== null; diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php index 0e984b6806..fa359bb246 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php @@ -111,7 +111,19 @@ class XList extends Action // Fill response model foreach ($rules as $rule) { $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); - $rule->setAttribute('logs', $certificate->getAttribute('logs', '')); + + // Merge logs: priority to certificate logs if both have values, otherwise use whichever is not empty + $ruleLogs = $rule->getAttribute('logs', ''); + $certificateLogs = $certificate->getAttribute('logs', ''); + $logs = ''; + if (!empty($certificateLogs) && !empty($ruleLogs)) { + $logs = $certificateLogs; // Certificate logs have priority + } elseif (!empty($certificateLogs)) { + $logs = $certificateLogs; + } elseif (!empty($ruleLogs)) { + $logs = $ruleLogs; + } + $rule->setAttribute('logs', $logs); $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); $certificateHasUpdatedAt = $certificate->getUpdatedAt() !== null; diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 7ea8032b50..60df176390 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -157,14 +157,14 @@ class Certificates extends Action try { $this->validateDomain($rule, $isMainDomain, $log, $verificationDomainAPI, $verificationDomainFunction); $updates - ->setAttribute('verificationLogs', '') + ->setAttribute('logs', '') ->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE); Console::success('Verification succeeded.'); $success = true; } catch (ExtendException $err) { Console::warning('Verification failed: ' . $err->getMessage()); - $updates->setAttribute('verificationLogs', $err->getMessage()); + $updates->setAttribute('logs', $err->getMessage()); } $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), $updates); diff --git a/src/Appwrite/Utopia/Response/Model/Rule.php b/src/Appwrite/Utopia/Response/Model/Rule.php index 86a4aeedff..b65c3a888f 100644 --- a/src/Appwrite/Utopia/Response/Model/Rule.php +++ b/src/Appwrite/Utopia/Response/Model/Rule.php @@ -89,17 +89,11 @@ class Rule extends Model 'default' => '', 'example' => RULE_STATUS_SUCCESSFUL, ]) - ->addRule('verificationLogs', [ - 'type' => self::TYPE_STRING, - 'description' => 'DNS verification logs. This contains error from last verification attempt.', - 'default' => '', - 'example' => 'Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.', - ]) ->addRule('logs', [ 'type' => self::TYPE_STRING, - 'description' => 'Certificate generation logs. This will return an empty string if generation did not run, or succeeded.', + 'description' => 'Logs from rule verification or certificate generation. Priority: certificate logs if both have values, otherwise whichever is not empty.', 'default' => '', - 'example' => 'HTTP challegne failed.', + 'example' => 'Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.', ]) ->addRule('renewAt', [ 'type' => self::TYPE_DATETIME, diff --git a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php index af700f4aa9..c0e6e69880 100644 --- a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php +++ b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php @@ -581,7 +581,7 @@ class ProxyCustomServerTest extends Scope $rule = $this->createSiteRule('stage-site.webapp.com', $siteId); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']); - $this->assertEmpty($rule['body']['verificationLogs']); + $this->assertEmpty($rule['body']['logs']); $this->assertNotEmpty($rule['body']['$id']); $ruleId = $rule['body']['$id']; @@ -589,7 +589,7 @@ class ProxyCustomServerTest extends Scope $this->assertEquals(200, $rule['headers']['status-code']); $this->assertEquals($ruleId, $rule['body']['$id']); $this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']); - $this->assertEmpty($rule['body']['verificationLogs']); + $this->assertEmpty($rule['body']['logs']); $this->cleanupRule($rule['body']['$id']); $this->cleanupSite($siteId); @@ -601,13 +601,13 @@ class ProxyCustomServerTest extends Scope $rule = $this->createFunctionRule('stage-function.webapp.com', $functionId); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']); - $this->assertEmpty($rule['body']['verificationLogs']); + $this->assertEmpty($rule['body']['logs']); $this->cleanupRule($rule['body']['$id']); $rule = $this->createAPIRule('stage-site.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']); - $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['verificationLogs']); + $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); $this->cleanupRule($rule['body']['$id']); $this->cleanupFunction($functionId); @@ -616,7 +616,7 @@ class ProxyCustomServerTest extends Scope $rule = $this->createAPIRule('wrong-a-webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']); - $this->assertStringContainsString('is missing CNAME record', $rule['body']['verificationLogs']); + $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); $ruleId = $rule['body']['$id']; $rule = $this->updateRuleVerification($ruleId); @@ -633,7 +633,7 @@ class ProxyCustomServerTest extends Scope $rule = $this->createAPIRule('webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']); - $this->assertEmpty($rule['body']['verificationLogs']); + $this->assertEmpty($rule['body']['logs']); $this->cleanupRule($rule['body']['$id']); @@ -641,7 +641,7 @@ class ProxyCustomServerTest extends Scope $rule = $this->createAPIRule('stage.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']); - $this->assertEmpty($rule['body']['verificationLogs']); + $this->assertEmpty($rule['body']['logs']); $this->cleanupRule($rule['body']['$id']); @@ -649,7 +649,7 @@ class ProxyCustomServerTest extends Scope $rule = $this->createAPIRule('stage-missing-cname.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']); - $this->assertStringContainsString('is missing CNAME record', $rule['body']['verificationLogs']); + $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); $ruleId = $rule['body']['$id']; $rule = $this->updateRuleVerification($ruleId); @@ -666,7 +666,7 @@ class ProxyCustomServerTest extends Scope $rule = $this->createAPIRule('stage-wrong-cname.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']); - $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['verificationLogs']); + $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); $ruleId = $rule['body']['$id']; $rule = $this->updateRuleVerification($ruleId); @@ -683,7 +683,7 @@ class ProxyCustomServerTest extends Scope $rule = $this->createAPIRule('stage-wrong-caa.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']); - $this->assertStringContainsString('has incorrect CAA value', $rule['body']['verificationLogs']); + $this->assertStringContainsString('has incorrect CAA value', $rule['body']['logs']); $ruleId = $rule['body']['$id']; $rule = $this->updateRuleVerification($ruleId); @@ -700,7 +700,7 @@ class ProxyCustomServerTest extends Scope $rule = $this->createAPIRule('stage-correct-caa.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']); - $this->assertEmpty($rule['body']['verificationLogs']); + $this->assertEmpty($rule['body']['logs']); $this->cleanupRule($rule['body']['$id']); } @@ -712,23 +712,23 @@ class ProxyCustomServerTest extends Scope $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']); - $this->assertNotEmpty($rule['body']['verificationLogs']); + $this->assertNotEmpty($rule['body']['logs']); $ruleId = $rule['body']['$id']; $initialUpdatedAt = $rule['body']['$updatedAt']; - $initialVerificationLogs = $rule['body']['verificationLogs']; + $initiallogs = $rule['body']['logs']; sleep(1); $updatedRule = $this->updateRuleVerification($ruleId); $this->assertEquals(400, $updatedRule['headers']['status-code']); - $this->assertStringContainsString($initialVerificationLogs, $updatedRule['body']['message']); + $this->assertStringContainsString($initiallogs, $updatedRule['body']['message']); $ruleAfterUpdate = $this->getRule($ruleId); $this->assertEquals(200, $ruleAfterUpdate['headers']['status-code']); $this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $ruleAfterUpdate['body']['status']); - $this->assertEquals($initialVerificationLogs, $ruleAfterUpdate['body']['verificationLogs']); + $this->assertEquals($initiallogs, $ruleAfterUpdate['body']['logs']); $this->assertNotEquals($initialUpdatedAt, $ruleAfterUpdate['body']['$updatedAt']); $initialTime = new \DateTime($initialUpdatedAt);