mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 09:45:29 +00:00
feat: start of EPP implementation
This commit is contained in:
parent
1db47dfa34
commit
8a46bb76bc
913
composer.lock
generated
913
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@
|
||||
namespace App\Config;
|
||||
|
||||
use App\Service\Connector\AutodnsProvider;
|
||||
use App\Service\Connector\EppClientProvider;
|
||||
use App\Service\Connector\GandiProvider;
|
||||
use App\Service\Connector\NamecheapProvider;
|
||||
use App\Service\Connector\NameComProvider;
|
||||
@ -15,6 +16,7 @@ enum ConnectorProvider: string
|
||||
case AUTODNS = 'autodns';
|
||||
case NAMECHEAP = 'namecheap';
|
||||
case NAMECOM = 'namecom';
|
||||
case EPP = 'epp';
|
||||
|
||||
public function getConnectorProvider(): string
|
||||
{
|
||||
@ -24,6 +26,7 @@ enum ConnectorProvider: string
|
||||
ConnectorProvider::AUTODNS => AutodnsProvider::class,
|
||||
ConnectorProvider::NAMECHEAP => NamecheapProvider::class,
|
||||
ConnectorProvider::NAMECOM => NameComProvider::class,
|
||||
ConnectorProvider::EPP => EppClientProvider::class,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,20 +2,23 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Config\ConnectorProvider;
|
||||
use App\Entity\Connector;
|
||||
use App\Entity\User;
|
||||
use App\Service\Connector\AbstractProvider;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class ConnectorController extends AbstractController
|
||||
{
|
||||
@ -25,7 +28,8 @@ class ConnectorController extends AbstractController
|
||||
private readonly LoggerInterface $logger,
|
||||
#[Autowire(service: 'service_container')]
|
||||
private readonly ContainerInterface $locator,
|
||||
) {
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route(
|
||||
@ -46,7 +50,7 @@ class ConnectorController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
#[Route(
|
||||
path: '/api/connectors',
|
||||
@ -57,8 +61,9 @@ class ConnectorController extends AbstractController
|
||||
],
|
||||
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']);
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
@ -75,6 +80,26 @@ class ConnectorController extends AbstractController
|
||||
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 */
|
||||
$providerClient = $this->locator->get($provider->getConnectorProvider());
|
||||
$authData = $providerClient->verifyAuthData($connector->getAuthData());
|
||||
@ -90,7 +115,7 @@ class ConnectorController extends AbstractController
|
||||
'username' => $user->getUserIdentifier(),
|
||||
]);
|
||||
|
||||
$connector->setCreatedAt(new \DateTimeImmutable('now'));
|
||||
$connector->setCreatedAt(new DateTimeImmutable('now'));
|
||||
$this->em->persist($connector);
|
||||
$this->em->flush();
|
||||
|
||||
|
||||
@ -29,7 +29,8 @@ use Symfony\Component\Uid\Uuid;
|
||||
),
|
||||
new Post(
|
||||
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'
|
||||
),
|
||||
new Delete(
|
||||
|
||||
71
src/Service/Connector/EppClientProvider.php
Normal file
71
src/Service/Connector/EppClientProvider.php
Normal 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 [];
|
||||
}
|
||||
}
|
||||
10
src/Service/Connector/EppClientProviderInterface.php
Normal file
10
src/Service/Connector/EppClientProviderInterface.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Connector;
|
||||
|
||||
use App\Entity\Domain;
|
||||
|
||||
interface EppClientProviderInterface
|
||||
{
|
||||
public function checkDomains(Domain ...$domains): array;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user