Add Health Certificate Response Model

This commit is contained in:
Khushboo Verma
2024-01-25 13:19:05 +05:30
parent 2d02d51fec
commit 6bd6a4f09c
4 changed files with 75 additions and 4 deletions
+4 -4
View File
@@ -401,7 +401,7 @@ App::get('/v1/health/certificate')
->label('sdk.description', '/docs/references/health/get-certificate.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)
->label('sdk.response.model', Response::MODEL_HEALTH_CERTIFICATE)
->param('domain', null, new Multiple([new Domain(), new PublicDomain()]), Multiple::TYPE_STRING, 'Domain name')
->inject('response')
->action(function (string $domain, Response $response) {
@@ -418,7 +418,7 @@ App::get('/v1/health/certificate')
$certificateInfo = openssl_x509_parse($certificate['options']['ssl']['peer_certificate']);
$certificatePayload = [
'name' => $certificateInfo['name'],
'subject' => $certificateInfo['subject'],
'subjectCN' => $certificateInfo['subject']['CN'],
'issuer' => $certificateInfo['issuer'],
'validFrom' => $certificateInfo['validFrom_time_t'],
'validTo' => $certificateInfo['validTo_time_t'],
@@ -434,8 +434,8 @@ App::get('/v1/health/certificate')
$response->dynamic(new Document([
'name' => 'certificate',
'status' => $status,
'ping' => 0
]), Response::MODEL_HEALTH_STATUS);
'payload' => json_encode($certificatePayload),
]), Response::MODEL_HEALTH_CERTIFICATE);
}, ['response']);
App::get('/v1/health/queue/certificates')
+3
View File
@@ -74,6 +74,7 @@ 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\HealthCertificate;
use Appwrite\Utopia\Response\Model\HealthQueue;
use Appwrite\Utopia\Response\Model\HealthStatus;
use Appwrite\Utopia\Response\Model\HealthTime;
@@ -272,6 +273,7 @@ class Response extends SwooleResponse
public const MODEL_HEALTH_TIME = 'healthTime';
public const MODEL_HEALTH_ANTIVIRUS = 'healthAntivirus';
public const MODEL_HEALTH_STATUS_LIST = 'healthStatusList';
public const MODEL_HEALTH_CERTIFICATE = 'healthCertificate';
// Console
public const MODEL_CONSOLE_VARIABLES = 'consoleVariables';
@@ -413,6 +415,7 @@ class Response extends SwooleResponse
->setModel(new HealthAntivirus())
->setModel(new HealthQueue())
->setModel(new HealthStatus())
->setModel(new HealthCertificate())
->setModel(new HealthTime())
->setModel(new HealthVersion())
->setModel(new Metric())
@@ -0,0 +1,58 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class HealthCertificate extends Model
{
public function __construct()
{
$this
->addRule('name', [
'type' => self::TYPE_STRING,
'description' => 'Name of the service.',
'default' => '',
'example' => 'database',
])
->addRule('payload', [
'type' => self::TYPE_JSON,
'description' => 'Certificate information payload',
'default' => [],
'example' => [
'name' => '/CN=www.google.com',
'validFrom' => '1704200998',
'validTo' => '1711458597',
'signatureTypeSN' => 'RSA-SHA256',
],
])
->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 Certificate';
}
/**
* Get Type
*
* @return string
*/
public function getType(): string
{
return Response::MODEL_HEALTH_CERTIFICATE;
}
}
@@ -439,6 +439,11 @@ class HealthCustomServerTest extends Scope
$this->assertNotEmpty($response['body']['status']);
$this->assertIsString($response['body']['status']);
$this->assertEquals('pass', $response['body']['status']);
$this->assertNotEmpty($response['body']['payload']);
$payload = json_decode($response['body']['payload']);
$this->assertEquals('www.google.com', $payload->subjectCN);
$this->assertEquals('Google Trust Services LLC', $payload->issuer->O);
$this->assertIsInt($payload->validFrom);
$response = $this->client->call(Client::METHOD_GET, '/health/certificate?domain=appwrite.io', array_merge([
'content-type' => 'application/json',
@@ -449,6 +454,11 @@ class HealthCustomServerTest extends Scope
$this->assertNotEmpty($response['body']['status']);
$this->assertIsString($response['body']['status']);
$this->assertEquals('pass', $response['body']['status']);
$this->assertNotEmpty($response['body']['payload']);
$payload = json_decode($response['body']['payload']);
$this->assertEquals('appwrite.io', $payload->subjectCN);
$this->assertEquals("Let's Encrypt", $payload->issuer->O);
$this->assertIsInt($payload->validFrom);
$response = $this->client->call(Client::METHOD_GET, '/health/certificate?domain=https://google.com', array_merge([
'content-type' => 'application/json',