feat: verify SLD before adding connector

This commit is contained in:
Maël Gangloff 2024-08-24 18:22:15 +02:00
parent afd6a3810e
commit e3f1229c74
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
3 changed files with 17 additions and 18 deletions

View File

@ -3,7 +3,6 @@
namespace App\Config\Provider; namespace App\Config\Provider;
use App\Entity\Domain; use App\Entity\Domain;
use App\Entity\Tld;
use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\KernelInterface;
@ -23,22 +22,32 @@ abstract class AbstractProvider
abstract public function orderDomain(Domain $domain, bool $dryRun): void; abstract public function orderDomain(Domain $domain, bool $dryRun): void;
public function isSupported(Tld ...$tldList): bool public function isSupported(Domain ...$domainList): bool
{ {
$item = $this->getCachedTldList(); $item = $this->getCachedTldList();
if (!$item->isHit()) { if (!$item->isHit()) {
$supportedTldList = $this->getSupportedTldList(); $supportedTldList = $this->getSupportedTldList();
$item $item
->set($supportedTldList) ->set($supportedTldList)
->expiresAfter(new \DateInterval('P1D')); ->expiresAfter(new \DateInterval('PT1H'));
$this->cacheItemPool->saveDeferred($item); $this->cacheItemPool->saveDeferred($item);
} else { } else {
$supportedTldList = $item->get(); $supportedTldList = $item->get();
} }
/** @var string $tldString */ $extensionList = [];
foreach (array_unique(array_map(fn (Tld $tld) => $tld->getTld(), $tldList)) as $tldString) { foreach ($domainList as $domain) {
if (!in_array($tldString, $supportedTldList)) { // We want to check the support of TLDs and SLDs here.
// For example, it is not enough for the Connector to support .fr for it to support the domain name example.asso.fr.
// It must support .asso.fr.
$extension = explode('.', $domain->getLdhName(), 2)[1];
if (!in_array($extension, $extensionList)) {
$extensionList[] = $extension;
}
}
foreach ($extensionList as $extension) {
if (!in_array($extension, $supportedTldList)) {
return false; return false;
} }
} }

View File

@ -69,7 +69,7 @@ class StatisticsController extends AbstractController
$value = $getItemFunction(); $value = $getItemFunction();
$item $item
->set($value) ->set($value)
->expiresAfter(24 * 60 * 60); ->expiresAfter(new \DateInterval('PT6H'));
$this->pool->save($item); $this->pool->save($item);
return $value; return $value;

View File

@ -207,17 +207,7 @@ class WatchListController extends AbstractController
$connectorProvider = new $connectorProviderClass($connector->getAuthData(), $this->httpClient, $this->cacheItemPool, $this->kernel); $connectorProvider = new $connectorProviderClass($connector->getAuthData(), $this->httpClient, $this->cacheItemPool, $this->kernel);
$connectorProvider::verifyAuthData($connector->getAuthData(), $this->httpClient); // We want to check if the tokens are OK $connectorProvider::verifyAuthData($connector->getAuthData(), $this->httpClient); // We want to check if the tokens are OK
$supported = $connectorProvider->isSupported(...$watchList->getDomains()->toArray());
$tldList = [];
/** @var Domain $domain */
foreach ($watchList->getDomains()->getIterator() as $domain) {
$tld = $domain->getTld();
if (!in_array($tld, $tldList)) {
$tldList[] = $tld;
}
}
$supported = $connectorProvider->isSupported(...$tldList);
if (!$supported) { if (!$supported) {
$this->logger->notice('The Connector ({connector}) does not support all TLDs in this Watchlist', [ $this->logger->notice('The Connector ({connector}) does not support all TLDs in this Watchlist', [