mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 17:55:42 +00:00
feat: verify SLD before adding connector
This commit is contained in:
parent
afd6a3810e
commit
e3f1229c74
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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', [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user