chore: merge master

This commit is contained in:
Maël Gangloff 2025-03-03 12:58:38 +01:00
commit c259d6b528
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
10 changed files with 112 additions and 42 deletions

View File

@ -60,14 +60,6 @@ export default function OvhCloudConnectorForm({form}: {
<Input autoComplete='off'/>
</Form.Item>
<Form.Item
label={t`Application key`}
name={['authData', 'appKey']}
rules={[{required: true, message: t`Required`}]}
>
<Input autoComplete='off'/>
</Form.Item>
<Form.Item
label={t`OVH Endpoint`}
name={['authData', 'apiEndpoint']}

View File

@ -35,6 +35,10 @@ security:
login_throttling:
limiter: app.login_rate_limiter
api_public:
pattern: ^/api(?:/docs|/register|/config)?$
stateless: true
api:
pattern: ^/api
stateless: true

View File

@ -14,16 +14,13 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\SerializerInterface;
class ConnectorController extends AbstractController
{
public function __construct(
private readonly SerializerInterface $serializer,
private readonly EntityManagerInterface $em,
private readonly LoggerInterface $logger,
#[Autowire(service: 'service_container')]
@ -61,10 +58,8 @@ class ConnectorController extends AbstractController
],
methods: ['POST']
)]
public function createConnector(Request $request): Connector
public function createConnector(Connector $connector): Connector
{
/** @var Connector $connector */
$connector = $this->serializer->deserialize($request->getContent(), Connector::class, 'json', ['groups' => 'connector:create']);
/** @var User $user */
$user = $this->getUser();
$connector->setUser($user);

View File

@ -26,7 +26,8 @@ class DomainRefreshController extends AbstractController
private readonly RDAPService $RDAPService,
private readonly RateLimiterFactory $rdapRequestsLimiter,
private readonly MessageBusInterface $bus,
private readonly LoggerInterface $logger, private readonly KernelInterface $kernel,
private readonly LoggerInterface $logger,
private readonly KernelInterface $kernel,
) {
}
@ -38,7 +39,7 @@ class DomainRefreshController extends AbstractController
* @throws HttpExceptionInterface
* @throws \Throwable
*/
public function __invoke(string $ldhName, KernelInterface $kernel, Request $request): Domain
public function __invoke(string $ldhName, Request $request): Domain
{
$idnDomain = strtolower(idn_to_ascii($ldhName));
$userId = $this->getUser()->getUserIdentifier();
@ -64,7 +65,7 @@ class DomainRefreshController extends AbstractController
return $domain;
}
if (false === $kernel->isDebug() && true === $this->getParameter('limited_features')) {
if (false === $this->kernel->isDebug() && true === $this->getParameter('limited_features')) {
$limiter = $this->rdapRequestsLimiter->create($userId);
$limit = $limiter->consume();

View File

@ -9,13 +9,16 @@ use App\Entity\DomainEvent;
use App\Entity\User;
use App\Entity\WatchList;
use App\Notifier\TestChatNotification;
use App\Repository\DomainRepository;
use App\Repository\WatchListRepository;
use App\Service\ChatNotificationService;
use App\Service\Connector\AbstractProvider;
use App\Service\RDAPService;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\OptimisticLockException;
use Eluceo\iCal\Domain\Entity\Attendee;
use Eluceo\iCal\Domain\Entity\Calendar;
use Eluceo\iCal\Domain\Entity\Event;
@ -40,24 +43,45 @@ 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\Exception\TooManyRequestsHttpException;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\RateLimiter\RateLimiterFactory;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class WatchListController extends AbstractController
{
public function __construct(
private readonly SerializerInterface $serializer,
private readonly SerializerInterface&DecoderInterface&DenormalizerInterface $serializer,
private readonly EntityManagerInterface $em,
private readonly WatchListRepository $watchListRepository,
private readonly LoggerInterface $logger,
private readonly ChatNotificationService $chatNotificationService,
private readonly DomainRepository $domainRepository,
private readonly RDAPService $RDAPService,
private readonly RateLimiterFactory $rdapRequestsLimiter,
private readonly KernelInterface $kernel,
#[Autowire(service: 'service_container')]
private ContainerInterface $locator,
private readonly ContainerInterface $locator,
) {
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws \JsonException
* @throws \Exception
*/
#[Route(
@ -71,7 +95,7 @@ class WatchListController extends AbstractController
)]
public function createWatchList(Request $request): WatchList
{
$watchList = $this->serializer->deserialize($request->getContent(), WatchList::class, 'json', ['groups' => 'watchlist:create']);
$watchList = $this->registerDomainsInWatchlist($request->getContent(), ['watchlist:create']);
/** @var User $user */
$user = $this->getUser();
@ -199,6 +223,14 @@ class WatchListController extends AbstractController
/**
* @throws ORMException
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws \JsonException
* @throws OptimisticLockException
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws ExceptionInterface
* @throws \Exception
*/
#[Route(
@ -210,8 +242,10 @@ class WatchListController extends AbstractController
],
methods: ['PUT']
)]
public function putWatchList(WatchList $watchList): WatchList
public function putWatchList(Request $request): WatchList
{
$watchList = $this->registerDomainsInWatchlist($request->getContent(), ['watchlist:create', 'watchlist:token']);
/** @var User $user */
$user = $this->getUser();
$watchList->setUser($user);
@ -400,4 +434,48 @@ class WatchListController extends AbstractController
return $domains;
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws \JsonException
*/
private function registerDomainsInWatchlist(string $content, array $groups): WatchList
{
/** @var WatchList $watchList */
$watchList = $this->serializer->deserialize($content, WatchList::class, 'json', ['groups' => $groups]);
$data = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
if (!is_array($data) || !isset($data['domains']) || !is_array($data['domains'])) {
throw new BadRequestHttpException('Invalid payload: missing or invalid "domains" field.');
}
$domains = array_map(fn (string $d) => str_replace('/api/domains/', '', $d), $data['domains']);
foreach ($domains as $ldhName) {
/** @var ?Domain $domain */
$domain = $this->domainRepository->findOneBy(['ldhName' => $ldhName]);
if (null === $domain) {
$domain = $this->RDAPService->registerDomain($ldhName);
if (false === $this->kernel->isDebug() && true === $this->getParameter('limited_features')) {
$limiter = $this->rdapRequestsLimiter->create($this->getUser()->getUserIdentifier());
$limit = $limiter->consume();
if (!$limit->isAccepted()) {
throw new TooManyRequestsHttpException($limit->getRetryAfter()->getTimestamp() - time());
}
}
}
$watchList->addDomain($domain);
}
return $watchList;
}
}

View File

@ -104,7 +104,7 @@ class WatchList
#[ORM\JoinTable(name: 'watch_lists_domains',
joinColumns: [new ORM\JoinColumn(name: 'watch_list_token', referencedColumnName: 'token', onDelete: 'CASCADE')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name', onDelete: 'CASCADE')])]
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create'])]
#[Groups(['watchlist:list', 'watchlist:item'])]
private Collection $domains;
/**

View File

@ -13,7 +13,6 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
@ -58,8 +57,8 @@ abstract class AbstractProvider
$data = $this->serializer->denormalize($this->verifyLegalAuthData($authData), $this->dtoClass);
$violations = $this->validator->validate($data);
if ($violations->count()) {
throw new BadRequestHttpException(implode('\n', array_map(fn (ConstraintViolationInterface $v) => $v->getPropertyPath().': '.$v->getMessage(), iterator_to_array($violations))));
if ($violations->count() > 0) {
throw new BadRequestHttpException((string) $violations);
}
return [

View File

@ -2,6 +2,7 @@
namespace App\Service\Connector;
use App\Dto\Connector\NameComProviderDto;
use App\Entity\Domain;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
@ -21,9 +22,10 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
#[Autoconfigure(public: true)]
class NameComProvider extends AbstractProvider
{
protected string $dtoClass = NameComProvider::class;
protected string $dtoClass = NameComProviderDto::class;
public function __construct(CacheItemPoolInterface $cacheItemPool,
public function __construct(
CacheItemPoolInterface $cacheItemPool,
private readonly HttpClientInterface $client,
private readonly KernelInterface $kernel,
DenormalizerInterface&NormalizerInterface $serializer,

View File

@ -150,7 +150,7 @@ readonly class RDAPService
$this->updateDomainStatus($domain, $rdapData);
if (in_array('free', $domain->getStatus())) {
throw new NotFoundHttpException('The domain name is not present in the WHOIS database.');
throw new NotFoundHttpException("The domain name $idnDomain is not present in the WHOIS database.");
}
$domain->setRdapServer($rdapServer)->setDelegationSigned(isset($rdapData['secureDNS']['delegationSigned']) && true === $rdapData['secureDNS']['delegationSigned']);
@ -170,13 +170,13 @@ readonly class RDAPService
return $domain;
}
private function getTld($domain): Tld
private function getTld(string $domain): Tld
{
if (!str_contains($domain, '.')) {
$tldEntity = $this->tldRepository->findOneBy(['tld' => '']);
if (null == $tldEntity) {
throw new NotFoundHttpException('The requested TLD is not yet supported, please try again with another one');
throw new NotFoundHttpException("The requested TLD $domain is not yet supported, please try again with another one");
}
return $tldEntity;
@ -192,7 +192,7 @@ readonly class RDAPService
$tldEntity = $this->tldRepository->findOneBy(['tld' => $tld]);
if (null === $tldEntity) {
throw new NotFoundHttpException('The requested TLD is not yet supported, please try again with another one');
throw new NotFoundHttpException("The requested TLD $tld is not yet supported, please try again with another one");
}
return $tldEntity;
@ -205,10 +205,11 @@ readonly class RDAPService
private function fetchRdapServer(Tld $tld): RdapServer
{
$rdapServer = $this->rdapServerRepository->findOneBy(['tld' => $tld], ['updatedAt' => 'DESC']);
$tldString = $tld->getTld();
$rdapServer = $this->rdapServerRepository->findOneBy(['tld' => $tldString], ['updatedAt' => 'DESC']);
if (null === $rdapServer) {
throw new NotFoundHttpException('Unable to determine which RDAP server to contact');
throw new NotFoundHttpException("TLD $tldString : Unable to determine which RDAP server to contact");
}
return $rdapServer;
@ -262,7 +263,7 @@ readonly class RDAPService
$this->em->flush();
}
throw new NotFoundHttpException('The domain name is not present in the WHOIS database.');
throw new NotFoundHttpException("The domain name $idnDomain is not present in the WHOIS database.");
}
return $e;

View File

@ -58,9 +58,8 @@ msgstr ""
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:50
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:58
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:66
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:74
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:73
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:81
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:89
msgid "Required"
msgstr ""
@ -1246,7 +1245,6 @@ msgid ""
msgstr ""
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:34
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:64
msgid "Application key"
msgstr ""
@ -1258,23 +1256,23 @@ msgstr ""
msgid "Consumer key"
msgstr ""
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:72
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:64
msgid "OVH Endpoint"
msgstr ""
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:79
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:71
msgid "OVH subsidiary"
msgstr ""
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:87
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:79
msgid "OVH pricing mode"
msgstr ""
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:92
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:84
msgid "Confirm pricing mode"
msgstr ""
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:93
#: assets/utils/providers/forms/OvhCloudConnectorForm.tsx:85
msgid ""
"Are you sure about this setting? This may result in additional charges from "
"the API Provider"