chore: progress towards namecheap

This commit is contained in:
vinceh121
2024-08-19 21:17:57 +02:00
parent 4ac43e9ca9
commit f225213c49
6 changed files with 64 additions and 10 deletions

View File

@@ -2,19 +2,22 @@
namespace App\Config;
use App\Config\Connector\GandiConnector;
use App\Config\Connector\OvhConnector;
use App\Service\Connector\OvhConnector;
use App\Service\Connector\GandiConnector;
use App\Service\Connector\NamecheapConnector;
enum ConnectorProvider: string
{
case OVH = 'ovh';
case GANDI = 'gandi';
case NAMECHEAP = 'namecheap';
public function getConnectorProvider(): string
{
return match ($this) {
ConnectorProvider::OVH => OvhConnector::class,
ConnectorProvider::GANDI => GandiConnector::class
ConnectorProvider::GANDI => GandiConnector::class,
ConnectorProvider::NAMECHEAP => NamecheapConnector::class
};
}
}

View File

@@ -2,7 +2,6 @@
namespace App\MessageHandler;
use App\Config\Connector\ConnectorInterface;
use App\Config\TriggerAction;
use App\Entity\Connector;
use App\Entity\Domain;
@@ -22,6 +21,8 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use App\Service\Connector\ConnectorInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
#[AsMessageHandler]
final readonly class ProcessDomainTriggerHandler
@@ -34,7 +35,8 @@ final readonly class ProcessDomainTriggerHandler
private DomainRepository $domainRepository,
private KernelInterface $kernel,
private LoggerInterface $logger,
private HttpClientInterface $client
private HttpClientInterface $client,
private ContainerBagInterface $container
) {
}
@@ -66,7 +68,7 @@ final readonly class ProcessDomainTriggerHandler
$connectorProviderClass = $provider->getConnectorProvider();
/** @var ConnectorInterface $connectorProvider */
$connectorProvider = new $connectorProviderClass($connector->getAuthData(), $this->client);
$connectorProvider = $this->container->get($connectorProviderClass);
$connectorProvider->orderDomain($domain, $this->kernel->isDebug());

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Config\Connector;
namespace App\Service\Connector;
use App\Entity\Domain;
use Symfony\Contracts\HttpClient\HttpClientInterface;

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Config\Connector;
namespace App\Service\Connector;
use App\Entity\Domain;
use http\Exception\InvalidArgumentException;

View 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
{
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Config\Connector;
namespace App\Service\Connector;
use App\Entity\Domain;
use Ovh\Api;
@@ -14,7 +14,8 @@ readonly class OvhConnector implements ConnectorInterface
[
'method' => 'GET',
'path' => '/order/cart',
], [
],
[
'method' => 'GET',
'path' => '/order/cart/*',
],