Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions lib/Handler/CertificateEngine/CfsslHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private function isUp(): bool {
try {
$client = $this->getClient();
if (!$this->portOpen()) {
throw new LibresignException('CFSSL server is down', 500);
return false;
}
$response = $client
->request('get',
Expand All @@ -291,24 +291,18 @@ private function isUp(): bool {
]
)
;
} catch (RequestException|ConnectException $th) {
switch ($th->getCode()) {
case 404:
throw new \Exception('Endpoint /health of CFSSL server not found. Maybe you are using incompatible version of CFSSL server. Use latests version.', 1);
default:
if ($th->getHandlerContext() && $th->getHandlerContext()['error']) {
throw new \Exception($th->getHandlerContext()['error'], 1);
}
throw new LibresignException($th->getMessage(), 500);
} catch (ConnectException) {
// Port not yet accepting connections — server still starting
return false;
} catch (RequestException $th) {
if ($th->getCode() === 404) {
throw new \Exception('Endpoint /health of CFSSL server not found. Maybe you are using incompatible version of CFSSL server. Use latests version.', 1);
}
return false;
}

$responseDecoded = json_decode((string)$response->getBody(), true);
if (!isset($responseDecoded['success']) || !$responseDecoded['success']) {
throw new LibresignException('Error while check cfssl API health!', 500);
}

if (empty($responseDecoded['result']) || empty($responseDecoded['result']['healthy'])) {
if (empty($responseDecoded['result']['healthy'])) {
return false;
}

Expand Down Expand Up @@ -346,7 +340,7 @@ private function wakeUp(): void {
}

$loops = 0;
while (!$this->portOpen() && $loops <= 4) {
while (!$this->portOpen() && $loops <= 9) {
sleep(1);
$loops++;
}
Expand Down
Loading