Renamed variable names

This commit is contained in:
Khushboo Verma
2024-01-29 14:53:39 +05:30
parent 6bd6a4f09c
commit b5d812207c
6 changed files with 32 additions and 40 deletions
+6 -6
View File
@@ -795,15 +795,15 @@ return [
'publish' => false
],
Exception::CERTIFICATE_EXPIRED => [
'name' => Exception::CERTIFICATE_EXPIRED,
'description' => 'Certificate expired.',
Exception::HEALTH_CERTIFICATE_EXPIRED => [
'name' => Exception::HEALTH_CERTIFICATE_EXPIRED,
'description' => 'The SSL certificate for the specified domain has expired and is no longer valid.',
'code' => 404,
],
Exception::INVALID_HOST => [
'name' => Exception::INVALID_HOST,
'description' => 'Host not found.',
Exception::HEALTH_INVALID_HOST => [
'name' => Exception::HEALTH_INVALID_HOST,
'description' => 'Failed to establish a connection to the specified domain. Please verify the domain name and ensure that the server is running and accessible.',
'code' => 404,
],
+23 -16
View File
@@ -392,7 +392,7 @@ App::get('/v1/health/queue/logs')
}, ['response']);
App::get('/v1/health/certificate')
->desc('Get status of certificate for a domain to check whether it is still valid or expired.')
->desc('Get the SSL certificate for a domain')
->groups(['api', 'health'])
->label('scope', 'health.read')
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
@@ -409,31 +409,38 @@ App::get('/v1/health/certificate')
$domain = parse_url($domain, PHP_URL_HOST);
}
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => true)));
$read = stream_socket_client("ssl://" . $domain . ":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
if (!$read) {
throw new Exception(Exception::INVALID_HOST, 'The domain is not valid.');
$sslContext = stream_context_create([
"ssl" => [
"capture_peer_cert" => true
]
]);
$sslSocket = stream_socket_client("ssl://" . $domain . ":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $sslContext);
if (!$sslSocket) {
throw new Exception(Exception::HEALTH_INVALID_HOST);
}
$certificate = stream_context_get_params($read);
$certificateInfo = openssl_x509_parse($certificate['options']['ssl']['peer_certificate']);
$streamContextParams = stream_context_get_params($sslSocket);
$peerCertificate = $streamContextParams['options']['ssl']['peer_certificate'];
$parsedCertificate = openssl_x509_parse($peerCertificate);
$certificatePayload = [
'name' => $certificateInfo['name'],
'subjectCN' => $certificateInfo['subject']['CN'],
'issuer' => $certificateInfo['issuer'],
'validFrom' => $certificateInfo['validFrom_time_t'],
'validTo' => $certificateInfo['validTo_time_t'],
'signatureTypeSN' => $certificateInfo['signatureTypeSN'],
'name' => $parsedCertificate['name'],
'subjectCN' => $parsedCertificate['subject']['CN'],
'issuer' => $parsedCertificate['issuer'],
'validFrom' => $parsedCertificate['validFrom_time_t'],
'validTo' => $parsedCertificate['validTo_time_t'],
'signatureTypeSN' => $parsedCertificate['signatureTypeSN'],
];
$sslExpiration = $certificateInfo['validTo_time_t'];
$sslExpiration = $parsedCertificate['validTo_time_t'];
$status = ($sslExpiration < time()) ? 'fail' : 'pass';
if ($status == 'fail') {
throw new Exception(Exception::CERTIFICATE_EXPIRED, 'The certificate of the domain has expired.');
throw new Exception(Exception::HEALTH_CERTIFICATE_EXPIRED);
}
$response->dynamic(new Document([
'name' => 'certificate',
'status' => $status,
'payload' => json_encode($certificatePayload),
]), Response::MODEL_HEALTH_CERTIFICATE);
}, ['response']);
+1 -1
View File
@@ -1 +1 @@
Get status of certificate for a domain to check whether it is still valid or expired.
Get the SSL certificate for a domain
+2 -2
View File
@@ -239,8 +239,8 @@ class Exception extends \Exception
/** Health */
public const QUEUE_SIZE_EXCEEDED = 'queue_size_exceeded';
public const CERTIFICATE_EXPIRED = 'certificate_expired';
public const INVALID_HOST = 'invalid_host';
public const HEALTH_CERTIFICATE_EXPIRED = 'health_certificate_expired';
public const HEALTH_INVALID_HOST = 'health_invalid_host';
/** Provider */
public const PROVIDER_NOT_FOUND = 'provider_not_found';
@@ -27,12 +27,6 @@ class HealthCertificate extends Model
'signatureTypeSN' => 'RSA-SHA256',
],
])
->addRule('status', [
'type' => self::TYPE_STRING,
'description' => 'Service status. Possible values can are: `pass`, `fail`',
'default' => '',
'example' => 'pass',
])
;
}
@@ -436,9 +436,6 @@ class HealthCustomServerTest extends Scope
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$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);
@@ -451,9 +448,6 @@ class HealthCustomServerTest extends Scope
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$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);
@@ -466,9 +460,6 @@ class HealthCustomServerTest extends Scope
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['status']);
$this->assertIsString($response['body']['status']);
$this->assertEquals('pass', $response['body']['status']);
/**
* Test for FAILURE