Merge branch '1.6.x' of https://github.com/appwrite/appwrite into feat-custom-cf-hostnames

This commit is contained in:
Christy Jacob 2024-11-09 16:01:16 +00:00
commit 76216c3bf6
5 changed files with 17 additions and 28 deletions

View file

@ -326,9 +326,9 @@ App::post('/v1/functions')
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', ''); $functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
if (!empty($functionsDomain)) { if (!empty($functionsDomain)) {
$ruleId = ID::unique();
$routeSubdomain = ID::unique(); $routeSubdomain = ID::unique();
$domain = "{$routeSubdomain}.{$functionsDomain}"; $domain = "{$routeSubdomain}.{$functionsDomain}";
$ruleId = md5($domain);
$rule = Authorization::skip( $rule = Authorization::skip(
fn () => $dbForConsole->createDocument('rules', new Document([ fn () => $dbForConsole->createDocument('rules', new Document([

View file

@ -11,7 +11,6 @@ use Utopia\App;
use Utopia\Database\Database; use Utopia\Database\Database;
use Utopia\Database\Document; use Utopia\Database\Document;
use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Exception\Query as QueryException;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Query; use Utopia\Database\Query;
use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\Query\Cursor;
use Utopia\Database\Validator\UID; use Utopia\Database\Validator\UID;
@ -60,9 +59,8 @@ App::post('/v1/proxy/rules')
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please pick another one.'); throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please pick another one.');
} }
$document = $dbForConsole->findOne('rules', [ $ruleId = md5($domain);
Query::equal('domain', [$domain]), $document = $dbForConsole->getDocument('rules', $ruleId);
]);
if (!$document->isEmpty()) { if (!$document->isEmpty()) {
if ($document->getAttribute('projectId') === $project->getId()) { if ($document->getAttribute('projectId') === $project->getId()) {
@ -103,7 +101,7 @@ App::post('/v1/proxy/rules')
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Domain may not start with http:// or https://.'); throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Domain may not start with http:// or https://.');
} }
$ruleId = ID::unique(); $ruleId = md5($domain->get());
$rule = new Document([ $rule = new Document([
'$id' => $ruleId, '$id' => $ruleId,
'projectId' => $project->getId(), 'projectId' => $project->getId(),

View file

@ -29,7 +29,6 @@ use Utopia\Database\Database;
use Utopia\Database\DateTime; use Utopia\Database\DateTime;
use Utopia\Database\Document; use Utopia\Database\Document;
use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\ID;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Authorization;
use Utopia\Domains\Domain; use Utopia\Domains\Domain;
use Utopia\DSN\DSN; use Utopia\DSN\DSN;
@ -52,14 +51,9 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
$host = $request->getHostname() ?? ''; $host = $request->getHostname() ?? '';
$route = Authorization::skip( $route = Authorization::skip(fn () => $dbForConsole->getDocument('rules', md5($host)));
fn () => $dbForConsole->find('rules', [
Query::equal('domain', [$host]),
Query::limit(1)
])
)[0] ?? null;
if ($route === null) { if ($route->isEmpty()) {
if ($host === System::getEnv('_APP_DOMAIN_FUNCTIONS', '')) { if ($host === System::getEnv('_APP_DOMAIN_FUNCTIONS', '')) {
throw new AppwriteException(AppwriteException::GENERAL_ACCESS_FORBIDDEN, 'This domain cannot be used for security reasons. Please use any subdomain instead.'); throw new AppwriteException(AppwriteException::GENERAL_ACCESS_FORBIDDEN, 'This domain cannot be used for security reasons. Please use any subdomain instead.');
} }
@ -518,19 +512,18 @@ App::init()
if (!empty($envDomain) && $envDomain !== 'localhost') { if (!empty($envDomain) && $envDomain !== 'localhost') {
$mainDomain = $envDomain; $mainDomain = $envDomain;
} else { } else {
$domainDocument = $dbForConsole->findOne('rules', [Query::orderAsc('$id')]); $domainDocument = $dbForConsole->getDocument('rules', md5($envDomain));
$mainDomain = !$domainDocument->isEmpty() ? $domainDocument->getAttribute('domain') : $domain->get(); $mainDomain = !$domainDocument->isEmpty() ? $domainDocument->getAttribute('domain') : $domain->get();
} }
if ($mainDomain !== $domain->get()) { if ($mainDomain !== $domain->get()) {
Console::warning($domain->get() . ' is not a main domain. Skipping SSL certificate generation.'); Console::warning($domain->get() . ' is not a main domain. Skipping SSL certificate generation.');
} else { } else {
$domainDocument = $dbForConsole->findOne('rules', [ $domainDocument = $dbForConsole->getDocument('rules', md5($domain->get()));
Query::equal('domain', [$domain->get()])
]);
if ($domainDocument->isEmpty()) { if ($domainDocument->isEmpty()) {
$domainDocument = new Document([ $domainDocument = new Document([
'$id' => md5($domain->get()),
'domain' => $domain->get(), 'domain' => $domain->get(),
'resourceType' => 'api', 'resourceType' => 'api',
'status' => 'verifying', 'status' => 'verifying',

14
composer.lock generated
View file

@ -4115,23 +4115,23 @@
}, },
{ {
"name": "phpdocumentor/type-resolver", "name": "phpdocumentor/type-resolver",
"version": "1.9.0", "version": "1.10.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git", "url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d" "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/1fb5ba8d045f5dd984ebded5b1cc66f29459422d", "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/679e3ce485b99e84c775d28e2e96fade9a7fb50a",
"reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d", "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"doctrine/deprecations": "^1.0", "doctrine/deprecations": "^1.0",
"php": "^7.3 || ^8.0", "php": "^7.3 || ^8.0",
"phpdocumentor/reflection-common": "^2.0", "phpdocumentor/reflection-common": "^2.0",
"phpstan/phpdoc-parser": "^1.18" "phpstan/phpdoc-parser": "^1.18|^2.0"
}, },
"require-dev": { "require-dev": {
"ext-tokenizer": "*", "ext-tokenizer": "*",
@ -4167,9 +4167,9 @@
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": { "support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues", "issues": "https://github.com/phpDocumentor/TypeResolver/issues",
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.9.0" "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.10.0"
}, },
"time": "2024-11-03T20:11:34+00:00" "time": "2024-11-09T15:12:26+00:00"
}, },
{ {
"name": "phpspec/prophecy", "name": "phpspec/prophecy",

View file

@ -520,9 +520,7 @@ class Certificates extends Action
private function updateDomainDocuments(string $certificateId, string $domain, bool $success, Database $dbForConsole, Event $queueForEvents, Func $queueForFunctions): void private function updateDomainDocuments(string $certificateId, string $domain, bool $success, Database $dbForConsole, Event $queueForEvents, Func $queueForFunctions): void
{ {
$rule = $dbForConsole->findOne('rules', [ $rule = $dbForConsole->getDocument('rules', md5($domain));
Query::equal('domain', [$domain]),
]);
if (!$rule->isEmpty()) { if (!$rule->isEmpty()) {
$rule->setAttribute('certificateId', $certificateId); $rule->setAttribute('certificateId', $certificateId);