mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
chore: progress towards namecheap
This commit is contained in:
@@ -2,19 +2,22 @@
|
|||||||
|
|
||||||
namespace App\Config;
|
namespace App\Config;
|
||||||
|
|
||||||
use App\Config\Connector\GandiConnector;
|
use App\Service\Connector\OvhConnector;
|
||||||
use App\Config\Connector\OvhConnector;
|
use App\Service\Connector\GandiConnector;
|
||||||
|
use App\Service\Connector\NamecheapConnector;
|
||||||
|
|
||||||
enum ConnectorProvider: string
|
enum ConnectorProvider: string
|
||||||
{
|
{
|
||||||
case OVH = 'ovh';
|
case OVH = 'ovh';
|
||||||
case GANDI = 'gandi';
|
case GANDI = 'gandi';
|
||||||
|
case NAMECHEAP = 'namecheap';
|
||||||
|
|
||||||
public function getConnectorProvider(): string
|
public function getConnectorProvider(): string
|
||||||
{
|
{
|
||||||
return match ($this) {
|
return match ($this) {
|
||||||
ConnectorProvider::OVH => OvhConnector::class,
|
ConnectorProvider::OVH => OvhConnector::class,
|
||||||
ConnectorProvider::GANDI => GandiConnector::class
|
ConnectorProvider::GANDI => GandiConnector::class,
|
||||||
|
ConnectorProvider::NAMECHEAP => NamecheapConnector::class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\MessageHandler;
|
namespace App\MessageHandler;
|
||||||
|
|
||||||
use App\Config\Connector\ConnectorInterface;
|
|
||||||
use App\Config\TriggerAction;
|
use App\Config\TriggerAction;
|
||||||
use App\Entity\Connector;
|
use App\Entity\Connector;
|
||||||
use App\Entity\Domain;
|
use App\Entity\Domain;
|
||||||
@@ -22,6 +21,8 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
|||||||
use Symfony\Component\Mime\Address;
|
use Symfony\Component\Mime\Address;
|
||||||
use Symfony\Component\Mime\Email;
|
use Symfony\Component\Mime\Email;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
use App\Service\Connector\ConnectorInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
|
||||||
|
|
||||||
#[AsMessageHandler]
|
#[AsMessageHandler]
|
||||||
final readonly class ProcessDomainTriggerHandler
|
final readonly class ProcessDomainTriggerHandler
|
||||||
@@ -34,7 +35,8 @@ final readonly class ProcessDomainTriggerHandler
|
|||||||
private DomainRepository $domainRepository,
|
private DomainRepository $domainRepository,
|
||||||
private KernelInterface $kernel,
|
private KernelInterface $kernel,
|
||||||
private LoggerInterface $logger,
|
private LoggerInterface $logger,
|
||||||
private HttpClientInterface $client
|
private HttpClientInterface $client,
|
||||||
|
private ContainerBagInterface $container
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +68,7 @@ final readonly class ProcessDomainTriggerHandler
|
|||||||
$connectorProviderClass = $provider->getConnectorProvider();
|
$connectorProviderClass = $provider->getConnectorProvider();
|
||||||
|
|
||||||
/** @var ConnectorInterface $connectorProvider */
|
/** @var ConnectorInterface $connectorProvider */
|
||||||
$connectorProvider = new $connectorProviderClass($connector->getAuthData(), $this->client);
|
$connectorProvider = $this->container->get($connectorProviderClass);
|
||||||
|
|
||||||
$connectorProvider->orderDomain($domain, $this->kernel->isDebug());
|
$connectorProvider->orderDomain($domain, $this->kernel->isDebug());
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Config\Connector;
|
namespace App\Service\Connector;
|
||||||
|
|
||||||
use App\Entity\Domain;
|
use App\Entity\Domain;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Config\Connector;
|
namespace App\Service\Connector;
|
||||||
|
|
||||||
use App\Entity\Domain;
|
use App\Entity\Domain;
|
||||||
use http\Exception\InvalidArgumentException;
|
use http\Exception\InvalidArgumentException;
|
||||||
48
src/Service/Connector/NamecheapConnector.php
Normal file
48
src/Service/Connector/NamecheapConnector.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Service\Connector;
|
||||||
|
|
||||||
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
use App\Entity\Domain;
|
||||||
|
|
||||||
|
class NamecheapConnector implements ConnectorInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
const BASE_URL = 'https://api.namecheap.com/xml.response';
|
||||||
|
|
||||||
|
const SANDBOX_BASE_URL = 'http://www.sandbox.namecheap.com';
|
||||||
|
|
||||||
|
public function __construct(private array $authData, private HttpClientInterface $client)
|
||||||
|
{}
|
||||||
|
|
||||||
|
public function orderDomain(Domain $domain, $dryRun): void
|
||||||
|
{}
|
||||||
|
|
||||||
|
private function call(string $command, array $parameters, array $authData = null): object
|
||||||
|
{
|
||||||
|
if (is_null($authData)) {
|
||||||
|
$authData = $this->authData;
|
||||||
|
}
|
||||||
|
|
||||||
|
$actualParams = array_merge([
|
||||||
|
'ApiUser' => $authData['ApiUser'],
|
||||||
|
'ApiKey' => $authData['ApiKey']
|
||||||
|
], $parameters);
|
||||||
|
|
||||||
|
$response = $this->client->request('POST', BASE_URL, [
|
||||||
|
'query' => $actualParams
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = new \SimpleXMLElement($response->getContent());
|
||||||
|
|
||||||
|
if ($data->errors->error) {
|
||||||
|
throw new \Exception(implode(', ', $data->errors->error)); // FIXME better exception type
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data->CommandResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function verifyAuthData(array $authData, HttpClientInterface $client): array
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Config\Connector;
|
namespace App\Service\Connector;
|
||||||
|
|
||||||
use App\Entity\Domain;
|
use App\Entity\Domain;
|
||||||
use Ovh\Api;
|
use Ovh\Api;
|
||||||
@@ -14,7 +14,8 @@ readonly class OvhConnector implements ConnectorInterface
|
|||||||
[
|
[
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'path' => '/order/cart',
|
'path' => '/order/cart',
|
||||||
], [
|
],
|
||||||
|
[
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'path' => '/order/cart/*',
|
'path' => '/order/cart/*',
|
||||||
],
|
],
|
||||||
Reference in New Issue
Block a user