diff --git a/CHANGES.md b/CHANGES.md index 0f67bc590..536eb247b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,14 @@ - Grouped auth related attributes in project collection. Introduced new attribute `auths` and removed all attributes related to auth methods and `usersAuthLimit` as well, all these are grouped under `auths` attribute - Grouped oAuth related attributes in project collection. Introduced new attribute `providers` and removed all attributes related to OAuth2 providers. All OAuth2 attributes are grouped under `providers` - Project model changed, `userAuth` => `auth` example `userAuthEmailPassword` => `authEmailPassword`, also `userOauth2...` => `provider...` example `userOauth2GithubAppid` => `providerGithubAppid` + +# Version 0.12.0 + +## Breaking Changes (Read before upgrading!) + +- Multiple HealthAPI response models were changed to new (better) schema +- Method `health.getAntiVirus()` has been renamed to `health.getAntivirus()` + # Version 0.11.0 ## Features diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 60b778d83..38024bb45 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -1,11 +1,13 @@ desc('Get HTTP') @@ -15,22 +17,33 @@ App::get('/v1/health') ->label('sdk.namespace', 'health') ->label('sdk.method', 'get') ->label('sdk.description', '/docs/references/health/get.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_STATUS) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ - $response->json(['status' => 'OK']); + $output = [ + 'status' => 'pass', + 'ping' => 0 + ]; + + $response->dynamic(new Document($output), Response::MODEL_HEALTH_STATUS); }); App::get('/v1/health/version') ->desc('Get Version') ->groups(['api', 'health']) ->label('scope', 'public') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_VERSION) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ - $response->json(['version' => APP_VERSION_STABLE]); + $response->dynamic(new Document([ 'version' => APP_VERSION_STABLE ]), Response::MODEL_HEALTH_VERSION); }); App::get('/v1/health/db') @@ -41,11 +54,17 @@ App::get('/v1/health/db') ->label('sdk.namespace', 'health') ->label('sdk.method', 'getDB') ->label('sdk.description', '/docs/references/health/get-db.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_STATUS) ->inject('response') ->inject('utopia') ->action(function ($response, $utopia) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\App $utopia */ + + $checkStart = \microtime(true); + try { $db = $utopia->getResource('db'); /* @var $db PDO */ @@ -59,7 +78,12 @@ App::get('/v1/health/db') throw new Exception('Database is not available', 500); } - return $response->json(['status' => 'OK']); + $output = [ + 'status' => 'pass', + 'ping' => \round((\microtime(true) - $checkStart) / 1000) + ]; + + $response->dynamic(new Document($output), Response::MODEL_HEALTH_STATUS); }); App::get('/v1/health/cache') @@ -70,19 +94,30 @@ App::get('/v1/health/cache') ->label('sdk.namespace', 'health') ->label('sdk.method', 'getCache') ->label('sdk.description', '/docs/references/health/get-cache.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_STATUS) ->inject('response') ->inject('utopia') ->action(function ($response, $utopia) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\App $utopia */ /** @var Redis */ + + $checkStart = \microtime(true); + $redis = $utopia->getResource('cache'); - if ($redis->ping(true)) { - return $response->json(['status' => 'OK']); - } else { + if (!$redis->ping(true)) { throw new Exception('Cache is not available', 500); } + + $output = [ + 'status' => 'pass', + 'ping' => \round((\microtime(true) - $checkStart) / 1000) + ]; + + $response->dynamic(new Document($output), Response::MODEL_HEALTH_STATUS); }); App::get('/v1/health/time') @@ -93,6 +128,9 @@ App::get('/v1/health/time') ->label('sdk.namespace', 'health') ->label('sdk.method', 'getTime') ->label('sdk.description', '/docs/references/health/get-time.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_TIME) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ @@ -131,7 +169,13 @@ App::get('/v1/health/time') throw new Exception('Server time gaps detected'); } - $response->json(['remote' => $timestamp, 'local' => \time(), 'diff' => $diff]); + $output = [ + 'remoteTime' => $timestamp, + 'localTime' => \time(), + 'diff' => $diff + ]; + + $response->dynamic(new Document($output), Response::MODEL_HEALTH_TIME); }); App::get('/v1/health/queue/webhooks') @@ -142,11 +186,14 @@ App::get('/v1/health/queue/webhooks') ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueWebhooks') ->label('sdk.description', '/docs/references/health/get-queue-webhooks.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ - $response->json(['size' => Resque::size(Event::WEBHOOK_QUEUE_NAME)]); + $response->dynamic(new Document([ 'size' => Resque::size(Event::WEBHOOK_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/logs') @@ -157,11 +204,14 @@ App::get('/v1/health/queue/logs') ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueLogs') ->label('sdk.description', '/docs/references/health/get-queue-logs.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ - $response->json(['size' => Resque::size(Event::AUDITS_QUEUE_NAME)]); + $response->dynamic(new Document([ 'size' => Resque::size(Event::AUDITS_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/usage') @@ -172,11 +222,14 @@ App::get('/v1/health/queue/usage') ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueUsage') ->label('sdk.description', '/docs/references/health/get-queue-usage.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ - $response->json(['size' => Resque::size(Event::USAGE_QUEUE_NAME)]); + $response->dynamic(new Document([ 'size' => Resque::size(Event::USAGE_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/certificates') @@ -187,11 +240,14 @@ App::get('/v1/health/queue/certificates') ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueCertificates') ->label('sdk.description', '/docs/references/health/get-queue-certificates.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ - $response->json(['size' => Resque::size(Event::CERTIFICATES_QUEUE_NAME)]); + $response->dynamic(new Document([ 'size' => Resque::size(Event::CERTIFICATES_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/queue/functions') @@ -202,11 +258,14 @@ App::get('/v1/health/queue/functions') ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueFunctions') ->label('sdk.description', '/docs/references/health/get-queue-functions.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_QUEUE) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ - $response->json(['size' => Resque::size(Event::FUNCTIONS_QUEUE_NAME)]); + $response->dynamic(new Document([ 'size' => Resque::size(Event::FUNCTIONS_QUEUE_NAME) ]), Response::MODEL_HEALTH_QUEUE); }, ['response']); App::get('/v1/health/storage/local') @@ -217,10 +276,15 @@ App::get('/v1/health/storage/local') ->label('sdk.namespace', 'health') ->label('sdk.method', 'getStorageLocal') ->label('sdk.description', '/docs/references/health/get-storage-local.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_STATUS) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ + $checkStart = \microtime(true); + foreach ([ 'Uploads' => APP_STORAGE_UPLOADS, 'Cache' => APP_STORAGE_CACHE, @@ -238,41 +302,51 @@ App::get('/v1/health/storage/local') } } - $response->json(['status' => 'OK']); + $output = [ + 'status' => 'pass', + 'ping' => \round((\microtime(true) - $checkStart) / 1000) + ]; + + $response->dynamic(new Document($output), Response::MODEL_HEALTH_STATUS); }); App::get('/v1/health/anti-virus') - ->desc('Get Anti virus') + ->desc('Get Antivirus') ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'health') - ->label('sdk.method', 'getAntiVirus') + ->label('sdk.method', 'getAntivirus') ->label('sdk.description', '/docs/references/health/get-storage-anti-virus.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_HEALTH_ANTIVIRUS) ->inject('response') ->action(function ($response) { /** @var Appwrite\Utopia\Response $response */ + $output = [ + 'status' => '', + 'version' => '' + ]; + if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled - return $response->json([ - 'status' => 'disabled', - 'version' => '', - ]); + $output['status'] = 'disabled'; + $output['version'] = ''; + } else { + $antivirus = new Network(App::getEnv('_APP_STORAGE_ANTIVIRUS_HOST', 'clamav'), + (int) App::getEnv('_APP_STORAGE_ANTIVIRUS_PORT', 3310)); + + try { + $output['version'] = @$antivirus->version(); + $output['status'] = (@$antivirus->ping()) ? 'pass' : 'fail'; + } catch( \Exception $e) { + $output['status'] = 'offline'; + $output['version'] = ''; + } } - $antiVirus = new Network(App::getEnv('_APP_STORAGE_ANTIVIRUS_HOST', 'clamav'), - (int) App::getEnv('_APP_STORAGE_ANTIVIRUS_PORT', 3310)); - try { - $response->json([ - 'status' => (@$antiVirus->ping()) ? 'online' : 'offline', - 'version' => @$antiVirus->version(), - ]); - } catch (Throwable $e) { - $response->json([ - 'status' => 'offline', - 'version' => '', - ]); - } + $response->dynamic(new Document($output), Response::MODEL_HEALTH_ANTIVIRUS); }); App::get('/v1/health/stats') // Currently only used internally diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index f137d58c4..1b58cda27 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -122,10 +122,10 @@ App::post('/v1/storage/files') $mimeType = $device->getFileMimeType($path); // Get mime-type before compression and encryption if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled - $antiVirus = new Network(App::getEnv('_APP_STORAGE_ANTIVIRUS_HOST', 'clamav'), + $antivirus = new Network(App::getEnv('_APP_STORAGE_ANTIVIRUS_HOST', 'clamav'), (int) App::getEnv('_APP_STORAGE_ANTIVIRUS_PORT', 3310)); - if (!$antiVirus->fileScan($path)) { + if (!$antivirus->fileScan($path)) { $device->delete($path); throw new Exception('Invalid file', 403); } @@ -882,4 +882,4 @@ App::get('/v1/storage/:bucketId/usage') } $response->dynamic($usage, Response::MODEL_USAGE_BUCKETS); - }); \ No newline at end of file + }); diff --git a/app/tasks/doctor.php b/app/tasks/doctor.php index 095adfb95..47e523ff9 100644 --- a/app/tasks/doctor.php +++ b/app/tasks/doctor.php @@ -113,17 +113,17 @@ $cli if(App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled try { - $antiVirus = new Network(App::getEnv('_APP_STORAGE_ANTIVIRUS_HOST', 'clamav'), + $antivirus = new Network(App::getEnv('_APP_STORAGE_ANTIVIRUS_HOST', 'clamav'), (int) App::getEnv('_APP_STORAGE_ANTIVIRUS_PORT', 3310)); - if((@$antiVirus->ping())) { - Console::success('AntiVirus...........connected 👍'); + if((@$antivirus->ping())) { + Console::success('Antivirus...........connected 👍'); } else { - Console::error('AntiVirus........disconnected 👎'); + Console::error('Antivirus........disconnected 👎'); } } catch (\Throwable $th) { - Console::error('AntiVirus........disconnected 👎'); + Console::error('Antivirus........disconnected 👎'); } } diff --git a/docs/references/health/get-storage-anti-virus.md b/docs/references/health/get-storage-anti-virus.md index 55bdb1963..a40f81a37 100644 --- a/docs/references/health/get-storage-anti-virus.md +++ b/docs/references/health/get-storage-anti-virus.md @@ -1 +1 @@ -Check the Appwrite Anti Virus server is up and connection is successful. \ No newline at end of file +Check the Appwrite Antivirus server is up and connection is successful. \ No newline at end of file diff --git a/docs/specs/overview.drawio.svg b/docs/specs/overview.drawio.svg index 516749492..f86059e2a 100644 --- a/docs/specs/overview.drawio.svg +++ b/docs/specs/overview.drawio.svg @@ -714,13 +714,13 @@
- AntiVirus (ClamAV) + Antivirus (ClamAV)
- AntiVirus (ClamAV) + Antivirus (ClamAV) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 5c8bd722d..8bf8b52ee 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -52,6 +52,11 @@ use Appwrite\Utopia\Response\Model\Tag; use Appwrite\Utopia\Response\Model\Token; use Appwrite\Utopia\Response\Model\Webhook; use Appwrite\Utopia\Response\Model\Preferences; +use Appwrite\Utopia\Response\Model\HealthAntivirus; +use Appwrite\Utopia\Response\Model\HealthQueue; +use Appwrite\Utopia\Response\Model\HealthStatus; +use Appwrite\Utopia\Response\Model\HealthTime; +use Appwrite\Utopia\Response\Model\HealthVersion; use Appwrite\Utopia\Response\Model\Mock; // Keep last use Appwrite\Utopia\Response\Model\Runtime; use Appwrite\Utopia\Response\Model\UsageBuckets; @@ -160,6 +165,13 @@ class Response extends SwooleResponse const MODEL_PLATFORM_LIST = 'platformList'; const MODEL_DOMAIN = 'domain'; const MODEL_DOMAIN_LIST = 'domainList'; + + // Health + const MODEL_HEALTH_STATUS = 'healthStatus'; + const MODEL_HEALTH_VERSION = 'healthVersion'; + const MODEL_HEALTH_QUEUE = 'healthQueue'; + const MODEL_HEALTH_TIME = 'healthTime'; + const MODEL_HEALTH_ANTIVIRUS = 'healthAntivirus'; // Deprecated const MODEL_PERMISSIONS = 'permissions'; @@ -255,6 +267,11 @@ class Response extends SwooleResponse ->setModel(new Language()) ->setModel(new Currency()) ->setModel(new Phone()) + ->setModel(new HealthAntivirus()) + ->setModel(new HealthQueue()) + ->setModel(new HealthStatus()) + ->setModel(new HealthTime()) + ->setModel(new HealthVersion()) ->setModel(new Metric()) ->setModel(new UsageDatabase()) ->setModel(new UsageCollection()) diff --git a/src/Appwrite/Utopia/Response/Model/Any.php b/src/Appwrite/Utopia/Response/Model/Any.php index 1613f0728..44f588250 100644 --- a/src/Appwrite/Utopia/Response/Model/Any.php +++ b/src/Appwrite/Utopia/Response/Model/Any.php @@ -23,7 +23,7 @@ class Any extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/BaseList.php b/src/Appwrite/Utopia/Response/Model/BaseList.php index 8328853c6..f3fa35abf 100644 --- a/src/Appwrite/Utopia/Response/Model/BaseList.php +++ b/src/Appwrite/Utopia/Response/Model/BaseList.php @@ -58,7 +58,7 @@ class BaseList extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Collection.php b/src/Appwrite/Utopia/Response/Model/Collection.php index 933b5f64f..69a1c7184 100644 --- a/src/Appwrite/Utopia/Response/Model/Collection.php +++ b/src/Appwrite/Utopia/Response/Model/Collection.php @@ -85,7 +85,7 @@ class Collection extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Continent.php b/src/Appwrite/Utopia/Response/Model/Continent.php index b7311d0d4..2d12f9d6a 100644 --- a/src/Appwrite/Utopia/Response/Model/Continent.php +++ b/src/Appwrite/Utopia/Response/Model/Continent.php @@ -36,7 +36,7 @@ class Continent extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Country.php b/src/Appwrite/Utopia/Response/Model/Country.php index 3c9eb6b6e..1595aea75 100644 --- a/src/Appwrite/Utopia/Response/Model/Country.php +++ b/src/Appwrite/Utopia/Response/Model/Country.php @@ -36,7 +36,7 @@ class Country extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Currency.php b/src/Appwrite/Utopia/Response/Model/Currency.php index 10d0d77ff..d6f9a6b16 100644 --- a/src/Appwrite/Utopia/Response/Model/Currency.php +++ b/src/Appwrite/Utopia/Response/Model/Currency.php @@ -66,7 +66,7 @@ class Currency extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Document.php b/src/Appwrite/Utopia/Response/Model/Document.php index 25aea0b2b..f911f9ab7 100644 --- a/src/Appwrite/Utopia/Response/Model/Document.php +++ b/src/Appwrite/Utopia/Response/Model/Document.php @@ -17,7 +17,7 @@ class Document extends Any } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Domain.php b/src/Appwrite/Utopia/Response/Model/Domain.php index 20ee9b853..9bd665fa2 100644 --- a/src/Appwrite/Utopia/Response/Model/Domain.php +++ b/src/Appwrite/Utopia/Response/Model/Domain.php @@ -65,7 +65,7 @@ class Domain extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Error.php b/src/Appwrite/Utopia/Response/Model/Error.php index 118e405d8..507b25209 100644 --- a/src/Appwrite/Utopia/Response/Model/Error.php +++ b/src/Appwrite/Utopia/Response/Model/Error.php @@ -42,7 +42,7 @@ class Error extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/ErrorDev.php b/src/Appwrite/Utopia/Response/Model/ErrorDev.php index 779314e59..abe2229ea 100644 --- a/src/Appwrite/Utopia/Response/Model/ErrorDev.php +++ b/src/Appwrite/Utopia/Response/Model/ErrorDev.php @@ -39,7 +39,7 @@ class ErrorDev extends Error } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Execution.php b/src/Appwrite/Utopia/Response/Model/Execution.php index 34c939b6c..cd8618451 100644 --- a/src/Appwrite/Utopia/Response/Model/Execution.php +++ b/src/Appwrite/Utopia/Response/Model/Execution.php @@ -85,7 +85,7 @@ class Execution extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/File.php b/src/Appwrite/Utopia/Response/Model/File.php index 32d9bab14..ac553cf2b 100644 --- a/src/Appwrite/Utopia/Response/Model/File.php +++ b/src/Appwrite/Utopia/Response/Model/File.php @@ -74,7 +74,7 @@ class File extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php index f731438b0..7b497389a 100644 --- a/src/Appwrite/Utopia/Response/Model/Func.php +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -110,7 +110,7 @@ class Func extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/HealthAntivirus.php b/src/Appwrite/Utopia/Response/Model/HealthAntivirus.php new file mode 100644 index 000000000..26bc8f827 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/HealthAntivirus.php @@ -0,0 +1,47 @@ +addRule('version', [ + 'type' => self::TYPE_STRING, + 'description' => 'Antivirus version.', + 'default' => '', + 'example' => '1.0.0', + ]) + ->addRule('status', [ + 'type' => self::TYPE_STRING, + 'description' => 'Antivirus status. Possible values can are: `disabled`, `offline`, `online`', + 'default' => '', + 'example' => 'online', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Health Antivirus'; + } + + /** + * Get Type + * + * @return string + */ + public function getType():string + { + return Response::MODEL_HEALTH_ANTIVIRUS; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/HealthQueue.php b/src/Appwrite/Utopia/Response/Model/HealthQueue.php new file mode 100644 index 000000000..04120a1ad --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/HealthQueue.php @@ -0,0 +1,41 @@ +addRule('size', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Amount of actions in the queue.', + 'default' => 0, + 'example' => 8, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Health Queue'; + } + + /** + * Get Type + * + * @return string + */ + public function getType():string + { + return Response::MODEL_HEALTH_QUEUE; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/HealthStatus.php b/src/Appwrite/Utopia/Response/Model/HealthStatus.php new file mode 100644 index 000000000..2887c3c4d --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/HealthStatus.php @@ -0,0 +1,47 @@ +addRule('ping', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Duration in milliseconds how long the health check took.', + 'default' => 0, + 'example' => 128, + ]) + ->addRule('status', [ + 'type' => self::TYPE_STRING, + 'description' => 'Service status. Possible values can are: `pass`, `fail`', + 'default' => '', + 'example' => 'pass', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Health Status'; + } + + /** + * Get Type + * + * @return string + */ + public function getType():string + { + return Response::MODEL_HEALTH_STATUS; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/HealthTime.php b/src/Appwrite/Utopia/Response/Model/HealthTime.php new file mode 100644 index 000000000..2bd666ed2 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/HealthTime.php @@ -0,0 +1,53 @@ +addRule('remoteTime', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Current unix timestamp on trustful remote server.', + 'default' => 0, + 'example' => 1639490751, + ]) + ->addRule('localTime', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Current unix timestamp of local server where Appwrite runs.', + 'default' => 0, + 'example' => 1639490844, + ]) + ->addRule('diff', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Difference of unix remote and local timestamps in milliseconds.', + 'default' => 0, + 'example' => 93, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Health Time'; + } + + /** + * Get Type + * + * @return string + */ + public function getType():string + { + return Response::MODEL_HEALTH_TIME; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/HealthVersion.php b/src/Appwrite/Utopia/Response/Model/HealthVersion.php new file mode 100644 index 000000000..fed63714c --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/HealthVersion.php @@ -0,0 +1,41 @@ +addRule('version', [ + 'type' => self::TYPE_STRING, + 'description' => 'Version of the Appwrite instance.', + 'default' => '', + 'example' => '0.11.0', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Health Version'; + } + + /** + * Get Type + * + * @return string + */ + public function getType():string + { + return Response::MODEL_HEALTH_VERSION; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/JWT.php b/src/Appwrite/Utopia/Response/Model/JWT.php index b30f51702..577747991 100644 --- a/src/Appwrite/Utopia/Response/Model/JWT.php +++ b/src/Appwrite/Utopia/Response/Model/JWT.php @@ -29,7 +29,7 @@ class JWT extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Key.php b/src/Appwrite/Utopia/Response/Model/Key.php index bca3ba7f9..c01136d24 100644 --- a/src/Appwrite/Utopia/Response/Model/Key.php +++ b/src/Appwrite/Utopia/Response/Model/Key.php @@ -54,7 +54,7 @@ class Key extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Language.php b/src/Appwrite/Utopia/Response/Model/Language.php index 77a115ab6..e56dd7a74 100644 --- a/src/Appwrite/Utopia/Response/Model/Language.php +++ b/src/Appwrite/Utopia/Response/Model/Language.php @@ -42,7 +42,7 @@ class Language extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Locale.php b/src/Appwrite/Utopia/Response/Model/Locale.php index c725d65f9..292ea1d82 100644 --- a/src/Appwrite/Utopia/Response/Model/Locale.php +++ b/src/Appwrite/Utopia/Response/Model/Locale.php @@ -66,7 +66,7 @@ class Locale extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Log.php b/src/Appwrite/Utopia/Response/Model/Log.php index 8752c6c87..ba2e52dbc 100644 --- a/src/Appwrite/Utopia/Response/Model/Log.php +++ b/src/Appwrite/Utopia/Response/Model/Log.php @@ -150,7 +150,7 @@ class Log extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Membership.php b/src/Appwrite/Utopia/Response/Model/Membership.php index 419eeac3e..2ea309ab3 100644 --- a/src/Appwrite/Utopia/Response/Model/Membership.php +++ b/src/Appwrite/Utopia/Response/Model/Membership.php @@ -79,7 +79,7 @@ class Membership extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Mock.php b/src/Appwrite/Utopia/Response/Model/Mock.php index 349042152..ae3030828 100644 --- a/src/Appwrite/Utopia/Response/Model/Mock.php +++ b/src/Appwrite/Utopia/Response/Model/Mock.php @@ -30,7 +30,7 @@ class Mock extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/None.php b/src/Appwrite/Utopia/Response/Model/None.php index 956ba0b72..78d990ea1 100644 --- a/src/Appwrite/Utopia/Response/Model/None.php +++ b/src/Appwrite/Utopia/Response/Model/None.php @@ -23,7 +23,7 @@ class None extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Phone.php b/src/Appwrite/Utopia/Response/Model/Phone.php index 5f1153a76..744f90372 100644 --- a/src/Appwrite/Utopia/Response/Model/Phone.php +++ b/src/Appwrite/Utopia/Response/Model/Phone.php @@ -42,7 +42,7 @@ class Phone extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Platform.php b/src/Appwrite/Utopia/Response/Model/Platform.php index f48f9890a..0377b0caf 100644 --- a/src/Appwrite/Utopia/Response/Model/Platform.php +++ b/src/Appwrite/Utopia/Response/Model/Platform.php @@ -76,7 +76,7 @@ class Platform extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Preferences.php b/src/Appwrite/Utopia/Response/Model/Preferences.php index c95c13710..68e178163 100644 --- a/src/Appwrite/Utopia/Response/Model/Preferences.php +++ b/src/Appwrite/Utopia/Response/Model/Preferences.php @@ -22,7 +22,7 @@ class Preferences extends Any } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index fd06b9611..fb7ee0138 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -196,7 +196,7 @@ class Project extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Session.php b/src/Appwrite/Utopia/Response/Model/Session.php index 81b975fb7..bb7b039ef 100644 --- a/src/Appwrite/Utopia/Response/Model/Session.php +++ b/src/Appwrite/Utopia/Response/Model/Session.php @@ -156,7 +156,7 @@ class Session extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Tag.php b/src/Appwrite/Utopia/Response/Model/Tag.php index 27c80c1c2..954020104 100644 --- a/src/Appwrite/Utopia/Response/Model/Tag.php +++ b/src/Appwrite/Utopia/Response/Model/Tag.php @@ -54,7 +54,7 @@ class Tag extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Team.php b/src/Appwrite/Utopia/Response/Model/Team.php index 8cd8977ea..d9627f91b 100644 --- a/src/Appwrite/Utopia/Response/Model/Team.php +++ b/src/Appwrite/Utopia/Response/Model/Team.php @@ -48,7 +48,7 @@ class Team extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Token.php b/src/Appwrite/Utopia/Response/Model/Token.php index df812a51a..84dc46773 100644 --- a/src/Appwrite/Utopia/Response/Model/Token.php +++ b/src/Appwrite/Utopia/Response/Model/Token.php @@ -48,7 +48,7 @@ class Token extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index 2d4e6821a..fd65b6a7e 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -72,7 +72,7 @@ class User extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/src/Appwrite/Utopia/Response/Model/Webhook.php b/src/Appwrite/Utopia/Response/Model/Webhook.php index fe3ce8489..14f45164a 100644 --- a/src/Appwrite/Utopia/Response/Model/Webhook.php +++ b/src/Appwrite/Utopia/Response/Model/Webhook.php @@ -72,7 +72,7 @@ class Webhook extends Model } /** - * Get Collection + * Get Type * * @return string */ diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index d7989c6a5..f7483d797 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -25,7 +25,9 @@ class HealthCustomServerTest extends Scope ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('OK', $response['body']['status']); + $this->assertEquals('pass', $response['body']['status']); + $this->assertIsInt($response['body']['ping']); + $this->assertLessThan(100, $response['body']['ping']); /** * Test for FAILURE @@ -45,7 +47,9 @@ class HealthCustomServerTest extends Scope ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('OK', $response['body']['status']); + $this->assertEquals('pass', $response['body']['status']); + $this->assertIsInt($response['body']['ping']); + $this->assertLessThan(100, $response['body']['ping']); /** * Test for FAILURE @@ -65,7 +69,9 @@ class HealthCustomServerTest extends Scope ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('OK', $response['body']['status']); + $this->assertEquals('pass', $response['body']['status']); + $this->assertIsInt($response['body']['ping']); + $this->assertLessThan(100, $response['body']['ping']); /** * Test for FAILURE @@ -85,10 +91,10 @@ class HealthCustomServerTest extends Scope ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['remote']); - $this->assertIsInt($response['body']['local']); - $this->assertNotEmpty($response['body']['remote']); - $this->assertNotEmpty($response['body']['local']); + $this->assertIsInt($response['body']['remoteTime']); + $this->assertIsInt($response['body']['localTime']); + $this->assertNotEmpty($response['body']['remoteTime']); + $this->assertNotEmpty($response['body']['localTime']); $this->assertLessThan(10, $response['body']['diff']); /** @@ -193,7 +199,9 @@ class HealthCustomServerTest extends Scope ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('OK', $response['body']['status']); + $this->assertEquals('pass', $response['body']['status']); + $this->assertIsInt($response['body']['ping']); + $this->assertLessThan(100, $response['body']['ping']); /** * Test for FAILURE