From 624822594977b6ef972fd2d9ebb56f4e3f4d05bb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 29 Jun 2022 06:02:20 +0000 Subject: [PATCH] linter fixes --- app/controllers/api/functions.php | 2 +- app/controllers/api/storage.php | 2 +- src/Appwrite/OpenSSL/OpenSSL.php | 2 +- src/Appwrite/Resque/Worker.php | 19 +++++++++---------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index f31bcbd765..fee1c5ae1e 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -877,7 +877,7 @@ App::post('/v1/functions/:functionId/executions') } } - if(!$current->isEmpty()) { + if (!$current->isEmpty()) { $jwtObj = new JWT($project->getAttribute('jwtSecrets'), 'HS256', 900, 10); // Instantiate with key, algo, maxAge and leeway. $jwt = $jwtObj->encode([ 'userId' => $user->getId(), diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index e884abdf23..fc7e19fe9d 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -519,7 +519,7 @@ App::post('/v1/storage/buckets/:bucketId/files') $fileSecret = OpenSSL::secretString(); $iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM)); $tag = null; - + $data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $fileSecret, 0, $iv, $tag); $openSSLCipher = OpenSSL::CIPHER_AES_128_GCM; diff --git a/src/Appwrite/OpenSSL/OpenSSL.php b/src/Appwrite/OpenSSL/OpenSSL.php index b500bdd118..77e0092d8e 100644 --- a/src/Appwrite/OpenSSL/OpenSSL.php +++ b/src/Appwrite/OpenSSL/OpenSSL.php @@ -71,7 +71,7 @@ class OpenSSL * * @throws \Exception */ - public static function secretString(int $length = 128):string + public static function secretString(int $length = 128): string { return \bin2hex(self::randomPseudoBytes($length)); } diff --git a/src/Appwrite/Resque/Worker.php b/src/Appwrite/Resque/Worker.php index 594577f280..dfb8ba32a8 100644 --- a/src/Appwrite/Resque/Worker.php +++ b/src/Appwrite/Resque/Worker.php @@ -225,15 +225,14 @@ abstract class Worker $database = new Database(new MariaDB($register->get('db')), $cache); $database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); - if(!empty($projectId)) { + if (!empty($projectId)) { $database->setNamespace("_console"); $project = $database->getDocument('projects', $projectId); - if(!$project->isEmpty()) { - + if (!$project->isEmpty()) { $secrets = $project->getAttribute('databaseSecrets'); - + $filters['encrypt'] = [ - 'encode' => function($value) use($secrets) { + 'encode' => function ($value) use ($secrets) { $version = array_key_last($secrets); $key = $secrets[$version]; $iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM)); @@ -246,19 +245,19 @@ abstract class Worker 'version' => $version, ]); }, - 'decode' => function($value) use($secrets) { - if(is_null($value)) { + 'decode' => function ($value) use ($secrets) { + if (is_null($value)) { return null; } - + $value = json_decode($value, true); $version = $value['version']; $key = $secrets[$version]; - + return OpenSSL::decrypt($value['data'], $value['method'], $key, 0, hex2bin($value['iv']), hex2bin($value['tag'])); } ]; - + $database = new Database(new MariaDB($register->get('db')), $cache, $filters); $database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); }