consts for rule status

This commit is contained in:
Matej Bačo
2025-09-16 11:57:45 +02:00
parent 824d90edc0
commit 7b46197ffe
18 changed files with 65 additions and 61 deletions
+3 -3
View File
@@ -344,7 +344,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
'deploymentResourceId' => $resourceId,
'deploymentResourceInternalId' => $resourceInternalId,
'deploymentVcsProviderBranch' => $providerBranch,
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
'owner' => 'Appwrite',
@@ -377,7 +377,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
'deploymentResourceId' => $resourceId,
'deploymentResourceInternalId' => $resourceInternalId,
'deploymentVcsProviderBranch' => $providerBranch,
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
'owner' => 'Appwrite',
@@ -408,7 +408,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
'deploymentResourceId' => $resourceId,
'deploymentResourceInternalId' => $resourceInternalId,
'deploymentVcsProviderBranch' => $providerBranch,
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
'owner' => 'Appwrite',
+1 -1
View File
@@ -969,7 +969,7 @@ App::init()
'$id' => $ruleId,
'domain' => $domain->get(),
'type' => 'api',
'status' => 'verifying',
'status' => RULE_STATUS_GENERATING_CERTIFICATE,
'projectId' => $console->getId(),
'projectInternalId' => $console->getSequence(),
'search' => implode(' ', [$ruleId, $domain->get()]),
+5 -1
View File
@@ -129,7 +129,11 @@ const DELETE_TYPE_TARGET = 'target';
const DELETE_TYPE_EXPIRED_TARGETS = 'invalid_targets';
const DELETE_TYPE_SESSION_TARGETS = 'session_targets';
const DELETE_TYPE_MAINTENANCE = 'maintenance';
// Rule types
const RULE_STATUS_VERIFICATION_FAILED = 'created';
const RULE_STATUS_GENERATING_CERTIFICATE = 'verifying';
const RULE_STATUS_GENERATION_FAILED = 'unverified';
const RULE_STATUS_SUCCESSFUL = 'verified';
// Message types
const MESSAGE_SEND_TYPE_INTERNAL = 'internal';
const MESSAGE_SEND_TYPE_EXTERNAL = 'external';
@@ -219,7 +219,7 @@ class Action extends PlatformAction
'deploymentResourceId' => $site->getId(),
'deploymentResourceInternalId' => $site->getSequence(),
'deploymentVcsProviderBranch' => $providerBranch,
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
'owner' => 'Appwrite',
@@ -245,7 +245,7 @@ class Action extends PlatformAction
'deploymentResourceId' => $site->getId(),
'deploymentResourceInternalId' => $site->getSequence(),
'deploymentVcsProviderBranch' => $providerBranch,
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
'owner' => 'Appwrite',
@@ -282,7 +282,7 @@ class Action extends PlatformAction
'deploymentResourceId' => $site->getId(),
'deploymentResourceInternalId' => $site->getSequence(),
'deploymentVcsProviderBranch' => $providerBranch,
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
'owner' => 'Appwrite',
@@ -365,7 +365,7 @@ class Create extends Action
'projectId' => $project->getId(),
'projectInternalId' => $project->getSequence(),
'domain' => $domain,
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'type' => 'deployment',
'trigger' => 'manual',
'deploymentId' => !isset($deployment) || $deployment->isEmpty() ? '' : $deployment->getId(),
@@ -1216,7 +1216,7 @@ class Builds extends Action
'deploymentResourceId' => $deployment->getId(),
'deploymentResourceInternalId' => $deployment->getSequence(),
'deploymentVcsProviderBranch' => $branchName,
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
'owner' => 'Appwrite',
@@ -133,9 +133,9 @@ class Create extends Action
// TODO: @christyjacob remove once we migrate the rules in 1.7.x
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique();
$status = 'created';
$status = RULE_STATUS_VERIFICATION_FAILED;
if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) {
$status = 'verified';
$status = RULE_STATUS_SUCCESSFUL;
}
$owner = '';
@@ -160,10 +160,10 @@ class Create extends Action
'region' => $project->getAttribute('region')
]);
if ($rule->getAttribute('status', '') === 'created') {
if ($rule->getAttribute('status', '') === RULE_STATUS_VERIFICATION_FAILED) {
try {
self::verifyRule($rule, $log);
$rule->setAttribute('status', 'verifying');
$rule->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE);
} catch (Exception $err) {
$rule->setAttribute('verificationLogs', $err->getMessage());
}
@@ -175,7 +175,7 @@ class Create extends Action
throw new Exception(Exception::RULE_ALREADY_EXISTS);
}
if ($rule->getAttribute('status', '') === 'verifying') {
if ($rule->getAttribute('status', '') === RULE_STATUS_GENERATING_CERTIFICATE) {
$queueForCertificates
->setDomain(new Document([
'domain' => $rule->getAttribute('domain'),
@@ -148,9 +148,9 @@ class Create extends Action
// TODO: @christyjacob remove once we migrate the rules in 1.7.x
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique();
$status = 'created';
$status = RULE_STATUS_VERIFICATION_FAILED;
if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) {
$status = 'verified';
$status = RULE_STATUS_SUCCESSFUL;
}
$owner = '';
@@ -181,10 +181,10 @@ class Create extends Action
'region' => $project->getAttribute('region')
]);
if ($rule->getAttribute('status', '') === 'created') {
if ($rule->getAttribute('status', '') === RULE_STATUS_VERIFICATION_FAILED) {
try {
self::verifyRule($rule, $log);
$rule->setAttribute('status', 'verifying');
$rule->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE);
} catch (Exception $err) {
$rule->setAttribute('verificationLogs', $err->getMessage());
}
@@ -196,7 +196,7 @@ class Create extends Action
throw new Exception(Exception::RULE_ALREADY_EXISTS);
}
if ($rule->getAttribute('status', '') === 'verifying') {
if ($rule->getAttribute('status', '') === RULE_STATUS_GENERATING_CERTIFICATE) {
$queueForCertificates
->setDomain(new Document([
'domain' => $rule->getAttribute('domain'),
@@ -155,9 +155,9 @@ class Create extends Action
// TODO: @christyjacob remove once we migrate the rules in 1.7.x
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique();
$status = 'created';
$status = RULE_STATUS_VERIFICATION_FAILED;
if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) {
$status = 'verified';
$status = RULE_STATUS_SUCCESSFUL;
}
$owner = '';
@@ -187,10 +187,10 @@ class Create extends Action
'region' => $project->getAttribute('region')
]);
if ($rule->getAttribute('status', '') === 'created') {
if ($rule->getAttribute('status', '') === RULE_STATUS_VERIFICATION_FAILED) {
try {
self::verifyRule($rule, $log);
$rule->setAttribute('status', 'verifying');
$rule->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE);
} catch (Exception $err) {
$rule->setAttribute('verificationLogs', $err->getMessage());
}
@@ -202,7 +202,7 @@ class Create extends Action
throw new Exception(Exception::RULE_ALREADY_EXISTS);
}
if ($rule->getAttribute('status', '') === 'verifying') {
if ($rule->getAttribute('status', '') === RULE_STATUS_GENERATING_CERTIFICATE) {
$queueForCertificates
->setDomain(new Document([
'domain' => $rule->getAttribute('domain'),
@@ -148,9 +148,9 @@ class Create extends Action
// TODO: @christyjacob remove once we migrate the rules in 1.7.x
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique();
$status = 'created';
$status = RULE_STATUS_VERIFICATION_FAILED;
if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) {
$status = 'verified';
$status = RULE_STATUS_SUCCESSFUL;
}
$owner = '';
@@ -181,10 +181,10 @@ class Create extends Action
'region' => $project->getAttribute('region')
]);
if ($rule->getAttribute('status', '') === 'created') {
if ($rule->getAttribute('status', '') === RULE_STATUS_VERIFICATION_FAILED) {
try {
self::verifyRule($rule, $log);
$rule->setAttribute('status', 'verifying');
$rule->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE);
} catch (Exception $err) {
$rule->setAttribute('verificationLogs', $err->getMessage());
}
@@ -196,7 +196,7 @@ class Create extends Action
throw new Exception(Exception::RULE_ALREADY_EXISTS);
}
if ($rule->getAttribute('status', '') === 'verifying') {
if ($rule->getAttribute('status', '') === RULE_STATUS_GENERATING_CERTIFICATE) {
$queueForCertificates
->setDomain(new Document([
'domain' => $rule->getAttribute('domain'),
@@ -92,7 +92,7 @@ class Update extends Action
throw $err;
}
$updates->setAttribute('status', 'verifying');
$updates->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE);
$rule = $dbForPlatform->updateDocument('rules', $rule->getId(), $updates);
@@ -287,7 +287,7 @@ class Create extends Action
'deploymentResourceType' => 'site',
'deploymentResourceId' => $site->getId(),
'deploymentResourceInternalId' => $site->getSequence(),
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
'owner' => 'Appwrite',
@@ -352,7 +352,7 @@ class Create extends Action
'deploymentResourceType' => 'site',
'deploymentResourceId' => $site->getId(),
'deploymentResourceInternalId' => $site->getSequence(),
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
'owner' => 'Appwrite',
@@ -159,7 +159,7 @@ class Create extends Action
'deploymentResourceType' => 'site',
'deploymentResourceId' => $site->getId(),
'deploymentResourceInternalId' => $site->getSequence(),
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'owner' => 'Appwrite',
'region' => $project->getAttribute('region')
@@ -188,7 +188,7 @@ class Create extends Action
'deploymentResourceType' => 'site',
'deploymentResourceId' => $site->getId(),
'deploymentResourceInternalId' => $site->getSequence(),
'status' => 'verified',
'status' => RULE_STATUS_SUCCESSFUL,
'certificateId' => '',
'owner' => 'Appwrite',
'region' => $project->getAttribute('region')
+1 -1
View File
@@ -124,7 +124,7 @@ class Maintenance extends Action
$rules = $dbForPlatform->find('rules', [
Query::createdAfter(DatabaseDateTime::format($oldestToCheck)), // max 3 days old
Query::equal('status', ['created']), // not verified yet
Query::equal('status', [RULE_STATUS_VERIFICATION_FAILED]), // not verified yet
Query::orderAsc('$updatedAt'), // Pick the ones waiting for another attempt for longest
Query::limit(30), // Reasonable pagination limit, processable within a minute
]);
@@ -138,7 +138,7 @@ class Certificates extends Action
}
// Skip if verification not needed
if ($rule->getAttribute('status', '') !== 'created') {
if ($rule->getAttribute('status', '') !== RULE_STATUS_VERIFICATION_FAILED) {
Console::warning('Verification for ' . $rule->getAttribute('domain', '') . ' is not needed.');
return;
}
@@ -156,7 +156,7 @@ class Certificates extends Action
$this->validateDomain($rule, $isMainDomain, $log, $verificationDomainAPI, $verificationDomainFunction);
$updates
->setAttribute('verificationLogs', '')
->setAttribute('status', 'verifying');
->setAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE);
Console::success('Verification succeeded.');
$success = true;
@@ -251,7 +251,7 @@ class Certificates extends Action
$certificate->setAttribute('domain', $domain->get());
}
$status = $certificate->getAttribute('status', 'verifying');
$status = $certificate->getAttribute('status', RULE_STATUS_GENERATING_CERTIFICATE);
try {
// Clean-up logs from previous attempt
@@ -304,7 +304,7 @@ class Certificates extends Action
// This is useful when cert provider does extra work in background
// For example, verification, or example certificate distribution to all edges
if ($certificates->isIssueInstant($domain->get(), $domainType)) {
$status = 'verified';
$status = RULE_STATUS_SUCCESSFUL;
}
// Command succeeded, store all data into document
@@ -315,7 +315,7 @@ class Certificates extends Action
$certificate->setAttribute('attempts', 0);
$certificate->setAttribute('issueDate', DateTime::now());
} catch (Throwable $e) {
$status = 'unverified';
$status = RULE_STATUS_GENERATION_FAILED;
$logs = $e->getMessage();
$currentLogs = $certificate->getAttribute('logs', '');
+2 -2
View File
@@ -84,9 +84,9 @@ class Rule extends Model
])
->addRule('status', [
'type' => self::TYPE_STRING,
'description' => 'Domain verification status. Possible values are "created", "verifying", "verified" and "unverified"',
'description' => 'Domain verification status. Possible values are "' . RULE_STATUS_VERIFICATION_FAILED . '", "' . RULE_STATUS_GENERATING_CERTIFICATE . '", "' . RULE_STATUS_SUCCESSFUL . '" and "' . RULE_STATUS_GENERATION_FAILED . '"',
'default' => false,
'example' => 'verified',
'example' => RULE_STATUS_SUCCESSFUL,
])
->addRule('verificationLogs', [
'type' => self::TYPE_STRING,
@@ -86,7 +86,7 @@ class ProxyCustomServerTest extends Scope
$domain = \uniqid() . '.com';
$rule = $this->createAPIRule($domain);
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
}
public function testCreateRuleVcs(): void
@@ -389,7 +389,7 @@ class ProxyCustomServerTest extends Scope
$rule = $this->createAPIRule($domain);
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('verified', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_SUCCESSFUL, $rule['body']['status']);
$this->cleanupRule($rule['body']['$id']);
@@ -398,7 +398,7 @@ class ProxyCustomServerTest extends Scope
$rule = $this->createAPIRule($domain);
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('verified', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_SUCCESSFUL, $rule['body']['status']);
$this->cleanupRule($rule['body']['$id']);
@@ -407,7 +407,7 @@ class ProxyCustomServerTest extends Scope
$rule = $this->createAPIRule($domain);
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$ruleId = $rule['body']['$id'];
@@ -580,7 +580,7 @@ class ProxyCustomServerTest extends Scope
$rule = $this->createSiteRule('stage-site.webapp.com', $siteId);
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('verifying', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']);
$this->assertEmpty($rule['body']['verificationLogs']);
$this->cleanupRule($rule['body']['$id']);
@@ -592,13 +592,13 @@ class ProxyCustomServerTest extends Scope
$rule = $this->createFunctionRule('stage-function.webapp.com', $functionId);
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('verifying', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']);
$this->assertEmpty($rule['body']['verificationLogs']);
$this->cleanupRule($rule['body']['$id']);
$rule = $this->createAPIRule('stage-site.webapp.com');
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$this->assertStringContainsString('has incorrect CNAME value', $rule['body']['verificationLogs']);
$this->cleanupRule($rule['body']['$id']);
@@ -607,7 +607,7 @@ class ProxyCustomServerTest extends Scope
// 3. Wrong A record fails to verify
$rule = $this->createAPIRule('wrong-a-webapp.com');
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$this->assertStringContainsString('is missing CNAME record', $rule['body']['verificationLogs']);
$ruleId = $rule['body']['$id'];
@@ -617,14 +617,14 @@ class ProxyCustomServerTest extends Scope
$rule = $this->getRule($ruleId);
$this->assertEquals(200, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$this->cleanupRule($ruleId);
// 4. Correct A record can verify
$rule = $this->createAPIRule('webapp.com');
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('verifying', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']);
$this->assertEmpty($rule['body']['verificationLogs']);
$this->cleanupRule($rule['body']['$id']);
@@ -632,7 +632,7 @@ class ProxyCustomServerTest extends Scope
// 5. Correct CNAME record can verify (no CAA record)
$rule = $this->createAPIRule('stage.webapp.com');
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('verifying', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']);
$this->assertEmpty($rule['body']['verificationLogs']);
$this->cleanupRule($rule['body']['$id']);
@@ -640,7 +640,7 @@ class ProxyCustomServerTest extends Scope
// 6. Missing CNAME record fails to verify
$rule = $this->createAPIRule('stage-missing-cname.webapp.com');
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$this->assertStringContainsString('is missing CNAME record', $rule['body']['verificationLogs']);
$ruleId = $rule['body']['$id'];
@@ -650,14 +650,14 @@ class ProxyCustomServerTest extends Scope
$rule = $this->getRule($ruleId);
$this->assertEquals(200, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$this->cleanupRule($ruleId);
// 7. Wrong CNAME record fails to verify
$rule = $this->createAPIRule('stage-wrong-cname.webapp.com');
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$this->assertStringContainsString('has incorrect CNAME value', $rule['body']['verificationLogs']);
$ruleId = $rule['body']['$id'];
@@ -667,14 +667,14 @@ class ProxyCustomServerTest extends Scope
$rule = $this->getRule($ruleId);
$this->assertEquals(200, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$this->cleanupRule($ruleId);
// 8. Wrong CAA record fails to verify
$rule = $this->createAPIRule('stage-wrong-caa.webapp.com');
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$this->assertStringContainsString('has incorrect CAA value', $rule['body']['verificationLogs']);
$ruleId = $rule['body']['$id'];
@@ -684,14 +684,14 @@ class ProxyCustomServerTest extends Scope
$rule = $this->getRule($ruleId);
$this->assertEquals(200, $rule['headers']['status-code']);
$this->assertEquals('created', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_VERIFICATION_FAILED, $rule['body']['status']);
$this->cleanupRule($ruleId);
// 9. Correct CAA record can verify
$rule = $this->createAPIRule('stage-correct-caa.webapp.com');
$this->assertEquals(201, $rule['headers']['status-code']);
$this->assertEquals('verifying', $rule['body']['status']);
$this->assertEquals(RULE_STATUS_GENERATING_CERTIFICATE, $rule['body']['status']);
$this->assertEmpty($rule['body']['verificationLogs']);
$this->cleanupRule($rule['body']['$id']);