fix: remove DomainStatus enum

This commit is contained in:
Maël Gangloff
2024-07-14 21:15:13 +02:00
parent d202aa8964
commit 8a8059a366
6 changed files with 257 additions and 76 deletions

View File

@@ -1,47 +0,0 @@
<?php
namespace App\Config;
/**
* @see https://www.iana.org/assignments/rdap-json-values/rdap-json-values.xhtml
*/
enum DomainStatus: string
{
case Validated = 'validated';
case RenewProhibited = 'renew prohibited';
case UpdateProhibited = 'update prohibited';
case TransferProhibited = 'transfer prohibited';
case DeleteProhibited = 'delete prohibited';
case Proxy = 'proxy';
case Private = 'private';
case Removed = 'removed';
case Obscured = 'obscured';
case Associated = 'associated';
case Active = 'active';
case Inactive = 'inactive';
case Locked = 'locked';
case PendingCreate = 'pending create';
case PendingRenew = 'pending renew';
case PendingTransfer = 'pending transfer';
case PendingUpdate = 'pending update';
case PendingDelete = 'pending delete';
case AddPeriod = 'add period';
case AutoRenewPeriod = 'auto renew period';
case ClientDeleteProhibited = 'client delete prohibited';
case ClientHold = 'client hold';
case ClientRenewProhibited = 'client renew prohibited';
case ClientTransferProhibited = 'client transfer prohibited';
case ClientUpdateProhibited = 'client update prohibited';
case PendingRestore = 'pending restore';
case RedemptionPeriod = 'redemption period';
case RenewPeriod = 'renew period';
case ServerDeleteProhibited = 'server delete prohibited';
case ServerRenewProhibited = 'server renew prohibited';
case ServerTransferProhibited = 'server transfer prohibited';
case ServerUpdateProhibited = 'server update prohibited';
case ServerRecoverProhibited = 'server recover prohibited';
case ServerHold = 'server hold';
case TransferPeriod = 'transfer period';
case Administrative = 'administrative';
case Reserved = 'reserved';
}

View File

@@ -2,7 +2,6 @@
namespace App\Entity;
use App\Config\DomainStatus;
use App\Repository\DomainRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@@ -31,7 +30,7 @@ class Domain
#[ORM\OneToMany(targetEntity: DomainEntity::class, mappedBy: 'domain', cascade: ['persist'], orphanRemoval: true)]
private Collection $domainEntities;
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainStatus::class)]
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $status = [];
/**
@@ -142,9 +141,6 @@ class Domain
return $this;
}
/**
* @return DomainStatus[]
*/
public function getStatus(): array
{
return $this->status;

View File

@@ -3,7 +3,6 @@
namespace App\Entity;
use App\Config\DomainRole;
use App\Config\DomainStatus;
use App\Repository\NameserverEntityRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
@@ -25,7 +24,7 @@ class NameserverEntity
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainRole::class)]
private array $roles = [];
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainStatus::class)]
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $status = [];
public function getNameserver(): ?Nameserver
@@ -67,9 +66,6 @@ class NameserverEntity
return $this;
}
/**
* @return DomainStatus[]
*/
public function getStatus(): array
{
return $this->status;

View File

@@ -4,7 +4,6 @@
namespace App\Service;
use App\Config\DomainRole;
use App\Config\DomainStatus;
use App\Config\EventAction;
use App\Entity\Domain;
use App\Entity\DomainEntity;
@@ -27,19 +26,19 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Throwable;
class RDAPService
readonly class RDAPService
{
public function __construct(private readonly HttpClientInterface $client,
private readonly EntityRepository $entityRepository,
private readonly DomainRepository $domainRepository,
private readonly DomainEventRepository $domainEventRepository,
private readonly NameserverRepository $nameserverRepository,
private readonly NameserverEntityRepository $nameserverEntityRepository,
private readonly EntityEventRepository $entityEventRepository,
private readonly DomainEntityRepository $domainEntityRepository,
private readonly EntityManagerInterface $em,
private readonly ParameterBagInterface $params
public function __construct(private HttpClientInterface $client,
private EntityRepository $entityRepository,
private DomainRepository $domainRepository,
private DomainEventRepository $domainEventRepository,
private NameserverRepository $nameserverRepository,
private NameserverEntityRepository $nameserverEntityRepository,
private EntityEventRepository $entityEventRepository,
private DomainEntityRepository $domainEntityRepository,
private EntityManagerInterface $em,
private ParameterBagInterface $params
)
{
@@ -53,7 +52,7 @@ class RDAPService
$idnDomain = idn_to_ascii($fqdn);
try {
$rdapServer = $this->getRDAPServer(RDAPService::getTld($idnDomain));
} catch (Exception $e) {
} catch (Exception) {
throw new Exception("Unable to determine which RDAP server to contact");
}
@@ -61,7 +60,7 @@ class RDAPService
$res = $this->client->request(
'GET', $rdapServer . 'domain/' . $idnDomain
)->toArray();
} catch (Throwable $e) {
} catch (Throwable) {
throw new Exception("Unable to contact RDAP server");
}
@@ -71,7 +70,7 @@ class RDAPService
$domain
->setLdhName($res['ldhName'])
->setHandle($res['handle'])
->setStatus(array_map(fn($str): DomainStatus => DomainStatus::from($str), $res['status']));
->setStatus($res['status']);
foreach ($res['events'] as $rdapEvent) {
@@ -79,7 +78,7 @@ class RDAPService
if ($eventAction === EventAction::LastUpdateOfRDAPDatabase) continue;
$event = $this->domainEventRepository->findOneBy([
"action" => EventAction::from($rdapEvent["eventAction"]),
"action" => $eventAction,
"date" => new DateTimeImmutable($rdapEvent["eventDate"]),
"domain" => $domain
]);
@@ -146,7 +145,7 @@ class RDAPService
$nameserver->addNameserverEntity($nameserverEntity
->setNameserver($nameserver)
->setEntity($entity)
->setStatus(array_map(fn($str): DomainStatus => DomainStatus::from($str), $rdapNameserver['status']))
->setStatus($rdapNameserver['status'])
->setRoles(array_map(fn($str): DomainRole => DomainRole::from($str), $rdapEntity['roles'])));
}
@@ -174,6 +173,9 @@ class RDAPService
throw new Exception("This TLD ($tld) is not supported");
}
/**
* @throws Exception
*/
private static function getTld($domain): string
{
$lastDotPosition = strrpos($domain, '.');