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;
use App\Entity\Domain;
use App\Entity\Tld;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\HttpKernel\KernelInterface;
@ -23,22 +22,32 @@ abstract class AbstractProvider
abstract public function orderDomain(Domain $domain, bool $dryRun): void;
public function isSupported(Tld ...$tldList): bool
public function isSupported(Domain ...$domainList): bool
{
$item = $this->getCachedTldList();
if (!$item->isHit()) {
$supportedTldList = $this->getSupportedTldList();
$item
->set($supportedTldList)
->expiresAfter(new \DateInterval('P1D'));
->expiresAfter(new \DateInterval('PT1H'));
$this->cacheItemPool->saveDeferred($item);
} else {
$supportedTldList = $item->get();
}
/** @var string $tldString */
foreach (array_unique(array_map(fn (Tld $tld) => $tld->getTld(), $tldList)) as $tldString) {
if (!in_array($tldString, $supportedTldList)) {
$extensionList = [];
foreach ($domainList as $domain) {
// 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;
}
}

View File

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

View File

@ -207,17 +207,7 @@ class WatchListController extends AbstractController
$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
$tldList = [];
/** @var Domain $domain */
foreach ($watchList->getDomains()->getIterator() as $domain) {
$tld = $domain->getTld();
if (!in_array($tld, $tldList)) {
$tldList[] = $tld;
}
}
$supported = $connectorProvider->isSupported(...$tldList);
$supported = $connectorProvider->isSupported(...$watchList->getDomains()->toArray());
if (!$supported) {
$this->logger->notice('The Connector ({connector}) does not support all TLDs in this Watchlist', [