feat: custom RDAP servers

This commit is contained in:
Maël Gangloff
2024-08-19 18:06:11 +02:00
parent b473a6932a
commit 0b0d4257da
4 changed files with 48 additions and 5 deletions

1
config/app/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/custom_rdap_servers.yaml

View File

@@ -4,6 +4,8 @@
# Put parameters here that don't need to change on each machine where the app is deployed # Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters: parameters:
custom_rdap_servers_file: '%kernel.project_dir%/config/app/custom_rdap_servers.yaml'
mailer_sender_email: '%env(string:MAILER_SENDER_EMAIL)%' mailer_sender_email: '%env(string:MAILER_SENDER_EMAIL)%'
mailer_sender_name: '%env(string:MAILER_SENDER_NAME)%' mailer_sender_name: '%env(string:MAILER_SENDER_NAME)%'
oauth_enabled: '%env(OAUTH_CLIENT_ID)%' oauth_enabled: '%env(OAUTH_CLIENT_ID)%'

View File

@@ -4,6 +4,7 @@ namespace App\MessageHandler;
use App\Message\UpdateRdapServers; use App\Message\UpdateRdapServers;
use App\Service\RDAPService; use App\Service\RDAPService;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
@@ -14,8 +15,10 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
#[AsMessageHandler] #[AsMessageHandler]
final readonly class UpdateRdapServersHandler final readonly class UpdateRdapServersHandler
{ {
public function __construct(private RDAPService $RDAPService) public function __construct(
{ private RDAPService $RDAPService,
private ParameterBagInterface $bag
) {
} }
/** /**
@@ -29,17 +32,32 @@ final readonly class UpdateRdapServersHandler
{ {
/** @var \Throwable[] $throws */ /** @var \Throwable[] $throws */
$throws = []; $throws = [];
try { try {
$this->RDAPService->updateTldListIANA(); $this->RDAPService->updateTldListIANA();
$this->RDAPService->updateGTldListICANN(); $this->RDAPService->updateGTldListICANN();
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
$throws[] = $throwable; $throws[] = $throwable;
} }
try { try {
$this->RDAPService->updateRDAPServers(); $this->RDAPService->updateRDAPServersFromIANA();
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
$throws[] = $throwable; $throws[] = $throwable;
} }
try {
$this->RDAPService->updateRDAPServersFromIANA();
} catch (\Throwable $throwable) {
$throws[] = $throwable;
}
try {
$this->RDAPService->updateRDAPServersFromFile($this->bag->get('custom_rdap_servers_file'));
} catch (\Throwable $throwable) {
$throws[] = $throwable;
}
if (!empty($throws)) { if (!empty($throws)) {
throw $throws[0]; throw $throws[0];
} }

View File

@@ -28,6 +28,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Exception\ClientException; use Symfony\Component\HttpClient\Exception\ClientException;
use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Yaml\Yaml;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
@@ -424,14 +425,35 @@ readonly class RDAPService
* @throws ClientExceptionInterface * @throws ClientExceptionInterface
* @throws ORMException * @throws ORMException
*/ */
public function updateRDAPServers(): void public function updateRDAPServersFromIANA(): void
{ {
$this->logger->info('Started updating the RDAP server list.'); $this->logger->info('Start of update the RDAP server list from IANA.');
$dnsRoot = $this->client->request( $dnsRoot = $this->client->request(
'GET', 'https://data.iana.org/rdap/dns.json' 'GET', 'https://data.iana.org/rdap/dns.json'
)->toArray(); )->toArray();
$this->updateRDAPServers($dnsRoot);
}
/**
* @throws ORMException
*/
public function updateRDAPServersFromFile(string $fileName): void
{
if (!file_exists($fileName)) {
return;
}
$this->logger->info('Start of update the RDAP server list from custom config file.');
$this->updateRDAPServers(Yaml::parseFile($fileName));
}
/**
* @throws ORMException
*/
private function updateRDAPServers(array $dnsRoot): void
{
foreach ($dnsRoot['services'] as $service) { foreach ($dnsRoot['services'] as $service) {
foreach ($service[0] as $tld) { foreach ($service[0] as $tld) {
if ('' === $tld) { if ('' === $tld) {