Fixed formatting

This commit is contained in:
Eldad Fux
2024-04-22 07:56:36 +02:00
parent b97cf78d9d
commit 3b70ae4d9f
25 changed files with 74 additions and 103 deletions
+1 -2
View File
@@ -17,7 +17,6 @@ use Utopia\Config\Config;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Validator\Authorization;
use Utopia\Http\Http;
use Utopia\Logger\Log;
use Utopia\Platform\Service;
use Utopia\Pools\Group;
@@ -180,7 +179,7 @@ CLI::setResource('logError', function (Registry $register) {
$log->setAction($action);
$isProduction = System::getEnv('_APP_ENV', 'development') === 'production';
$log->setEnvironment($isProduction ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING);
$responseCode = $logger->addLog($log);
+2 -2
View File
@@ -16,10 +16,10 @@ use GraphQL\Validator\Rules\QueryDepth;
use Swoole\Coroutine\WaitGroup;
use Utopia\Database\Document;
use Utopia\Database\Validator\Authorization;
use Utopia\System\System;
use Utopia\Http\Http;
use Utopia\Http\Validator\JSON;
use Utopia\Http\Validator\Text;
use Utopia\Http\Http;
use Utopia\System\System;
Http::init()
->groups(['graphql'])
+1 -1
View File
@@ -89,7 +89,7 @@ Http::get('/v1/health/db')
$pool = $pools['pools-'.$key.'-'.$database]['pool'];
$dsn = $pools['pools-'.$key.'-'.$database]['dsn'];
$connection = $pool->get();
$connections->add($connection, $pool);
$adapter = match ($dsn->getScheme()) {
+1 -1
View File
@@ -198,7 +198,7 @@ Http::post('/v1/projects')
$dbForProject->setAuthorization($authorization);
$dbForProject->setNamespace("_{$project->getInternalId()}");
$dbForProject->create();
$audit = new Audit($dbForProject, $authorization);
$audit->setup();
$adapter = new TimeLimit('', 0, 1, $dbForProject, $authorization);
+4 -4
View File
@@ -23,7 +23,6 @@ use Utopia\Database\Document;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\DI\Dependency;
use Utopia\Domains\Domain;
use Utopia\Http\Http;
use Utopia\Http\Route;
@@ -33,7 +32,6 @@ use Utopia\Locale\Locale;
use Utopia\Logger\Log;
use Utopia\Logger\Log\User;
use Utopia\Logger\Logger;
use Utopia\Registry\Registry;
use Utopia\System\System;
Config::setParam('domainVerification', false);
@@ -383,7 +381,8 @@ Http::init()
Document $console,
Document $project,
Database $dbForConsole,
Locale $locale, array $localeCodes,
Locale $locale,
array $localeCodes,
array $clients,
/**
* @disregard P1009 Undefined type
@@ -392,7 +391,8 @@ Http::init()
// Usage $queueForUsage,
// Event $queueForEvents,
Certificate $queueForCertificates,
Authorization $authorization) {
Authorization $authorization
) {
/*
* Appwrite Router
*/
+1 -1
View File
@@ -27,10 +27,10 @@ use Utopia\Database\Document;
use Utopia\Database\Helpers\Role;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\Authorization\Input;
use Utopia\System\System;
use Utopia\Http\Http;
use Utopia\Http\Route;
use Utopia\Http\Validator\WhiteList;
use Utopia\System\System;
$parseLabel = function (string $label, array $responsePayload, array $requestParams, Document $user) {
preg_match_all('/{(.*?)}/', $label, $matches);
+1 -1
View File
@@ -245,4 +245,4 @@ Http::init()
$authorization->addRole(Role::any()->toString());
});
$http->start();
$http->start();
+1 -1
View File
@@ -824,7 +824,7 @@ $register->set('pools', function () {
//throw new Exception(Exception::GENERAL_SERVER_ERROR, "Missing value for DSN connection in {$key}");
continue;
}
$dsn = new DSN($dsn);
$dsnHost = $dsn->getHost();
$dsnPort = $dsn->getPort();
+1 -1
View File
@@ -156,4 +156,4 @@ const METRIC_FUNCTION_ID_EXECUTIONS = '{functionInternalId}.executions';
const METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE = '{functionInternalId}.executions.compute';
const METRIC_NETWORK_REQUESTS = 'network.requests';
const METRIC_NETWORK_INBOUND = 'network.inbound';
const METRIC_NETWORK_OUTBOUND = 'network.outbound';
const METRIC_NETWORK_OUTBOUND = 'network.outbound';
+1 -1
View File
@@ -395,4 +395,4 @@ Database::addFilter(
function (mixed $value) {
return $value;
}
);
);
+1 -1
View File
@@ -40,4 +40,4 @@ Structure::addFormat(APP_DATABASE_ATTRIBUTE_FLOAT_RANGE, function ($attribute) {
$min = $attribute['formatOptions']['min'] ?? -INF;
$max = $attribute['formatOptions']['max'] ?? INF;
return new Range($min, $max, Range::TYPE_FLOAT);
}, Database::VAR_FLOAT);
}, Database::VAR_FLOAT);
+1 -1
View File
@@ -20,4 +20,4 @@ foreach ($locales as $locale) {
}
Locale::setLanguageFromJSON($code, $path);
}
}
+38 -56
View File
@@ -29,37 +29,27 @@ use Appwrite\Event\Messaging;
use Appwrite\Event\Migration;
use Appwrite\Event\Usage;
use Appwrite\Extend\Exception;
use Appwrite\GraphQL\Promises\Adapter\Swoole;
use Appwrite\GraphQL\Schema;
use Appwrite\Hooks\Hooks;
use Appwrite\Network\Validator\Email;
use Appwrite\Network\Validator\Origin;
use Appwrite\OpenSSL\OpenSSL;
use Appwrite\URL\URL;
use Appwrite\Utopia\Queue\Connections;
use MaxMind\Db\Reader;
use PHPMailer\PHPMailer\PHPMailer;
use Swoole\Coroutine;
use Swoole\Database\PDOConfig;
use Swoole\Database\PDOPool;
use Swoole\Database\PDOProxy;
use Swoole\Database\RedisConfig;
use Swoole\Database\RedisPool;
use Utopia\Cache\Adapter\Redis as RedisCache;
use Utopia\Cache\Adapter\Sharding;
use Utopia\Cache\Adapter\None;
use Utopia\Cache\Cache;
use Utopia\CLI\Console;
use Utopia\Config\Config;
use Utopia\Database\Adapter\MariaDB;
use Utopia\Database\Adapter\MySQL;
use Utopia\Database\Adapter\SQL;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\Datetime as DatetimeValidator;
use Utopia\Database\Validator\Structure;
use Utopia\DI\Container;
use Utopia\DI\Dependency;
use Utopia\Domains\Validator\PublicDomain;
use Utopia\DSN\DSN;
@@ -67,14 +57,9 @@ use Utopia\Http\Http;
use Utopia\Http\Request;
use Utopia\Http\Response;
use Utopia\Http\Validator\Hostname;
use Utopia\Http\Validator\IP;
use Utopia\Http\Validator\Range;
use Utopia\Http\Validator\WhiteList;
use Utopia\Locale\Locale;
use Utopia\Logger\Log;
use Utopia\Logger\Logger;
use Utopia\Pools\Group;
use Utopia\Pools\Pool;
use Utopia\Queue;
use Utopia\Queue\Connection;
use Utopia\Registry\Registry;
@@ -87,9 +72,6 @@ use Utopia\Storage\Device\S3;
use Utopia\Storage\Device\Wasabi;
use Utopia\Storage\Storage;
use Utopia\System\System;
use Utopia\VCS\Adapter\Git\GitHub as VcsGitHub;
use Utopia\Cache\Adapter\None;
use Utopia\DI\Container;
Http::setMode(System::getEnv('_APP_ENV', Http::MODE_TYPE_PRODUCTION));
@@ -210,7 +192,7 @@ $global->set('geodb', function () {
});
$global->set('hooks', function () {
return new Hooks();
return new Hooks();
});
$global->set('pools', (function () {
@@ -279,11 +261,11 @@ $global->set('pools', (function () {
$name = ($multipe) ? $dsn[0] : 'main';
$config[] = $name;
$dsn = $dsn[1] ?? '';
if (empty($dsn)) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, "Missing value for DSN connection in {$key}");
}
$dsn = new DSN($dsn);
$dsnHost = $dsn->getHost();
$dsnPort = $dsn->getPort();
@@ -306,7 +288,8 @@ $global->set('pools', (function () {
switch ($dsnScheme) {
case 'mysql':
case 'mariadb':
$pool = new PDOPool((new PDOConfig)
$pool = new PDOPool(
(new PDOConfig())
->withHost($dsnHost)
->withPort($dsnPort)
->withDbName($dsnDatabase)
@@ -327,17 +310,16 @@ $global->set('pools', (function () {
);
break;
case 'redis':
$pool = new RedisPool((new RedisConfig)
$pool = new RedisPool((new RedisConfig())
->withHost($dsnHost)
->withPort((int)$dsnPort)
->withAuth($dsnPass)
, $poolSize);
->withAuth($dsnPass), $poolSize);
break;
default:
throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid scheme");
}
$pools['pools-' . $key . '-' . $name] = [
'pool' => $pool,
'dsn' => $dsn,
@@ -381,32 +363,32 @@ $user
$authorization->setDefaultStatus(true);
Auth::setCookieName('a_session_' . $project->getId());
if (APP_MODE_ADMIN === $mode) {
Auth::setCookieName('a_session_' . $console->getId());
}
$session = Auth::decodeSession(
$request->getCookie(
Auth::$cookieName, // Get sessions
$request->getCookie(Auth::$cookieName . '_legacy', '')
)
);
// Get session from header for SSR clients
if (empty($session['id']) && empty($session['secret'])) {
$sessionHeader = $request->getHeader('x-appwrite-session', '');
if (!empty($sessionHeader)) {
$session = Auth::decodeSession($sessionHeader);
}
}
// Get fallback session from old clients (no SameSite support) or clients who block 3rd-party cookies
if ($response) {
$response->addHeader('X-Debug-Fallback', 'false');
}
if (empty($session['id']) && empty($session['secret'])) {
if ($response) {
$response->addHeader('X-Debug-Fallback', 'true');
@@ -415,10 +397,10 @@ $user
$fallback = \json_decode($fallback, true);
$session = Auth::decodeSession(((isset($fallback[Auth::$cookieName])) ? $fallback[Auth::$cookieName] : ''));
}
Auth::$unique = $session['id'] ?? '';
Auth::$secret = $session['secret'] ?? '';
if (APP_MODE_ADMIN !== $mode) {
if ($project->isEmpty()) {
$user = new Document([]);
@@ -432,14 +414,14 @@ $user
} else {
$user = $dbForConsole->getDocument('users', Auth::$unique);
}
if (
$user->isEmpty() // Check a document has been found in the DB
|| !Auth::sessionVerify($user->getAttribute('sessions', []), Auth::$secret)
) { // Validate user has valid login token
$user = new Document([]);
}
if (APP_MODE_ADMIN === $mode) {
if ($user->find('teamId', $project->getAttribute('teamId'), 'memberships')) {
$authorization->setDefaultStatus(false); // Cancel security segmentation for admin users.
@@ -447,34 +429,34 @@ $user
$user = new Document([]);
}
}
$authJWT = $request->getHeader('x-appwrite-jwt', '');
if (!empty($authJWT) && !$project->isEmpty()) { // JWT authentication
$jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 900, 10); // Instantiate with key, algo, maxAge and leeway.
try {
$payload = $jwt->decode($authJWT);
} catch (JWTException $error) {
throw new Exception(Exception::USER_JWT_INVALID, 'Failed to verify JWT. ' . $error->getMessage());
}
$jwtUserId = $payload['userId'] ?? '';
$jwtSessionId = $payload['sessionId'] ?? '';
if ($jwtUserId && $jwtSessionId) {
$user = $dbForProject->getDocument('users', $jwtUserId);
}
if (empty($user->find('$id', $jwtSessionId, 'sessions'))) { // Match JWT to active token
$user = new Document([]);
}
}
// Adds logs to database queries
$dbForProject->setMetadata('user', $user->getId());
$dbForConsole->setMetadata('user', $user->getId());
return $user;
});
$container->set($user);
@@ -589,14 +571,14 @@ $dbForProject
->inject('dbForConsole')
->inject('connections')
->inject('authorization')
->setCallback(function(array $pools, Document $project, Cache $cache, Database $dbForConsole, Connections $connections, Authorization $authorization) {
->setCallback(function (array $pools, Document $project, Cache $cache, Database $dbForConsole, Connections $connections, Authorization $authorization) {
if ($project->isEmpty() || $project->getId() === 'console') {
return $dbForConsole;
}
$pool = $pools['pools-database-'.$project->getAttribute('database')]['pool'];
$dsn = $pools['pools-database-'.$project->getAttribute('database')]['dsn'];
$connection = $pool->get();
$connections->add($connection, $pool);
$adapter = match ($dsn->getScheme()) {
@@ -606,16 +588,16 @@ $dbForProject
};
$adapter->setDatabase($dsn->getPath());
$database = new Database($adapter, $cache);
$database->setAuthorization($authorization);
$database
->setNamespace('_' . $project->getInternalId())
->setMetadata('host', \gethostname())
->setMetadata('project', $project->getId())
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
return $database;
});
$container->set($dbForProject);
@@ -627,7 +609,7 @@ $dbForConsole
->inject('cache')
->inject('authorization')
->inject('connections')
->setCallback(function(array $pools, Cache $cache, Authorization $authorization, Connections $connections): Database {
->setCallback(function (array $pools, Cache $cache, Authorization $authorization, Connections $connections): Database {
$pool = $pools['pools-console-main']['pool'];
$dsn = $pools['pools-console-main']['dsn'];
$connection = $pool->get();
@@ -886,7 +868,7 @@ $clients
'type' => Origin::CLIENT_TYPE_WEB,
'hostname' => $request->getHostname(),
], Document::SET_TYPE_APPEND);
$hostnames = explode(',', System::getEnv('_APP_CONSOLE_HOSTNAMES', ''));
$validator = new Hostname();
foreach ($hostnames as $hostname) {
@@ -901,7 +883,7 @@ $clients
'hostname' => $hostname,
], Document::SET_TYPE_APPEND);
}
/**
* Get All verified client URLs for both console and current projects
* + Filter for duplicated entries
@@ -913,7 +895,7 @@ $clients
fn ($node) => (isset($node['type']) && ($node['type'] === Origin::CLIENT_TYPE_WEB) && isset($node['hostname']) && !empty($node['hostname']))
)
);
$clients = \array_unique(
\array_merge(
$clientsConsole,
@@ -926,7 +908,7 @@ $clients
)
)
);
return $clients;
});
$container->set($clients);
+9 -12
View File
@@ -20,10 +20,8 @@ use Appwrite\Platform\Appwrite;
use Appwrite\Utopia\Queue\Connections;
use Swoole\Runtime;
use Utopia\Cache\Adapter\None;
use Utopia\Cache\Adapter\Sharding;
use Utopia\Cache\Cache;
use Utopia\CLI\Console;
use Utopia\Config\Config;
use Utopia\Database\Adapter\MariaDB;
use Utopia\Database\Adapter\MySQL;
use Utopia\Database\Database;
@@ -38,7 +36,6 @@ use Utopia\Pools\Group;
use Utopia\Queue\Connection;
use Utopia\Queue\Connection\Redis;
use Utopia\Queue\Message;
use Utopia\Queue\Server;
use Utopia\Queue\Worker;
use Utopia\Registry\Registry;
use Utopia\Storage\Device\Local;
@@ -114,10 +111,10 @@ $dbForProject
if ($project->isEmpty() || $project->getId() === 'console') {
return $dbForConsole;
}
$pool = $pools['pools-database-'.$project->getAttribute('database')]['pool'];
$dsn = $pools['pools-database-'.$project->getAttribute('database')]['dsn'];
$connection = $pool->get();
$connections->add($connection, $pool);
$adapter = match ($dsn->getScheme()) {
@@ -125,9 +122,9 @@ $dbForProject
'mysql' => new MySQL($connection),
default => null
};
$adapter->setDatabase($dsn->getPath());
$database = new Database($adapter, $cache);
$database->setAuthorization($auth);
$database->setNamespace('_' . $project->getInternalId());
@@ -143,11 +140,11 @@ $project
->setCallback(function (Message $message, Database $dbForConsole) {
$payload = $message->getPayload() ?? [];
$project = new Document($payload['project'] ?? []);
if ($project->getId() === 'console') {
return $project;
}
return $dbForConsole->getDocument('projects', $project->getId());
});
$container->set($project);
@@ -170,7 +167,7 @@ $getProjectDB
$pool = $pools['pools-database-'.$databaseName]['pool'];
$dsn = $pools['pools-database-'.$databaseName]['dsn'];
$connection = $pool->get();
$connections->add($connection, $pool);
$adapter = match ($dsn->getScheme()) {
@@ -268,7 +265,7 @@ $queue
$dsn = $pools['pools-queue-main']['dsn'];
$connection = $pool->get();
$connections->add($connection, $pool);
return new Redis($dsn->getHost(), $dsn->getPort());
});
$container->set($queue);
@@ -558,4 +555,4 @@ Worker::error()
$platform
->getWorker()
->setContainer($container)
->start();
->start();
-1
View File
@@ -7,7 +7,6 @@ use Utopia\CLI\Console;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Http\Http;
use Utopia\Platform\Action;
use Utopia\System\System;
@@ -9,7 +9,6 @@ use Utopia\Database\DateTime;
use Utopia\Database\Document;
use Utopia\Database\Exception;
use Utopia\Database\Query;
use Utopia\Http\Http;
use Utopia\Platform\Action;
use Utopia\Pools\Group;
use Utopia\System\System;
+6 -6
View File
@@ -9,8 +9,6 @@ use Appwrite\Utopia\Response;
use Exception;
use Swoole\Http\Request as SwooleHttpRequest;
use Swoole\Http\Response as SwooleHttpResponse;
use Utopia\Http\Adapter\Swoole\Request;
use Utopia\Http\Adapter\Swoole\Response as HttpResponse;
use Utopia\Cache\Adapter\None;
use Utopia\Cache\Cache;
use Utopia\CLI\Console;
@@ -18,12 +16,14 @@ use Utopia\Config\Config;
use Utopia\Database\Adapter\MySQL;
use Utopia\Database\Database;
use Utopia\Http\Adapter\FPM\Server;
use Utopia\Http\Adapter\Swoole\Request;
use Utopia\Http\Adapter\Swoole\Response as HttpResponse;
use Utopia\Http\Http;
use Utopia\Http\Validator\Text;
use Utopia\Http\Validator\WhiteList;
use Utopia\Platform\Action;
use Utopia\Registry\Registry;
use Utopia\System\System;
use Utopia\Http\Validator\Text;
use Utopia\Http\Validator\WhiteList;
class Specs extends Action
{
@@ -45,11 +45,11 @@ class Specs extends Action
public function action(string $version, string $mode, Registry $register): void
{
$appRoutes = Http::getRoutes();
$response = new Response(new HttpResponse(new SwooleHttpResponse));
$response = new Response(new HttpResponse(new SwooleHttpResponse()));
$mocks = ($mode === 'mocks');
// Mock dependencies
Http::setResource('request', fn () => new Request(new SwooleHttpRequest));
Http::setResource('request', fn () => new Request(new SwooleHttpRequest()));
Http::setResource('response', fn () => $response);
Http::setResource('dbForConsole', fn () => new Database(new MySQL(''), new Cache(new None())));
Http::setResource('dbForProject', fn () => new Database(new MySQL(''), new Cache(new None())));
-1
View File
@@ -3,7 +3,6 @@
namespace Appwrite\Platform\Tasks;
use Utopia\CLI\Console;
use Utopia\Http\Http;
use Utopia\Platform\Action;
use Utopia\System\System;
+2 -3
View File
@@ -14,7 +14,6 @@ use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\Http\Http;
use Utopia\Platform\Action;
use Utopia\Pools\Group;
use Utopia\Queue\Message;
@@ -72,11 +71,11 @@ class Hamster extends Action
public function action(Message $message, Group $pools, Cache $cache, Database $dbForConsole, Authorization $auth, Connections $connections): void
{
$token = System::getEnv('_APP_MIXPANEL_TOKEN', '');
if (empty($token)) {
throw new \Exception('Missing MixPanel Token');
}
$this->mixpanel = new Mixpanel($token);
$payload = $message->getPayload() ?? [];
@@ -12,7 +12,6 @@ use Utopia\Database\Document;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Query;
use Utopia\DSN\DSN;
use Utopia\Http\Http;
use Utopia\Logger\Log;
use Utopia\Messaging\Adapter\Email as EmailAdapter;
use Utopia\Messaging\Adapter\Email\Mailgun;
@@ -8,7 +8,6 @@ use Exception;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Http\Http;
use Utopia\Logger\Log;
use Utopia\Platform\Action;
use Utopia\Queue\Message;
+1 -1
View File
@@ -458,7 +458,7 @@ class Response extends HttpResponse
// Tests (keep last)
->setModel(new Mock());
parent::__construct($response->swoole);
parent::__construct($response->swoole);
}
/**
+1 -1
View File
@@ -11,7 +11,7 @@ use Utopia\Queue;
use Utopia\Queue\Client;
use Utopia\System\System;
require_once __DIR__ . '/../../../app/init.php';
//require_once __DIR__ . '/../../../app/init.php';
class EventTest extends TestCase
{
+1 -1
View File
@@ -36,7 +36,7 @@ abstract class MigrationTest extends TestCase
*/
public function testMigrationVersions(): void
{
require_once __DIR__ . '/../../../app/init.php';
//require_once __DIR__ . '/../../../app/init.php';
foreach (Migration::$versions as $class) {
$this->assertTrue(class_exists('Appwrite\\Migration\\Version\\' . $class));
-1
View File
@@ -5,7 +5,6 @@ namespace Tests\Unit\Usage;
use Appwrite\URL\URL as AppwriteURL;
use PHPUnit\Framework\TestCase;
use Utopia\DSN\DSN;
use Utopia\Http\Http;
use Utopia\Queue;
use Utopia\Queue\Client;
use Utopia\Queue\Connection;