1
0
Fork 0
mirror of synced 2024-07-02 05:00:33 +12:00

Add auto-verify logic to createRule

This commit is contained in:
Matej Bačo 2023-07-12 12:55:33 +02:00
parent 7cdf83b05e
commit f236b6539e
2 changed files with 28 additions and 11 deletions

@ -1 +1 @@
Subproject commit a4d777092e7a8fa0d0856d4d41c502b85b398e7f
Subproject commit 08060d1a19d1d74f52ac35ce7635cca28607ab1f

View file

@ -82,14 +82,7 @@ App::post('/v1/proxy/rules')
$domain = new Domain($domain);
$ruleId = ID::unique();
$status = 'created';
$functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS', 'disabled');
if ($functionsDomain !== 'disabled' && \str_ends_with($domain->get(), $functionsDomain)) {
$status = 'verified';
}
$rule = $dbForConsole->createDocument('rules', new Document([
$rule = new Document([
'$id' => $ruleId,
'projectId' => $project->getId(),
'projectInternalId' => $project->getInternalId(),
@ -97,9 +90,33 @@ App::post('/v1/proxy/rules')
'resourceType' => $resourceType,
'resourceId' => $resourceId,
'resourceInternalId' => $resourceInternalId,
'status' => $status,
'certificateId' => '',
]));
]);
$status = 'created';
$functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS', 'disabled');
if ($functionsDomain !== 'disabled' && \str_ends_with($domain->get(), $functionsDomain)) {
$status = 'verified';
}
if ($status === 'created') {
$target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', ''));
$validator = new CNAME($target->get()); // Verify Domain with DNS records
if ($validator->isValid($domain->get())) {
$status = 'verifying';
$event = new Certificate();
$event
->setDomain(new Document([
'domain' => $rule->getAttribute('domain')
]))
->trigger();
}
}
$rule->setAttribute('status', $status);
$rule = $dbForConsole->createDocument('rules', $rule);
$events->setParam('ruleId', $rule->getId());