mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 17:55:42 +00:00
feat: connector credentials check
This commit is contained in:
parent
2441eb2925
commit
63bc105de9
@ -1,4 +1,4 @@
|
|||||||
import {List, Tag, Tooltip, Typography} from 'antd'
|
import {Flex, List, Tag, Tooltip, Typography} from 'antd'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import type {Domain} from '../../utils/api'
|
import type {Domain} from '../../utils/api'
|
||||||
import {rdapRoleDetailTranslation, rdapRoleTranslation} from '../../utils/functions/rdapTranslation'
|
import {rdapRoleDetailTranslation, rdapRoleTranslation} from '../../utils/functions/rdapTranslation'
|
||||||
@ -37,7 +37,9 @@ export function EntitiesList({domain}: { domain: Domain }) {
|
|||||||
{details.organization && <div>🏢 {details.organization}</div>}
|
{details.organization && <div>🏢 {details.organization}</div>}
|
||||||
</>}
|
</>}
|
||||||
/>
|
/>
|
||||||
{e.roles.map(roleToTag)}
|
<Flex gap='4px 0' wrap>
|
||||||
|
{e.roles.map(roleToTag)}
|
||||||
|
</Flex>
|
||||||
</List.Item>
|
</List.Item>
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -27,6 +27,7 @@ framework:
|
|||||||
App\Message\SendDomainEventNotif: async
|
App\Message\SendDomainEventNotif: async
|
||||||
App\Message\UpdateDomainsFromWatchlist: async
|
App\Message\UpdateDomainsFromWatchlist: async
|
||||||
App\Message\UpdateRdapServers: async
|
App\Message\UpdateRdapServers: async
|
||||||
|
App\Message\ValidateConnectorCredentials: async
|
||||||
|
|
||||||
# Route your messages to the transports
|
# Route your messages to the transports
|
||||||
# 'App\Message\YourMessage': async
|
# 'App\Message\YourMessage': async
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class ConnectorController extends AbstractController
|
|||||||
private readonly EntityManagerInterface $em,
|
private readonly EntityManagerInterface $em,
|
||||||
private readonly LoggerInterface $logger,
|
private readonly LoggerInterface $logger,
|
||||||
#[Autowire(service: 'service_container')]
|
#[Autowire(service: 'service_container')]
|
||||||
private ContainerInterface $locator,
|
private readonly ContainerInterface $locator,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/Message/ValidateConnectorCredentials.php
Normal file
16
src/Message/ValidateConnectorCredentials.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Message;
|
||||||
|
|
||||||
|
final class ValidateConnectorCredentials
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Add whatever properties and methods you need
|
||||||
|
* to hold the data for this message class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// public function __construct(
|
||||||
|
// public readonly string $name,
|
||||||
|
// ) {
|
||||||
|
// }
|
||||||
|
}
|
||||||
53
src/MessageHandler/ValidateConnectorCredentialsHandler.php
Normal file
53
src/MessageHandler/ValidateConnectorCredentialsHandler.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\MessageHandler;
|
||||||
|
|
||||||
|
use App\Message\ValidateConnectorCredentials;
|
||||||
|
use App\Notifier\ValidateConnectorCredentialsErrorNotification;
|
||||||
|
use App\Repository\ConnectorRepository;
|
||||||
|
use App\Service\Connector\AbstractProvider;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||||
|
use Symfony\Component\Mailer\MailerInterface;
|
||||||
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||||
|
use Symfony\Component\Mime\Address;
|
||||||
|
use Symfony\Component\Notifier\Recipient\Recipient;
|
||||||
|
|
||||||
|
#[AsMessageHandler]
|
||||||
|
final readonly class ValidateConnectorCredentialsHandler
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ConnectorRepository $connectorRepository,
|
||||||
|
#[Autowire(service: 'service_container')]
|
||||||
|
private ContainerInterface $locator,
|
||||||
|
private MailerInterface $mailer,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
*/
|
||||||
|
public function __invoke(ValidateConnectorCredentials $message): void
|
||||||
|
{
|
||||||
|
foreach ($this->connectorRepository->findAll() as $connector) {
|
||||||
|
$provider = $connector->getProvider();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (null === $provider) {
|
||||||
|
throw new \Exception('Provider not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var AbstractProvider $providerClient */
|
||||||
|
$providerClient = $this->locator->get($provider->getConnectorProvider());
|
||||||
|
$providerClient->authenticate($connector->getAuthData());
|
||||||
|
} catch (\Exception) {
|
||||||
|
$email = $connector->getUser()->getEmail();
|
||||||
|
$this->mailer->send(
|
||||||
|
(new ValidateConnectorCredentialsErrorNotification(new Address($email), $connector))
|
||||||
|
->asEmailMessage(new Recipient($email))->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifier;
|
||||||
|
|
||||||
|
use App\Entity\Connector;
|
||||||
|
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||||
|
use Symfony\Component\Mime\Address;
|
||||||
|
use Symfony\Component\Notifier\Message\EmailMessage;
|
||||||
|
use Symfony\Component\Notifier\Notification\Notification;
|
||||||
|
use Symfony\Component\Notifier\Recipient\EmailRecipientInterface;
|
||||||
|
|
||||||
|
class ValidateConnectorCredentialsErrorNotification extends Notification
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly Address $sender,
|
||||||
|
private readonly Connector $connector,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asEmailMessage(EmailRecipientInterface $recipient): EmailMessage
|
||||||
|
{
|
||||||
|
return new EmailMessage((new TemplatedEmail())
|
||||||
|
->from($this->sender)
|
||||||
|
->to($recipient->getEmail())
|
||||||
|
->subject('Connector credentials error')
|
||||||
|
->htmlTemplate('emails/errors/connector_credentials.html.twig')
|
||||||
|
->locale('en')
|
||||||
|
->context([
|
||||||
|
'connector' => $this->connector,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/Scheduler/ValidateConnectorCredentialsSchedule.php
Normal file
29
src/Scheduler/ValidateConnectorCredentialsSchedule.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Scheduler;
|
||||||
|
|
||||||
|
use App\Message\ValidateConnectorCredentials;
|
||||||
|
use Symfony\Component\Scheduler\Attribute\AsSchedule;
|
||||||
|
use Symfony\Component\Scheduler\RecurringMessage;
|
||||||
|
use Symfony\Component\Scheduler\Schedule;
|
||||||
|
use Symfony\Component\Scheduler\ScheduleProviderInterface;
|
||||||
|
use Symfony\Contracts\Cache\CacheInterface;
|
||||||
|
|
||||||
|
#[AsSchedule('ValidateConnectorCredentials')]
|
||||||
|
final class ValidateConnectorCredentialsSchedule implements ScheduleProviderInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private CacheInterface $cache,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSchedule(): Schedule
|
||||||
|
{
|
||||||
|
return (new Schedule())
|
||||||
|
->add(
|
||||||
|
RecurringMessage::every('1 week', new ValidateConnectorCredentials()),
|
||||||
|
)
|
||||||
|
->stateful($this->cache)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
templates/emails/errors/connector_credentials.twig
Normal file
22
templates/emails/errors/connector_credentials.twig
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{% extends "emails/base.html.twig" %}
|
||||||
|
|
||||||
|
{% set email_color = '#f9f9f9' %}
|
||||||
|
{% set title = 'Connector Validation Failed' %}
|
||||||
|
{% block content %}
|
||||||
|
<p>Hello, <br/>
|
||||||
|
We would like to inform you that an authentication error occurred during the weekly validation of the following connector:<br/>
|
||||||
|
<strong>Connector ID:</strong> {{ connector.token }}<br/>
|
||||||
|
<strong>Connector Provider:</strong> {{ connector.provider }}<br/>
|
||||||
|
</p>
|
||||||
|
<p>This issue indicates that the login credentials provided for the connector could not be validated. As a result, we were unable to verify the connector's validity.</p>
|
||||||
|
<p>Here are some possible causes:</p>
|
||||||
|
<ul>
|
||||||
|
<li>The login credentials for the connector may have been changed or are incorrect.</li>
|
||||||
|
<li>A temporary issue with the authentication server or service may have occurred.</li>
|
||||||
|
</ul>
|
||||||
|
<br/><br/>
|
||||||
|
<p>To resolve this issue, please verify the login credentials associated with the connector and update them if necessary.</p>
|
||||||
|
<p>Thank you for your attention,<br/>
|
||||||
|
Sincerely,<br/>
|
||||||
|
</p>
|
||||||
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user