mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 17:55:42 +00:00
feat: add RDAP response dto
This commit is contained in:
parent
d769c48955
commit
b777683c50
52
src/Entity/RdapResponse/Domain.php
Normal file
52
src/Entity/RdapResponse/Domain.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
use App\Config\EventAction;
|
||||
use App\Entity\DomainEntity;
|
||||
use App\Entity\DomainEvent;
|
||||
|
||||
class Domain
|
||||
{
|
||||
public string $objectClassName = 'domain';
|
||||
public ?string $handle;
|
||||
public string $ldhName;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public ?array $status;
|
||||
/**
|
||||
* @var Event[]
|
||||
*/
|
||||
public ?array $events;
|
||||
|
||||
/**
|
||||
* @var Entity[]
|
||||
*/
|
||||
public ?array $entities;
|
||||
/**
|
||||
* @var Nameserver[]
|
||||
*/
|
||||
public ?array $nameservers;
|
||||
|
||||
public ?SecureDNS $secureDNS;
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(\App\Entity\Domain $d)
|
||||
{
|
||||
$this->handle = $d->getHandle();
|
||||
$this->ldhName = $d->getLdhName();
|
||||
$this->status = $d->getStatus();
|
||||
$events = $d->getEvents()->toArray();
|
||||
usort($events, fn (DomainEvent $d1, DomainEvent $d2) => $d1->getDate()->getTimestamp() - $d2->getDate()->getTimestamp());
|
||||
$this->events = [
|
||||
...array_map(fn (DomainEvent $de) => Event::fromEvent($de), $events),
|
||||
new Event($d->getUpdatedAt()->format(\DateTimeInterface::ATOM), EventAction::LastUpdateOfRDAPDatabase->value),
|
||||
];
|
||||
$this->entities = array_map(fn (DomainEntity $de) => Entity::fromDomainEntity($de), $d->getDomainEntities()->toArray());
|
||||
$this->nameservers = array_map(fn (\App\Entity\Nameserver $ns) => Nameserver::fromNameserver($ns), $d->getNameservers()->toArray());
|
||||
$this->secureDNS = SecureDNS::fromDomain($d);
|
||||
}
|
||||
}
|
||||
13
src/Entity/RdapResponse/DomainRdapResponse.php
Normal file
13
src/Entity/RdapResponse/DomainRdapResponse.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
class DomainRdapResponse extends Domain
|
||||
{
|
||||
use RdapResponseTrait;
|
||||
|
||||
public function __construct(\App\Entity\Domain $d)
|
||||
{
|
||||
parent::__construct($d);
|
||||
}
|
||||
}
|
||||
24
src/Entity/RdapResponse/DsData.php
Normal file
24
src/Entity/RdapResponse/DsData.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
use App\Entity\DnsKey;
|
||||
|
||||
class DsData
|
||||
{
|
||||
public int $keyTag;
|
||||
public int $algorithm;
|
||||
public string $digest;
|
||||
public int $digestType;
|
||||
|
||||
public static function fromDnsKey(DnsKey $dnsKey): self
|
||||
{
|
||||
$d = new DsData();
|
||||
$d->algorithm = $dnsKey->getAlgorithm()->value;
|
||||
$d->keyTag = (int) $dnsKey->getKeyTag();
|
||||
$d->digest = $dnsKey->getDigest();
|
||||
$d->digestType = $dnsKey->getDigestType()->value;
|
||||
|
||||
return $d;
|
||||
}
|
||||
}
|
||||
54
src/Entity/RdapResponse/Entity.php
Normal file
54
src/Entity/RdapResponse/Entity.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
use App\Config\DomainRole;
|
||||
use App\Entity\DomainEntity;
|
||||
use App\Entity\EntityEvent;
|
||||
|
||||
class Entity
|
||||
{
|
||||
public string $objectClassName = 'entity';
|
||||
public ?string $handle;
|
||||
|
||||
/**
|
||||
* @var PublicId[]
|
||||
*/
|
||||
public ?array $publicIds;
|
||||
/**
|
||||
* @var Event[]
|
||||
*/
|
||||
public ?array $events;
|
||||
/**
|
||||
* @var Link[]
|
||||
*/
|
||||
public array $vcardArray;
|
||||
|
||||
/**
|
||||
* @var DomainRole[]
|
||||
*/
|
||||
public array $roles;
|
||||
|
||||
public ?array $remarks;
|
||||
|
||||
public function __construct(\App\Entity\Entity $e)
|
||||
{
|
||||
if (!str_starts_with($e->getHandle(), 'DW-FAKEHANDLE')) {
|
||||
$this->handle = $e->getHandle();
|
||||
}
|
||||
if ($e->getIcannAccreditation()) {
|
||||
$this->publicIds = [new PublicId('IANA Registrar ID', (string) $e->getIcannAccreditation()->getId())];
|
||||
}
|
||||
$this->vcardArray = $e->getJCard();
|
||||
$this->remarks = $e->getRemarks();
|
||||
}
|
||||
|
||||
public static function fromDomainEntity(DomainEntity $de): self
|
||||
{
|
||||
$e = new Entity($de->getEntity());
|
||||
$e->events = array_map(fn (EntityEvent $ee) => Event::fromEvent($ee), $de->getEntity()->getEvents()->toArray());
|
||||
$e->roles = $de->getRoles();
|
||||
|
||||
return $e;
|
||||
}
|
||||
}
|
||||
13
src/Entity/RdapResponse/EntityRdapResponse.php
Normal file
13
src/Entity/RdapResponse/EntityRdapResponse.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
class EntityRdapResponse extends Entity
|
||||
{
|
||||
use RdapResponseTrait;
|
||||
|
||||
public function __construct(\App\Entity\Entity $e)
|
||||
{
|
||||
parent::__construct($e);
|
||||
}
|
||||
}
|
||||
17
src/Entity/RdapResponse/Event.php
Normal file
17
src/Entity/RdapResponse/Event.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
class Event
|
||||
{
|
||||
public function __construct(
|
||||
public string $eventDate,
|
||||
public string $eventAction,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function fromEvent(\App\Entity\Event $event): self
|
||||
{
|
||||
return new Event($event->getDate()->format(\DateTimeInterface::ATOM), $event->getAction());
|
||||
}
|
||||
}
|
||||
10
src/Entity/RdapResponse/Link.php
Normal file
10
src/Entity/RdapResponse/Link.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
class Link
|
||||
{
|
||||
public string $href;
|
||||
public string $value;
|
||||
public string $rel;
|
||||
}
|
||||
18
src/Entity/RdapResponse/Nameserver.php
Normal file
18
src/Entity/RdapResponse/Nameserver.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
class Nameserver
|
||||
{
|
||||
public string $objectClassName = 'nameserver';
|
||||
|
||||
public function __construct(
|
||||
public string $ldhName,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function fromNameserver(\App\Entity\Nameserver $ns): self
|
||||
{
|
||||
return new Nameserver($ns->getLdhName());
|
||||
}
|
||||
}
|
||||
13
src/Entity/RdapResponse/NameserverRdapResponse.php
Normal file
13
src/Entity/RdapResponse/NameserverRdapResponse.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
class NameserverRdapResponse extends Nameserver
|
||||
{
|
||||
use RdapResponseTrait;
|
||||
|
||||
public function __construct(\App\Entity\Nameserver $ns)
|
||||
{
|
||||
parent::__construct($ns->getLdhName());
|
||||
}
|
||||
}
|
||||
19
src/Entity/RdapResponse/Notice.php
Normal file
19
src/Entity/RdapResponse/Notice.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
class Notice
|
||||
{
|
||||
public function __construct(
|
||||
public string $title,
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public array $description,
|
||||
/**
|
||||
* @var Link[]
|
||||
*/
|
||||
public array $links,
|
||||
) {
|
||||
}
|
||||
}
|
||||
12
src/Entity/RdapResponse/PublicId.php
Normal file
12
src/Entity/RdapResponse/PublicId.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
class PublicId
|
||||
{
|
||||
public function __construct(
|
||||
public string $type,
|
||||
public string $identifier)
|
||||
{
|
||||
}
|
||||
}
|
||||
21
src/Entity/RdapResponse/RdapResponseTrait.php
Normal file
21
src/Entity/RdapResponse/RdapResponseTrait.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
trait RdapResponseTrait
|
||||
{
|
||||
public array $rdapConformance = [
|
||||
'rdap_level_0',
|
||||
'icann_rdap_technical_implementation_guide_1',
|
||||
'icann_rdap_response_profile_1',
|
||||
];
|
||||
/**
|
||||
* @var Link[]
|
||||
*/
|
||||
public array $links;
|
||||
|
||||
/**
|
||||
* @var Notice[]
|
||||
*/
|
||||
public array $notices;
|
||||
}
|
||||
28
src/Entity/RdapResponse/SecureDNS.php
Normal file
28
src/Entity/RdapResponse/SecureDNS.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\RdapResponse;
|
||||
|
||||
use App\Entity\DnsKey;
|
||||
|
||||
class SecureDNS
|
||||
{
|
||||
public bool $delegationSigned;
|
||||
/**
|
||||
* @var DsData[]
|
||||
*/
|
||||
public ?array $dsData = null;
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function fromDomain(\App\Entity\Domain $d): self
|
||||
{
|
||||
$s = new SecureDNS();
|
||||
$s->delegationSigned = $d->isDelegationSigned();
|
||||
if ($s->delegationSigned) {
|
||||
$s->dsData = array_map(fn (DnsKey $dnsKey) => DsData::fromDnsKey($dnsKey), $d->getDnsKey()->toArray());
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
}
|
||||
31
src/State/DomainRdapResponseProvider.php
Normal file
31
src/State/DomainRdapResponseProvider.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Entity\Domain;
|
||||
use App\Entity\RdapResponse\DomainRdapResponse;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Service\RDAPService;
|
||||
|
||||
readonly class DomainRdapResponseProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private DomainRepository $domainRepository,
|
||||
private AutoRegisterDomainProvider $autoRegisterDomainProvider,
|
||||
) {
|
||||
}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
$this->autoRegisterDomainProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
$idnDomain = RDAPService::convertToIdn($uriVariables['ldhName']);
|
||||
|
||||
/** @var Domain $domain */
|
||||
$domain = $this->domainRepository->findOneBy(['ldhName' => $idnDomain]);
|
||||
|
||||
return new DomainRdapResponse($domain);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user