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;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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', [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user