mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
Merge branch 'master' into feat/epp-protocol
This commit is contained in:
@@ -16,4 +16,7 @@ final class AutodnsProviderDto extends DefaultProviderDto
|
||||
public bool $ownerConfirm;
|
||||
|
||||
public int $context = 4;
|
||||
|
||||
#[Assert\NotBlank]
|
||||
public string $contactid;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Service\Connector;
|
||||
|
||||
use App\Dto\Connector\DefaultProviderDto;
|
||||
use App\Entity\Domain;
|
||||
use Exception;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
|
||||
@@ -25,12 +24,9 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
#[Autoconfigure(public: true)]
|
||||
abstract class AbstractProvider
|
||||
{
|
||||
/**
|
||||
* @var class-string
|
||||
*/
|
||||
/** @var class-string */
|
||||
protected string $dtoClass = DefaultProviderDto::class;
|
||||
|
||||
protected array $authData;
|
||||
protected DefaultProviderDto $authData;
|
||||
|
||||
public function __construct(
|
||||
protected CacheItemPoolInterface $cacheItemPool,
|
||||
@@ -46,12 +42,12 @@ abstract class AbstractProvider
|
||||
*
|
||||
* @param array $authData raw authentication data as supplied by the user
|
||||
*
|
||||
* @return array a cleaned up version of the authentication data
|
||||
* @return DefaultProviderDto a cleaned up version of the authentication data
|
||||
*
|
||||
* @throws HttpException when the user does not accept the necessary conditions
|
||||
* @throws ExceptionInterface
|
||||
*/
|
||||
private function verifyAuthData(array $authData): array
|
||||
private function verifyAuthData(array $authData): DefaultProviderDto
|
||||
{
|
||||
/** @var DefaultProviderDto $data */
|
||||
$data = $this->serializer->denormalize($this->verifyLegalAuthData($authData), $this->dtoClass);
|
||||
@@ -61,12 +57,7 @@ abstract class AbstractProvider
|
||||
throw new BadRequestHttpException((string) $violations);
|
||||
}
|
||||
|
||||
return [
|
||||
...$this->serializer->normalize($data),
|
||||
'acceptConditions' => $authData['acceptConditions'],
|
||||
'ownerLegalAge' => $authData['ownerLegalAge'],
|
||||
'waiveRetractationPeriod' => $authData['waiveRetractationPeriod'],
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +131,7 @@ abstract class AbstractProvider
|
||||
$this->authData = $this->verifyAuthData($authData);
|
||||
$this->assertAuthentication();
|
||||
|
||||
return $this->authData;
|
||||
return $authData;
|
||||
}
|
||||
|
||||
abstract protected function getCachedTldList(): CacheItemInterface;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Service\Connector;
|
||||
|
||||
use App\Dto\Connector\AutodnsProviderDto;
|
||||
use App\Dto\Connector\DefaultProviderDto;
|
||||
use App\Entity\Domain;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
@@ -26,6 +27,9 @@ class AutodnsProvider extends AbstractProvider
|
||||
{
|
||||
protected string $dtoClass = AutodnsProviderDto::class;
|
||||
|
||||
/** @var AutodnsProviderDto */
|
||||
protected DefaultProviderDto $authData;
|
||||
|
||||
public function __construct(
|
||||
CacheItemPoolInterface $cacheItemPool,
|
||||
DenormalizerInterface&NormalizerInterface $serializer,
|
||||
@@ -59,22 +63,22 @@ class AutodnsProvider extends AbstractProvider
|
||||
'POST',
|
||||
'/v1/domain',
|
||||
(new HttpOptions())
|
||||
->setAuthBasic($this->authData['username'], $this->authData['password'])
|
||||
->setAuthBasic($this->authData->username, $this->authData->password)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setHeader('X-Domainrobot-Context', $this->authData['context'])
|
||||
->setHeader('X-Domainrobot-Context', (string) $this->authData->context)
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->setJson([
|
||||
'name' => $ldhName,
|
||||
'ownerc' => [
|
||||
'id' => $this->authData['contactid'],
|
||||
'id' => $this->authData->contactid,
|
||||
],
|
||||
'adminc' => [
|
||||
'id' => $this->authData['contactid'],
|
||||
'id' => $this->authData->contactid,
|
||||
],
|
||||
'techc' => [
|
||||
'id' => $this->authData['contactid'],
|
||||
'id' => $this->authData->contactid,
|
||||
],
|
||||
'confirmOrder' => $this->authData['ownerConfirm'],
|
||||
'confirmOrder' => $this->authData->ownerConfirm,
|
||||
'nameServers' => [
|
||||
[
|
||||
'name' => 'a.ns14.net',
|
||||
@@ -115,9 +119,9 @@ class AutodnsProvider extends AbstractProvider
|
||||
'POST',
|
||||
'/v1/zone/_search?keys=name',
|
||||
(new HttpOptions())
|
||||
->setAuthBasic($authData['username'], $authData['password'])
|
||||
->setAuthBasic($authData->username, $authData->password)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setHeader('X-Domainrobot-Context', $authData['context'])
|
||||
->setHeader('X-Domainrobot-Context', (string) $authData->context)
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->setJson([
|
||||
'filters' => [
|
||||
@@ -140,14 +144,14 @@ class AutodnsProvider extends AbstractProvider
|
||||
'POST',
|
||||
'/v1/zone',
|
||||
(new HttpOptions())
|
||||
->setAuthBasic($authData['username'], $authData['password'])
|
||||
->setAuthBasic($authData->username, $authData->password)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setHeader('X-Domainrobot-Context', $authData['context'])
|
||||
->setHeader('X-Domainrobot-Context', (string) $authData->context)
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->setJson([
|
||||
'origin' => $ldhName,
|
||||
'main' => [
|
||||
'address' => $authData['dns_ip'],
|
||||
'address' => null, // $authData['dns_ip'],
|
||||
],
|
||||
'soa' => [
|
||||
'refresh' => 3600,
|
||||
@@ -205,9 +209,9 @@ class AutodnsProvider extends AbstractProvider
|
||||
'GET',
|
||||
'/v1/hello',
|
||||
(new HttpOptions())
|
||||
->setAuthBasic($this->authData['username'], $this->authData['password'])
|
||||
->setAuthBasic($this->authData->username, $this->authData->password)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setHeader('X-Domainrobot-Context', $this->authData['context'])
|
||||
->setHeader('X-Domainrobot-Context', (string) $this->authData->context)
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->toArray()
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Service\Connector;
|
||||
|
||||
use App\Dto\Connector\DefaultProviderDto;
|
||||
use App\Dto\Connector\GandiProviderDto;
|
||||
use App\Entity\Domain;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
@@ -26,6 +27,9 @@ class GandiProvider extends AbstractProvider
|
||||
{
|
||||
protected string $dtoClass = GandiProviderDto::class;
|
||||
|
||||
/** @var GandiProviderDto */
|
||||
protected DefaultProviderDto $authData;
|
||||
|
||||
private const BASE_URL = 'https://api.gandi.net';
|
||||
|
||||
public function __construct(
|
||||
@@ -52,14 +56,14 @@ class GandiProvider extends AbstractProvider
|
||||
}
|
||||
|
||||
$user = $this->client->request('GET', '/v5/organization/user-info', (new HttpOptions())
|
||||
->setAuthBearer($this->authData['token'])
|
||||
->setAuthBearer($this->authData->token)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->toArray()
|
||||
)->toArray();
|
||||
|
||||
$httpOptions = (new HttpOptions())
|
||||
->setAuthBearer($this->authData['token'])
|
||||
->setAuthBearer($this->authData->token)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->setHeader('Dry-Run', $dryRun ? '1' : '0')
|
||||
@@ -80,9 +84,9 @@ class GandiProvider extends AbstractProvider
|
||||
'tld_period' => 'golive',
|
||||
]);
|
||||
|
||||
if (array_key_exists('sharingId', $this->authData)) {
|
||||
if ($this->authData->sharingId) {
|
||||
$httpOptions->setQuery([
|
||||
'sharing_id' => $this->authData['sharingId'],
|
||||
'sharing_id' => $this->authData->sharingId,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -100,7 +104,7 @@ class GandiProvider extends AbstractProvider
|
||||
protected function assertAuthentication(): void
|
||||
{
|
||||
$response = $this->client->request('GET', '/v5/organization/user-info', (new HttpOptions())
|
||||
->setAuthBearer($this->authData['token'])
|
||||
->setAuthBearer($this->authData->token)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->toArray()
|
||||
@@ -121,7 +125,7 @@ class GandiProvider extends AbstractProvider
|
||||
protected function getSupportedTldList(): array
|
||||
{
|
||||
$response = $this->client->request('GET', '/v5/domain/tlds', (new HttpOptions())
|
||||
->setAuthBearer($this->authData['token'])
|
||||
->setAuthBearer($this->authData->token)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->toArray())->toArray();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Service\Connector;
|
||||
|
||||
use App\Dto\Connector\DefaultProviderDto;
|
||||
use App\Dto\Connector\NameComProviderDto;
|
||||
use App\Entity\Domain;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
@@ -24,6 +25,9 @@ class NameComProvider extends AbstractProvider
|
||||
{
|
||||
protected string $dtoClass = NameComProviderDto::class;
|
||||
|
||||
/** @var NameComProviderDto */
|
||||
protected DefaultProviderDto $authData;
|
||||
|
||||
public function __construct(
|
||||
CacheItemPoolInterface $cacheItemPool,
|
||||
private readonly HttpClientInterface $client,
|
||||
@@ -56,7 +60,7 @@ class NameComProvider extends AbstractProvider
|
||||
'/v4/domains',
|
||||
(new HttpOptions())
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setAuthBasic($this->authData['username'], $this->authData['token'])
|
||||
->setAuthBasic($this->authData->username, $this->authData->token)
|
||||
->setBaseUri($dryRun ? self::DEV_BASE_URL : self::BASE_URL)
|
||||
->setJson([
|
||||
'domain' => [
|
||||
@@ -103,7 +107,7 @@ class NameComProvider extends AbstractProvider
|
||||
'/v4/hello',
|
||||
(new HttpOptions())
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setAuthBasic($this->authData['username'], $this->authData['token'])
|
||||
->setAuthBasic($this->authData->username, $this->authData->token)
|
||||
->setBaseUri($this->kernel->isDebug() ? self::DEV_BASE_URL : self::BASE_URL)
|
||||
->toArray()
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Service\Connector;
|
||||
|
||||
use App\Dto\Connector\DefaultProviderDto;
|
||||
use App\Dto\Connector\NamecheapProviderDto;
|
||||
use App\Entity\Domain;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
@@ -23,6 +24,9 @@ class NamecheapProvider extends AbstractProvider
|
||||
{
|
||||
protected string $dtoClass = NamecheapProviderDto::class;
|
||||
|
||||
/** @var NamecheapProviderDto */
|
||||
protected DefaultProviderDto $authData;
|
||||
|
||||
public const BASE_URL = 'https://api.namecheap.com/xml.response';
|
||||
public const SANDBOX_BASE_URL = 'https://api.sandbox.namecheap.com/xml.response';
|
||||
|
||||
@@ -88,9 +92,9 @@ class NamecheapProvider extends AbstractProvider
|
||||
{
|
||||
$actualParams = array_merge([
|
||||
'Command' => $command,
|
||||
'UserName' => $this->authData['ApiUser'],
|
||||
'ApiUser' => $this->authData['ApiUser'],
|
||||
'ApiKey' => $this->authData['ApiKey'],
|
||||
'UserName' => $this->authData->ApiUser,
|
||||
'ApiUser' => $this->authData->ApiUser,
|
||||
'ApiKey' => $this->authData->ApiKey,
|
||||
'ClientIp' => $this->outgoingIp,
|
||||
], $parameters);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Service\Connector;
|
||||
|
||||
use App\Dto\Connector\DefaultProviderDto;
|
||||
use App\Dto\Connector\OvhProviderDto;
|
||||
use App\Entity\Domain;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
@@ -21,6 +22,9 @@ class OvhProvider extends AbstractProvider
|
||||
{
|
||||
protected string $dtoClass = OvhProviderDto::class;
|
||||
|
||||
/** @var OvhProviderDto */
|
||||
protected DefaultProviderDto $authData;
|
||||
|
||||
public const REQUIRED_ROUTES = [
|
||||
[
|
||||
'method' => 'GET',
|
||||
@@ -68,19 +72,19 @@ class OvhProvider extends AbstractProvider
|
||||
throw new \InvalidArgumentException('Domain name cannot be null');
|
||||
}
|
||||
|
||||
$acceptConditions = $this->authData['acceptConditions'];
|
||||
$ownerLegalAge = $this->authData['ownerLegalAge'];
|
||||
$waiveRetractationPeriod = $this->authData['waiveRetractationPeriod'];
|
||||
$acceptConditions = $this->authData->acceptConditions;
|
||||
$ownerLegalAge = $this->authData->ownerLegalAge;
|
||||
$waiveRetractationPeriod = $this->authData->waiveRetractationPeriod;
|
||||
|
||||
$conn = new Api(
|
||||
$this->authData['appKey'],
|
||||
$this->authData['appSecret'],
|
||||
$this->authData['apiEndpoint'],
|
||||
$this->authData['consumerKey']
|
||||
$this->authData->appKey,
|
||||
$this->authData->appSecret,
|
||||
$this->authData->apiEndpoint,
|
||||
$this->authData->consumerKey,
|
||||
);
|
||||
|
||||
$cart = $conn->post('/order/cart', [
|
||||
'ovhSubsidiary' => $this->authData['ovhSubsidiary'],
|
||||
'ovhSubsidiary' => $this->authData->ovhSubsidiary,
|
||||
'description' => 'Domain Watchdog',
|
||||
]);
|
||||
$cartId = $cart['cartId'];
|
||||
@@ -90,8 +94,8 @@ class OvhProvider extends AbstractProvider
|
||||
]);
|
||||
|
||||
$pricingModes = ['create-default'];
|
||||
if ('create-default' !== $this->authData['pricingMode']) {
|
||||
$pricingModes[] = $this->authData['pricingMode'];
|
||||
if ('create-default' !== $this->authData->pricingMode) {
|
||||
$pricingModes[] = $this->authData->pricingMode;
|
||||
}
|
||||
|
||||
$offer = array_filter($offers, fn ($offer) => 'create' === $offer['action']
|
||||
@@ -140,10 +144,10 @@ class OvhProvider extends AbstractProvider
|
||||
protected function assertAuthentication(): void
|
||||
{
|
||||
$conn = new Api(
|
||||
$this->authData['appKey'],
|
||||
$this->authData['appSecret'],
|
||||
$this->authData['apiEndpoint'],
|
||||
$this->authData['consumerKey'],
|
||||
$this->authData->appKey,
|
||||
$this->authData->appSecret,
|
||||
$this->authData->apiEndpoint,
|
||||
$this->authData->consumerKey,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -186,14 +190,14 @@ class OvhProvider extends AbstractProvider
|
||||
protected function getSupportedTldList(): array
|
||||
{
|
||||
$conn = new Api(
|
||||
$this->authData['appKey'],
|
||||
$this->authData['appSecret'],
|
||||
$this->authData['apiEndpoint'],
|
||||
$this->authData['consumerKey']
|
||||
$this->authData->appKey,
|
||||
$this->authData->appSecret,
|
||||
$this->authData->apiEndpoint,
|
||||
$this->authData->consumerKey,
|
||||
);
|
||||
|
||||
return $conn->get('/domain/extensions', [
|
||||
'ovhSubsidiary' => $this->authData['ovhSubsidiary'],
|
||||
'ovhSubsidiary' => $this->authData->ovhSubsidiary,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user