mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Replace verificationLogs with logs
This commit is contained in:
@@ -1186,7 +1186,7 @@ return [
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('verificationLogs'),
|
||||
'$id' => ID::custom('logs'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 65535,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user