From 0b0d4257da279fabea127e8da7f6b66cdcc70316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Mon, 19 Aug 2024 18:06:11 +0200 Subject: [PATCH] feat: custom RDAP servers --- config/app/.gitignore | 1 + config/services.yaml | 2 ++ .../UpdateRdapServersHandler.php | 24 ++++++++++++++--- src/Service/RDAPService.php | 26 +++++++++++++++++-- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 config/app/.gitignore diff --git a/config/app/.gitignore b/config/app/.gitignore new file mode 100644 index 0000000..72667d9 --- /dev/null +++ b/config/app/.gitignore @@ -0,0 +1 @@ +/custom_rdap_servers.yaml diff --git a/config/services.yaml b/config/services.yaml index c7deee0..4ebaaab 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,6 +4,8 @@ # 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 parameters: + custom_rdap_servers_file: '%kernel.project_dir%/config/app/custom_rdap_servers.yaml' + mailer_sender_email: '%env(string:MAILER_SENDER_EMAIL)%' mailer_sender_name: '%env(string:MAILER_SENDER_NAME)%' oauth_enabled: '%env(OAUTH_CLIENT_ID)%' diff --git a/src/MessageHandler/UpdateRdapServersHandler.php b/src/MessageHandler/UpdateRdapServersHandler.php index 5002f8f..3d139af 100644 --- a/src/MessageHandler/UpdateRdapServersHandler.php +++ b/src/MessageHandler/UpdateRdapServersHandler.php @@ -4,6 +4,7 @@ namespace App\MessageHandler; use App\Message\UpdateRdapServers; use App\Service\RDAPService; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; @@ -14,8 +15,10 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; #[AsMessageHandler] 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 */ $throws = []; + try { $this->RDAPService->updateTldListIANA(); $this->RDAPService->updateGTldListICANN(); } catch (\Throwable $throwable) { $throws[] = $throwable; } + try { - $this->RDAPService->updateRDAPServers(); + $this->RDAPService->updateRDAPServersFromIANA(); } catch (\Throwable $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)) { throw $throws[0]; } diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index ff14969..f8c9b59 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -28,6 +28,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\HttpClient\Exception\ClientException; use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\Yaml\Yaml; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; @@ -424,14 +425,35 @@ readonly class RDAPService * @throws ClientExceptionInterface * @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( 'GET', 'https://data.iana.org/rdap/dns.json' )->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 ($service[0] as $tld) { if ('' === $tld) {