feat: start of EPP implementation

This commit is contained in:
Maël Gangloff 2025-02-21 16:20:19 +01:00
parent 1db47dfa34
commit 8a46bb76bc
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
6 changed files with 541 additions and 500 deletions

913
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
namespace App\Config; namespace App\Config;
use App\Service\Connector\AutodnsProvider; use App\Service\Connector\AutodnsProvider;
use App\Service\Connector\EppClientProvider;
use App\Service\Connector\GandiProvider; use App\Service\Connector\GandiProvider;
use App\Service\Connector\NamecheapProvider; use App\Service\Connector\NamecheapProvider;
use App\Service\Connector\NameComProvider; use App\Service\Connector\NameComProvider;
@ -15,6 +16,7 @@ enum ConnectorProvider: string
case AUTODNS = 'autodns'; case AUTODNS = 'autodns';
case NAMECHEAP = 'namecheap'; case NAMECHEAP = 'namecheap';
case NAMECOM = 'namecom'; case NAMECOM = 'namecom';
case EPP = 'epp';
public function getConnectorProvider(): string public function getConnectorProvider(): string
{ {
@ -24,6 +26,7 @@ enum ConnectorProvider: string
ConnectorProvider::AUTODNS => AutodnsProvider::class, ConnectorProvider::AUTODNS => AutodnsProvider::class,
ConnectorProvider::NAMECHEAP => NamecheapProvider::class, ConnectorProvider::NAMECHEAP => NamecheapProvider::class,
ConnectorProvider::NAMECOM => NameComProvider::class, ConnectorProvider::NAMECOM => NameComProvider::class,
ConnectorProvider::EPP => EppClientProvider::class,
}; };
} }
} }

View File

@ -2,30 +2,34 @@
namespace App\Controller; namespace App\Controller;
use App\Config\ConnectorProvider;
use App\Entity\Connector; use App\Entity\Connector;
use App\Entity\User; use App\Entity\User;
use App\Service\Connector\AbstractProvider; use App\Service\Connector\AbstractProvider;
use DateTimeImmutable;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class ConnectorController extends AbstractController class ConnectorController extends AbstractController
{ {
public function __construct( public function __construct(
private readonly SerializerInterface $serializer, private readonly SerializerInterface $serializer,
private readonly EntityManagerInterface $em, private readonly EntityManagerInterface $em,
private readonly LoggerInterface $logger, private readonly LoggerInterface $logger,
#[Autowire(service: 'service_container')] #[Autowire(service: 'service_container')]
private readonly ContainerInterface $locator, private readonly ContainerInterface $locator,
) { )
{
} }
#[Route( #[Route(
@ -46,7 +50,7 @@ class ConnectorController extends AbstractController
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
#[Route( #[Route(
path: '/api/connectors', path: '/api/connectors',
@ -57,8 +61,9 @@ class ConnectorController extends AbstractController
], ],
methods: ['POST'] methods: ['POST']
)] )]
public function createConnector(Request $request, HttpClientInterface $client): Connector public function createConnector(Request $request): Connector
{ {
/** @var Connector $connector */
$connector = $this->serializer->deserialize($request->getContent(), Connector::class, 'json', ['groups' => 'connector:create']); $connector = $this->serializer->deserialize($request->getContent(), Connector::class, 'json', ['groups' => 'connector:create']);
/** @var User $user */ /** @var User $user */
$user = $this->getUser(); $user = $this->getUser();
@ -75,6 +80,26 @@ class ConnectorController extends AbstractController
throw new BadRequestHttpException('Provider not found'); throw new BadRequestHttpException('Provider not found');
} }
if ($provider === ConnectorProvider::EPP) {
$directory = sprintf('var/epp-certificates/%s/', $connector->getId());
$filesystem = new Filesystem();
$filesystem->mkdir($directory);
$authData = $connector->getAuthData();
if (!isset($authData['certificate_pem'], $authData['certificate_key'])) {
throw new BadRequestHttpException('EPP certificates are required');
}
$pemPath = $directory . 'certificate.pem';
$keyPath = $directory . 'certificate.key';
$filesystem->dumpFile($pemPath, $authData['certificate_pem']);
$filesystem->dumpFile($keyPath, $authData['certificate_key']);
$connector->setAuthData([...$authData, 'files' => ['pem' => $pemPath, 'key' => $keyPath]]);
}
/** @var AbstractProvider $providerClient */ /** @var AbstractProvider $providerClient */
$providerClient = $this->locator->get($provider->getConnectorProvider()); $providerClient = $this->locator->get($provider->getConnectorProvider());
$authData = $providerClient->verifyAuthData($connector->getAuthData()); $authData = $providerClient->verifyAuthData($connector->getAuthData());
@ -90,7 +115,7 @@ class ConnectorController extends AbstractController
'username' => $user->getUserIdentifier(), 'username' => $user->getUserIdentifier(),
]); ]);
$connector->setCreatedAt(new \DateTimeImmutable('now')); $connector->setCreatedAt(new DateTimeImmutable('now'));
$this->em->persist($connector); $this->em->persist($connector);
$this->em->flush(); $this->em->flush();

View File

@ -29,7 +29,8 @@ use Symfony\Component\Uid\Uuid;
), ),
new Post( new Post(
routeName: 'connector_create', routeName: 'connector_create',
normalizationContext: ['groups' => ['connector:create', 'connector:list']], denormalizationContext: ['groups' => 'connector:create'], normalizationContext: ['groups' => ['connector:create', 'connector:list']],
denormalizationContext: ['groups' => 'connector:create'],
name: 'create' name: 'create'
), ),
new Delete( new Delete(

View File

@ -0,0 +1,71 @@
<?php
namespace App\Service\Connector;
use App\Entity\Domain;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;
class EppClientProvider extends AbstractProvider implements EppClientProviderInterface
{
public function __construct(
CacheItemPoolInterface $cacheItemPool,
)
{
parent::__construct($cacheItemPool);
}
protected function verifySpecificAuthData(array $authData): array
{
// TODO: Create DTO for each authData schema
return $authData;
}
protected function assertAuthentication(): void
{
//TODO: implementation
}
public function orderDomain(Domain $domain, bool $dryRun): void
{
//TODO: implementation
}
/**
* @throws InvalidArgumentException
*/
protected function getCachedTldList(): CacheItemInterface
{
return $this->cacheItemPool->getItem('app.provider.epp.supported-tld');
}
protected function getSupportedTldList(): array
{
return [];
}
public function isSupported(Domain ...$domainList): bool
{
if (0 === count($domainList)) {
return true;
}
$tld = $domainList[0]->getTld();
foreach ($domainList as $domain) {
if ($domain->getTld() !== $tld) {
return false;
}
}
return true;
}
public function checkDomains(Domain ...$domains): array
{
//TODO : implementation
return [];
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Service\Connector;
use App\Entity\Domain;
interface EppClientProviderInterface
{
public function checkDomains(Domain ...$domains): array;
}