chore: merge master

This commit is contained in:
Maël Gangloff
2024-10-02 12:59:37 +02:00
22 changed files with 1302 additions and 985 deletions

View File

@@ -2,15 +2,17 @@
namespace App\Config;
use App\Config\Provider\AutodnsProvider;
use App\Config\Provider\GandiProvider;
use App\Config\Provider\OvhProvider;
use App\Service\Connector\AutodnsProvider;
use App\Service\Connector\GandiProvider;
use App\Service\Connector\NamecheapProvider;
use App\Service\Connector\OvhProvider;
enum ConnectorProvider: string
{
case OVH = 'ovh';
case GANDI = 'gandi';
case AUTODNS = 'autodns';
case NAMECHEAP = 'namecheap';
public function getConnectorProvider(): string
{
@@ -18,6 +20,7 @@ enum ConnectorProvider: string
ConnectorProvider::OVH => OvhProvider::class,
ConnectorProvider::GANDI => GandiProvider::class,
ConnectorProvider::AUTODNS => AutodnsProvider::class,
ConnectorProvider::NAMECHEAP => NamecheapProvider::class,
};
}
}

View File

@@ -2,13 +2,15 @@
namespace App\Controller;
use App\Config\Provider\AbstractProvider;
use App\Entity\Connector;
use App\Entity\User;
use App\Service\Connector\AbstractProvider;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
@@ -20,7 +22,9 @@ class ConnectorController extends AbstractController
public function __construct(
private readonly SerializerInterface $serializer,
private readonly EntityManagerInterface $em,
private readonly LoggerInterface $logger
private readonly LoggerInterface $logger,
#[Autowire(service: 'service_container')]
private ContainerInterface $locator
) {
}
@@ -71,11 +75,11 @@ class ConnectorController extends AbstractController
throw new BadRequestHttpException('Provider not found');
}
/** @var AbstractProvider $connectorProviderClass */
$connectorProviderClass = $provider->getConnectorProvider();
$authData = $connectorProviderClass::verifyAuthData($connector->getAuthData(), $client);
/** @var AbstractProvider $providerClient */
$providerClient = $this->locator->get($provider->getConnectorProvider());
$authData = $providerClient->verifyAuthData($connector->getAuthData());
$connector->setAuthData($authData);
$providerClient->authenticate($authData);
$this->logger->info('User {username} authentication data with the {provider} provider has been validated.', [
'username' => $user->getUserIdentifier(),

View File

@@ -2,7 +2,6 @@
namespace App\Controller;
use App\Config\Provider\AbstractProvider;
use App\Entity\Connector;
use App\Entity\Domain;
use App\Entity\DomainEntity;
@@ -12,6 +11,7 @@ use App\Entity\WatchList;
use App\Notifier\TestChatNotification;
use App\Repository\WatchListRepository;
use App\Service\ChatNotificationService;
use App\Service\Connector\AbstractProvider;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Exception\ORMException;
@@ -27,21 +27,20 @@ use Eluceo\iCal\Domain\ValueObject\Timestamp;
use Eluceo\iCal\Presentation\Component\Property;
use Eluceo\iCal\Presentation\Component\Property\Value\TextValue;
use Eluceo\iCal\Presentation\Factory\CalendarFactory;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Sabre\VObject\EofException;
use Sabre\VObject\InvalidDataException;
use Sabre\VObject\ParseException;
use Sabre\VObject\Reader;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class WatchListController extends AbstractController
{
@@ -50,10 +49,9 @@ class WatchListController extends AbstractController
private readonly EntityManagerInterface $em,
private readonly WatchListRepository $watchListRepository,
private readonly LoggerInterface $logger,
private readonly HttpClientInterface $httpClient,
private readonly CacheItemPoolInterface $cacheItemPool,
private readonly KernelInterface $kernel,
private readonly ChatNotificationService $chatNotificationService
private readonly ChatNotificationService $chatNotificationService,
#[Autowire(service: 'service_container')]
private ContainerInterface $locator
) {
}
@@ -182,9 +180,9 @@ class WatchListController extends AbstractController
$connectorProviderClass = $connector->getProvider()->getConnectorProvider();
/** @var AbstractProvider $connectorProvider */
$connectorProvider = new $connectorProviderClass($connector->getAuthData(), $this->httpClient, $this->cacheItemPool, $this->kernel);
$connectorProvider = $this->locator->get($connectorProviderClass);
$connectorProvider::verifyAuthData($connector->getAuthData(), $this->httpClient); // We want to check if the tokens are OK
$connectorProvider->authenticate($connector->getAuthData());
$supported = $connectorProvider->isSupported(...$watchList->getDomains()->toArray());
if (!$supported) {

View File

@@ -2,7 +2,6 @@
namespace App\MessageHandler;
use App\Config\Provider\AbstractProvider;
use App\Entity\Domain;
use App\Entity\WatchList;
use App\Message\OrderDomain;
@@ -11,16 +10,17 @@ use App\Notifier\DomainOrderNotification;
use App\Repository\DomainRepository;
use App\Repository\WatchListRepository;
use App\Service\ChatNotificationService;
use App\Service\Connector\AbstractProvider;
use App\Service\StatService;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Mime\Address;
use Symfony\Component\Notifier\Recipient\Recipient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
#[AsMessageHandler]
final readonly class OrderDomainHandler
@@ -33,12 +33,12 @@ final readonly class OrderDomainHandler
private WatchListRepository $watchListRepository,
private DomainRepository $domainRepository,
private KernelInterface $kernel,
private HttpClientInterface $client,
private CacheItemPoolInterface $cacheItemPool,
private MailerInterface $mailer,
private LoggerInterface $logger,
private StatService $statService,
private ChatNotificationService $chatNotificationService
private ChatNotificationService $chatNotificationService,
#[Autowire(service: 'service_container')]
private ContainerInterface $locator
) {
$this->sender = new Address($mailerSenderEmail, $mailerSenderName);
}
@@ -72,7 +72,8 @@ final readonly class OrderDomainHandler
$connectorProviderClass = $provider->getConnectorProvider();
/** @var AbstractProvider $connectorProvider */
$connectorProvider = new $connectorProviderClass($connector->getAuthData(), $this->client, $this->cacheItemPool, $this->kernel);
$connectorProvider = $this->locator->get($connectorProviderClass);
$connectorProvider->authenticate($connector->getAuthData());
$connectorProvider->orderDomain($domain, $this->kernel->isDebug());
$this->statService->incrementStat('stats.domain.purchased');

View File

@@ -1,24 +1,38 @@
<?php
namespace App\Config\Provider;
namespace App\Service\Connector;
use App\Entity\Domain;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* The typical flow of a provider will go as follows:
*
* MyProvider $provider; // gotten from DI
* $provider->authenticate($authData);
* $provider->orderDomain($domain, $dryRun);
*/
abstract class AbstractProvider
{
protected array $authData;
public function __construct(
protected array $authData,
protected HttpClientInterface $client,
protected CacheItemPoolInterface $cacheItemPool,
protected KernelInterface $kernel
protected CacheItemPoolInterface $cacheItemPool
) {
}
abstract public static function verifyAuthData(array $authData, HttpClientInterface $client): array;
/**
* @param array $authData raw authentication data as supplied by the user
*
* @return array a cleaned up version of the authentication data
*/
abstract public function verifyAuthData(array $authData): array;
/**
* @throws \Exception when the registrar denies the authentication
*/
abstract public function assertAuthentication(): void; // TODO use dedicated exception type
abstract public function orderDomain(Domain $domain, bool $dryRun): void;
@@ -55,6 +69,15 @@ abstract class AbstractProvider
return true;
}
/**
* @throws \Exception
*/
public function authenticate(array $authData): void
{
$this->authData = $this->verifyAuthData($authData);
$this->assertAuthentication();
}
abstract protected function getCachedTldList(): CacheItemInterface;
abstract protected function getSupportedTldList(): array;

View File

@@ -1,9 +1,11 @@
<?php
namespace App\Config\Provider;
namespace App\Service\Connector;
use App\Entity\Domain;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\HttpClient\HttpOptions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@@ -17,6 +19,11 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
class AutodnsProvider extends AbstractProvider
{
public function __construct(CacheItemPoolInterface $cacheItemPool, private readonly HttpClientInterface $client)
{
parent::__construct($cacheItemPool);
}
private const BASE_URL = 'https://api.autodns.com';
/**
@@ -37,9 +44,7 @@ class AutodnsProvider extends AbstractProvider
throw new \InvalidArgumentException('Domain name cannot be null');
}
$authData = self::verifyAuthData($this->authData, $this->client);
if($dryRun) {
if ($dryRun) {
return;
}
@@ -47,49 +52,55 @@ class AutodnsProvider extends AbstractProvider
'POST',
'/v1/domain',
(new HttpOptions())
->setAuthBasic($authData['username'], $authData['password'])
->setAuthBasic($this->authData['username'], $this->authData['password'])
->setHeader('Accept', 'application/json')
->setHeader('X-Domainrobot-Context', $authData['context'])
->setHeader('X-Domainrobot-Context', $this->authData['context'])
->setBaseUri(self::BASE_URL)
->setJson([
'name' => $ldhName,
'ownerc' => [
'id' => $authData['contactid'],
'id' => $this->authData['contactid'],
],
'adminc' => [
'id' => $authData['contactid'],
'id' => $this->authData['contactid'],
],
'techc' => [
'id' => $authData['contactid'],
'id' => $this->authData['contactid'],
],
'confirmOrder' => $authData['ownerConfirm'],
'confirmOrder' => $this->authData['ownerConfirm'],
'nameServers' => [
[
'name' => 'a.ns14.net'
'name' => 'a.ns14.net',
],
[
'name' => 'b.ns14.net'
'name' => 'b.ns14.net',
],
[
'name' => 'c.ns14.net'
'name' => 'c.ns14.net',
],
[
'name' => 'd.ns14.net'
'name' => 'd.ns14.net',
],
]
],
])
->toArray()
)->toArray();
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function registerZone(Domain $domain, bool $dryRun = false): void
{
$authData = $this->authData;
$ldhName = $domain->getLdhName();
if($dryRun) {
if ($dryRun) {
return;
}
@@ -100,7 +111,6 @@ class AutodnsProvider extends AbstractProvider
->setAuthBasic($authData['username'], $authData['password'])
->setHeader('Accept', 'application/json')
->setHeader('X-Domainrobot-Context', $authData['context'])
->setBaseUri(self::BASE_URL)
->setJson([
'filters' => [
@@ -108,7 +118,7 @@ class AutodnsProvider extends AbstractProvider
'key' => 'name',
'value' => $ldhName,
'operator' => 'EQUAL',
]
],
],
])
->toArray()
@@ -126,48 +136,42 @@ class AutodnsProvider extends AbstractProvider
->setAuthBasic($authData['username'], $authData['password'])
->setHeader('Accept', 'application/json')
->setHeader('X-Domainrobot-Context', $authData['context'])
->setBaseUri(self::BASE_URL)
->setJson([
'origin' => $ldhName,
'main' => [
'address' => $authData['dns_ip']
'address' => $authData['dns_ip'],
],
'soa' => [
'refresh' => 3600,
'retry' => 7200,
'expire' => 604800,
'ttl' => 600
'ttl' => 600,
],
'action' => 'COMPLETE',
'wwwInclude' => true,
'nameServers' => [
[
'name' => 'a.ns14.net'
'name' => 'a.ns14.net',
],
[
'name' => 'b.ns14.net'
'name' => 'b.ns14.net',
],
[
'name' => 'c.ns14.net'
'name' => 'c.ns14.net',
],
[
'name' => 'd.ns14.net'
'name' => 'd.ns14.net',
],
]
],
])
->toArray()
)->toArray();
}
}
/**
* @throws TransportExceptionInterface
*/
public static function verifyAuthData(array $authData, HttpClientInterface $client): array
{
public function verifyAuthData(array $authData): array
{
$username = $authData['username'];
$password = $authData['password'];
@@ -187,33 +191,22 @@ class AutodnsProvider extends AbstractProvider
if (
true !== $acceptConditions
|| empty($authData['ownerConfirm'])
|| true !== $authData['ownerConfirm']
|| true !== $ownerLegalAge
|| true !== $waiveRetractationPeriod
) {
throw new HttpException(451, 'The user has not given explicit consent');
}
try {
$response = $client->request(
'GET',
'/v1/hello',
(new HttpOptions())
->setAuthBasic($authData['username'], $authData['password'])
->setHeader('Accept', 'application/json')
->setHeader('X-Domainrobot-Context', $authData['context'])
->setBaseUri(self::BASE_URL)
->toArray()
);
} catch (\Exception $exp) {
throw new BadRequestHttpException('Invalid Login');
}
if (Response::HTTP_OK !== $response->getStatusCode()) {
throw new BadRequestHttpException('The status of these credentials is not valid');
}
return $authData;
return [
'username' => $authData['username'],
'password' => $authData['password'],
'acceptConditions' => $authData['acceptConditions'],
'ownerLegalAge' => $authData['ownerLegalAge'],
'ownerConfirm' => $authData['ownerConfirm'],
'waiveRetractationPeriod' => $authData['waiveRetractationPeriod'],
'context' => $authData['context'],
];
}
public function isSupported(Domain ...$domainList): bool
@@ -221,14 +214,41 @@ class AutodnsProvider extends AbstractProvider
return true;
}
protected function getSupportedTldList(): array {
protected function getSupportedTldList(): array
{
return [];
}
/**
* @throws \Psr\Cache\InvalidArgumentException
* @throws InvalidArgumentException
*/
protected function getCachedTldList(): CacheItemInterface
{
return $this->cacheItemPool->getItem('app.provider.autodns.supported-tld');
}
/**
* @throws TransportExceptionInterface
*/
public function assertAuthentication(): void
{
try {
$response = $this->client->request(
'GET',
'/v1/hello',
(new HttpOptions())
->setAuthBasic($this->authData['username'], $this->authData['password'])
->setHeader('Accept', 'application/json')
->setHeader('X-Domainrobot-Context', $this->authData['context'])
->setBaseUri(self::BASE_URL)
->toArray()
);
} catch (\Exception) {
throw new BadRequestHttpException('Invalid Login');
}
if (Response::HTTP_OK !== $response->getStatusCode()) {
throw new BadRequestHttpException('The status of these credentials is not valid');
}
}
}

View File

@@ -1,9 +1,10 @@
<?php
namespace App\Config\Provider;
namespace App\Service\Connector;
use App\Entity\Domain;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\HttpClient\HttpOptions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@@ -19,6 +20,11 @@ class GandiProvider extends AbstractProvider
{
private const BASE_URL = 'https://api.gandi.net';
public function __construct(CacheItemPoolInterface $cacheItemPool, private readonly HttpClientInterface $client)
{
parent::__construct($cacheItemPool);
}
/**
* Order a domain name with the Gandi API.
*
@@ -37,17 +43,15 @@ class GandiProvider extends AbstractProvider
throw new \InvalidArgumentException('Domain name cannot be null');
}
$authData = self::verifyAuthData($this->authData, $this->client);
$user = $this->client->request('GET', '/v5/organization/user-info', (new HttpOptions())
->setAuthBearer($authData['token'])
->setAuthBearer($this->authData['token'])
->setHeader('Accept', 'application/json')
->setBaseUri(self::BASE_URL)
->toArray()
)->toArray();
$httpOptions = (new HttpOptions())
->setAuthBearer($authData['token'])
->setAuthBearer($this->authData['token'])
->setHeader('Accept', 'application/json')
->setBaseUri(self::BASE_URL)
->setHeader('Dry-Run', $dryRun ? '1' : '0')
@@ -68,9 +72,9 @@ class GandiProvider extends AbstractProvider
'tld_period' => 'golive',
]);
if (array_key_exists('sharingId', $authData)) {
if (array_key_exists('sharingId', $this->authData)) {
$httpOptions->setQuery([
'sharing_id' => $authData['sharingId'],
'sharing_id' => $this->authData['sharingId'],
]);
}
@@ -78,14 +82,11 @@ class GandiProvider extends AbstractProvider
if ((!$dryRun && Response::HTTP_ACCEPTED !== $res->getStatusCode())
|| ($dryRun && Response::HTTP_OK !== $res->getStatusCode())) {
throw new \HttpException($res->toArray()['message']);
throw new HttpException($res->toArray()['message']);
}
}
/**
* @throws TransportExceptionInterface
*/
public static function verifyAuthData(array $authData, HttpClientInterface $client): array
public function verifyAuthData(array $authData): array
{
$token = $authData['token'];
@@ -105,17 +106,6 @@ class GandiProvider extends AbstractProvider
throw new HttpException(451, 'The user has not given explicit consent');
}
$response = $client->request('GET', '/v5/organization/user-info', (new HttpOptions())
->setAuthBearer($token)
->setHeader('Accept', 'application/json')
->setBaseUri(self::BASE_URL)
->toArray()
);
if (Response::HTTP_OK !== $response->getStatusCode()) {
throw new BadRequestHttpException('The status of these credentials is not valid');
}
$authDataReturned = [
'token' => $token,
'acceptConditions' => $acceptConditions,
@@ -130,6 +120,23 @@ class GandiProvider extends AbstractProvider
return $authDataReturned;
}
/**
* @throws TransportExceptionInterface
*/
public function assertAuthentication(): void
{
$response = $this->client->request('GET', '/v5/organization/user-info', (new HttpOptions())
->setAuthBearer($this->authData['token'])
->setHeader('Accept', 'application/json')
->setBaseUri(self::BASE_URL)
->toArray()
);
if (Response::HTTP_OK !== $response->getStatusCode()) {
throw new BadRequestHttpException('The status of these credentials is not valid');
}
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
@@ -139,10 +146,8 @@ class GandiProvider extends AbstractProvider
*/
protected function getSupportedTldList(): array
{
$authData = self::verifyAuthData($this->authData, $this->client);
$response = $this->client->request('GET', '/v5/domain/tlds', (new HttpOptions())
->setAuthBearer($authData['token'])
->setAuthBearer($this->authData['token'])
->setHeader('Accept', 'application/json')
->setBaseUri(self::BASE_URL)
->toArray())->toArray();

View File

@@ -0,0 +1,148 @@
<?php
namespace App\Service\Connector;
use App\Entity\Domain;
use Exception;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
#[Autoconfigure(public: true)]
class NamecheapProvider extends AbstractProvider
{
public const BASE_URL = 'https://api.namecheap.com/xml.response';
public const SANDBOX_BASE_URL = 'https://api.sandbox.namecheap.com/xml.response';
public function __construct(CacheItemPoolInterface $cacheItemPool, private HttpClientInterface $client, private readonly string $outgoingIp)
{
parent::__construct($cacheItemPool);
}
/**
* @throws \Exception
* @throws TransportExceptionInterface
*/
public function orderDomain(Domain $domain, $dryRun): void
{
$addressesRes = $this->call('namecheap.users.address.getList', [], $dryRun);
$addresses = $addressesRes->AddressGetListResult->List;
if (count($addresses) < 1) {
throw new \Exception('Namecheap account requires at least one address to purchase a domain');
}
$addressId = (string) $addresses->attributes()['AddressId'];
$address = (array) $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId], $dryRun)->GetAddressInfoResult;
if (empty($address['PostalCode'])) {
$address['PostalCode'] = $address['Zip'];
}
$domainAddresses = [];
self::mergePrefixKeys('Registrant', $address, $domainAddresses);
self::mergePrefixKeys('Tech', $address, $domainAddresses);
self::mergePrefixKeys('Admin', $address, $domainAddresses);
self::mergePrefixKeys('AuxBilling', $address, $domainAddresses);
$this->call('namecheap.domains.create', array_merge([
'DomainName' => $domain->getLdhName(),
'Years' => 1,
'AddFreeWhoisguard' => 'yes',
'WGEnabled' => 'yes',
], $domainAddresses), $dryRun);
}
private static function mergePrefixKeys(string $prefix, array|object $src, array &$dest): void
{
foreach ($src as $key => $value) {
$dest[$prefix.$key] = $value;
}
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
* @throws \Exception
*/
private function call(string $command, array $parameters = [], bool $dryRun = true): object
{
$actualParams = array_merge([
'Command' => $command,
'UserName' => $this->authData['ApiUser'],
'ApiUser' => $this->authData['ApiUser'],
'ApiKey' => $this->authData['ApiKey'],
'ClientIp' => $this->outgoingIp,
], $parameters);
$response = $this->client->request('POST', $dryRun ? self::SANDBOX_BASE_URL : self::BASE_URL, [
'query' => $actualParams,
]);
$data = new \SimpleXMLElement($response->getContent());
if ($data->Errors->Error) {
throw new \Exception($data->Errors->Error); // FIXME better exception type
}
return $data->CommandResponse;
}
public function verifyAuthData(array $authData): array
{
return [
'ApiUser' => $authData['ApiUser'],
'ApiKey' => $authData['ApiKey'],
'acceptConditions' => $authData['acceptConditions'],
'ownerLegalAge' => $authData['ownerLegalAge'],
];
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function assertAuthentication(): void
{
$this->call('namecheap.domains.gettldlist', [], false);
}
/**
* @throws InvalidArgumentException
*/
protected function getCachedTldList(): CacheItemInterface
{
return $this->cacheItemPool->getItem('app.provider.namecheap.supported-tld');
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
protected function getSupportedTldList(): array
{
$supported = [];
$tlds = $this->call('namecheap.domains.gettldlist', [], false)->Tlds->Tld;
for ($i = 0; $i < $tlds->count(); ++$i) {
$supported[] = (string) $tlds[$i]['Name'];
}
return $supported;
}
}

View File

@@ -1,16 +1,16 @@
<?php
namespace App\Config\Provider;
namespace App\Service\Connector;
use App\Entity\Domain;
use GuzzleHttp\Exception\ClientException;
use Ovh\Api;
use Ovh\Exceptions\InvalidParameterException;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class OvhProvider extends AbstractProvider
{
@@ -41,6 +41,11 @@ class OvhProvider extends AbstractProvider
],
];
public function __construct(CacheItemPoolInterface $cacheItemPool)
{
parent::__construct($cacheItemPool);
}
/**
* Order a domain name with the OVH API.
*
@@ -57,21 +62,19 @@ class OvhProvider extends AbstractProvider
throw new \InvalidArgumentException('Domain name cannot be null');
}
$authData = self::verifyAuthData($this->authData, $this->client);
$acceptConditions = $authData['acceptConditions'];
$ownerLegalAge = $authData['ownerLegalAge'];
$waiveRetractationPeriod = $authData['waiveRetractationPeriod'];
$acceptConditions = $this->authData['acceptConditions'];
$ownerLegalAge = $this->authData['ownerLegalAge'];
$waiveRetractationPeriod = $this->authData['waiveRetractationPeriod'];
$conn = new Api(
$authData['appKey'],
$authData['appSecret'],
$authData['apiEndpoint'],
$authData['consumerKey']
$this->authData['appKey'],
$this->authData['appSecret'],
$this->authData['apiEndpoint'],
$this->authData['consumerKey']
);
$cart = $conn->post('/order/cart', [
'ovhSubsidiary' => $authData['ovhSubsidiary'],
'ovhSubsidiary' => $this->authData['ovhSubsidiary'],
'description' => 'Domain Watchdog',
]);
$cartId = $cart['cartId'];
@@ -81,8 +84,8 @@ class OvhProvider extends AbstractProvider
]);
$pricingModes = ['create-default'];
if ('create-default' !== $authData['pricingMode']) {
$pricingModes[] = $authData['pricingMode'];
if ('create-default' !== $this->authData['pricingMode']) {
$pricingModes[] = $this->authData['pricingMode'];
}
$offer = array_filter($offers, fn ($offer) => 'create' === $offer['action']
@@ -131,7 +134,7 @@ class OvhProvider extends AbstractProvider
/**
* @throws \Exception
*/
public static function verifyAuthData(array $authData, HttpClientInterface $client): array
public function verifyAuthData(array $authData): array
{
$appKey = $authData['appKey'];
$appSecret = $authData['appSecret'];
@@ -160,11 +163,26 @@ class OvhProvider extends AbstractProvider
throw new HttpException(451, 'The user has not given explicit consent');
}
return [
'appKey' => $appKey,
'appSecret' => $appSecret,
'apiEndpoint' => $apiEndpoint,
'consumerKey' => $consumerKey,
'ovhSubsidiary' => $ovhSubsidiary,
'pricingMode' => $pricingMode,
'acceptConditions' => $acceptConditions,
'ownerLegalAge' => $ownerLegalAge,
'waiveRetractationPeriod' => $waiveRetractationPeriod,
];
}
public function assertAuthentication(): void
{
$conn = new Api(
$appKey,
$appSecret,
$apiEndpoint,
$consumerKey
$this->authData['appKey'],
$this->authData['appSecret'],
$this->authData['apiEndpoint'],
$this->authData['consumerKey'],
);
try {
@@ -197,18 +215,6 @@ class OvhProvider extends AbstractProvider
throw new BadRequestHttpException('This Connector does not have enough permissions on the Provider API. Please recreate this Connector.');
}
}
return [
'appKey' => $appKey,
'appSecret' => $appSecret,
'apiEndpoint' => $apiEndpoint,
'consumerKey' => $consumerKey,
'ovhSubsidiary' => $ovhSubsidiary,
'pricingMode' => $pricingMode,
'acceptConditions' => $acceptConditions,
'ownerLegalAge' => $ownerLegalAge,
'waiveRetractationPeriod' => $waiveRetractationPeriod,
];
}
/**
@@ -218,17 +224,15 @@ class OvhProvider extends AbstractProvider
*/
protected function getSupportedTldList(): array
{
$authData = self::verifyAuthData($this->authData, $this->client);
$conn = new Api(
$authData['appKey'],
$authData['appSecret'],
$authData['apiEndpoint'],
$authData['consumerKey']
$this->authData['appKey'],
$this->authData['appSecret'],
$this->authData['apiEndpoint'],
$this->authData['consumerKey']
);
return $conn->get('/domain/extensions', [
'ovhSubsidiary' => $authData['ovhSubsidiary'],
'ovhSubsidiary' => $this->authData['ovhSubsidiary'],
]);
}

View File

@@ -232,25 +232,27 @@ readonly class RDAPService
$event->setDeleted(true);
}
foreach ($res['events'] as $rdapEvent) {
if ($rdapEvent['eventAction'] === EventAction::LastUpdateOfRDAPDatabase->value) {
continue;
}
if (array_key_exists('events', $res) && is_array($res['events'])) {
foreach ($res['events'] as $rdapEvent) {
if ($rdapEvent['eventAction'] === EventAction::LastUpdateOfRDAPDatabase->value) {
continue;
}
$event = $this->domainEventRepository->findOneBy([
'action' => $rdapEvent['eventAction'],
'date' => new \DateTimeImmutable($rdapEvent['eventDate']),
'domain' => $domain,
]);
$event = $this->domainEventRepository->findOneBy([
'action' => $rdapEvent['eventAction'],
'date' => new \DateTimeImmutable($rdapEvent['eventDate']),
'domain' => $domain,
]);
if (null === $event) {
$event = new DomainEvent();
if (null === $event) {
$event = new DomainEvent();
}
$domain->addEvent($event
->setAction($rdapEvent['eventAction'])
->setDate(new \DateTimeImmutable($rdapEvent['eventDate']))
->setDeleted(false)
);
}
$domain->addEvent($event
->setAction($rdapEvent['eventAction'])
->setDate(new \DateTimeImmutable($rdapEvent['eventDate']))
->setDeleted(false)
);
}
/** @var DomainEntity $domainEntity */