feat: add logging info

This commit is contained in:
Maël Gangloff
2024-08-04 14:45:27 +02:00
parent 9d7076a76b
commit e413bfedc0
6 changed files with 93 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ use App\Entity\Connector;
use App\Entity\User;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
@@ -16,7 +17,9 @@ use Symfony\Component\Serializer\SerializerInterface;
class ConnectorController extends AbstractController
{
public function __construct(
private readonly SerializerInterface $serializer, private readonly EntityManagerInterface $em
private readonly SerializerInterface $serializer,
private readonly EntityManagerInterface $em,
private readonly LoggerInterface $logger
) {
}
@@ -56,13 +59,28 @@ class ConnectorController extends AbstractController
$user = $this->getUser();
$connector->setUser($user);
if (ConnectorProvider::OVH === $connector->getProvider()) {
$provider = $connector->getProvider();
$this->logger->info('User {username} wants to register a connector from provider {provider}.', [
'username' => $user->getUserIdentifier(),
'provider' => $provider->value,
]);
if (ConnectorProvider::OVH === $provider) {
$authData = OvhConnector::verifyAuthData($connector->getAuthData());
$connector->setAuthData($authData);
$this->logger->info('User {username} authentication data with the OVH provider has been validated.', [
'username' => $user->getUserIdentifier(),
]);
} else {
throw new \Exception('Unknown provider');
}
$this->logger->info('The new API connector requested by {username} has been successfully registered.', [
'username' => $user->getUserIdentifier(),
]);
$this->em->persist($connector);
$this->em->flush();

View File

@@ -7,6 +7,7 @@ use App\Entity\WatchList;
use App\Message\ProcessDomainTrigger;
use App\Repository\DomainRepository;
use App\Service\RDAPService;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
use Symfony\Component\HttpKernel\KernelInterface;
@@ -22,8 +23,9 @@ class DomainRefreshController extends AbstractController
public function __construct(private readonly DomainRepository $domainRepository,
private readonly RDAPService $RDAPService,
private readonly RateLimiterFactory $authenticatedApiLimiter,
private readonly MessageBusInterface $bus)
{
private readonly MessageBusInterface $bus,
private readonly LoggerInterface $logger
) {
}
/**
@@ -36,6 +38,12 @@ class DomainRefreshController extends AbstractController
public function __invoke(string $ldhName, KernelInterface $kernel): ?Domain
{
$idnDomain = strtolower(idn_to_ascii($ldhName));
$userId = $this->getUser()->getUserIdentifier();
$this->logger->info('User {username} wants to update the domain name {idnDomain}.', [
'username' => $userId,
'idnDomain' => $idnDomain,
]);
/** @var ?Domain $domain */
$domain = $this->domainRepository->findOneBy(['ldhName' => $idnDomain]);
@@ -46,12 +54,19 @@ class DomainRefreshController extends AbstractController
&& ($domain->getUpdatedAt()->diff(new \DateTimeImmutable('now'))->days < 7)
&& !$this->RDAPService::isToBeWatchClosely($domain, $domain->getUpdatedAt())
) {
$this->logger->info('It is not necessary to update the information of the domain name {idnDomain} with the RDAP protocol.', [
'idnDomain' => $idnDomain,
]);
return $domain;
}
if (false === $kernel->isDebug()) {
$limiter = $this->authenticatedApiLimiter->create($this->getUser()->getUserIdentifier());
$limiter = $this->authenticatedApiLimiter->create($userId);
if (false === $limiter->consume()->isAccepted()) {
$this->logger->warning('User {username} was rate limited by the API.', [
'username' => $this->getUser()->getUserIdentifier(),
]);
throw new TooManyRequestsHttpException();
}
}

View File

@@ -22,6 +22,7 @@ use Eluceo\iCal\Domain\ValueObject\Timestamp;
use Eluceo\iCal\Presentation\Component\Property;
use Eluceo\iCal\Presentation\Component\Property\Value\TextValue;
use Eluceo\iCal\Presentation\Factory\CalendarFactory;
use Psr\Log\LoggerInterface;
use Sabre\VObject\EofException;
use Sabre\VObject\InvalidDataException;
use Sabre\VObject\ParseException;
@@ -37,7 +38,8 @@ class WatchListController extends AbstractController
public function __construct(
private readonly SerializerInterface $serializer,
private readonly EntityManagerInterface $em,
private readonly WatchListRepository $watchListRepository
private readonly WatchListRepository $watchListRepository,
private readonly LoggerInterface $logger
) {
}
@@ -60,6 +62,10 @@ class WatchListController extends AbstractController
$user = $this->getUser();
$watchList->setUser($user);
$this->logger->info('User {username} register a Watchlist.', [
'username' => $user->getUserIdentifier(),
]);
$this->em->persist($watchList);
$this->em->flush();