Skip to content
Snippets Groups Projects
Commit b300c757 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Add a simple health check

Check if the LDAP connections works
parent 727be76d
No related branches found
No related tags found
No related merge requests found
Pipeline #86190 passed
<?php
declare(strict_types=1);
namespace Dbp\Relay\BasePersonConnectorLdapBundle\Service;
use Dbp\Relay\CoreBundle\HealthCheck\CheckInterface;
use Dbp\Relay\CoreBundle\HealthCheck\CheckOptions;
use Dbp\Relay\CoreBundle\HealthCheck\CheckResult;
class HealthCheck implements CheckInterface
{
private $ldap;
public function __construct(LDAPApi $ldap)
{
$this->ldap = $ldap;
}
public function getName(): string
{
return 'base-person-connector-ldap';
}
private function checkMethod(string $description, callable $func): CheckResult
{
$result = new CheckResult($description);
try {
$func();
} catch (\Throwable $e) {
$result->set(CheckResult::STATUS_FAILURE, $e->getMessage(), ['exception' => $e]);
return $result;
}
$result->set(CheckResult::STATUS_SUCCESS);
return $result;
}
public function check(CheckOptions $options): array
{
$results = [];
$results[] = $this->checkMethod('Check if we can connect to the LDAP server', [$this->ldap, 'checkConnection']);
return $results;
}
}
...@@ -106,6 +106,13 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -106,6 +106,13 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
$this->providerConfig['port'] = ($encryption === 'start_tls') ? 389 : 636; $this->providerConfig['port'] = ($encryption === 'start_tls') ? 389 : 636;
} }
public function checkConnection()
{
$provider = $this->getProvider();
$builder = $this->getCachedBuilder($provider);
$builder->first();
}
public function setDeploymentEnvironment(string $env) public function setDeploymentEnvironment(string $env)
{ {
$this->deploymentEnv = $env; $this->deploymentEnv = $env;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment