feat: instance IP address envvar

This commit is contained in:
Vincent
2024-08-23 14:01:02 +02:00
parent 2f841f0127
commit 3e3ea66848
5 changed files with 22 additions and 15 deletions

5
.env
View File

@@ -67,6 +67,11 @@ OAUTH_TOKEN_URL=
OAUTH_USERINFO_URL=
OAUTH_SCOPE=
# Typically your IP address, this envvar is required for
# some connectors that need to be provided with your host's
# outgoing IP address.
OUTGOING_IP=
LIMITED_FEATURES=false
LIMIT_MAX_WATCHLIST=0
LIMIT_MAX_WATCHLIST_DOMAINS=0

View File

@@ -2,7 +2,8 @@ import {request} from "./index";
export enum ConnectorProvider {
OVH = 'ovh',
GANDI = 'gandi'
GANDI = 'gandi',
NAMECHEAP = 'namecheap'
}
export type Connector = {

View File

@@ -15,6 +15,10 @@ export const helpGetTokenLink = (provider?: string) => {
return <Typography.Link target='_blank' href="https://admin.gandi.net/organizations/account/pat">
{t`Retrieve a Personal Access Token from your customer account on the Provider's website`}
</Typography.Link>
case ConnectorProvider.NAMECHEAP:
return <Typography.Link target='_blank' href="">
{t`Retreive an API key and whitelist this instance's IP address on Namecheap's website`}
</Typography.Link>
default:
return <></>

View File

@@ -21,6 +21,7 @@ services:
bind:
$mailerSenderEmail: '%mailer_sender_email%'
$mailerSenderName: '%mailer_sender_name%'
$outgoingIp: '%env(string:OUTGOING_IP)%'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name

View File

@@ -11,20 +11,20 @@ class NamecheapConnector extends AbstractConnector
public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response';
public function __construct(private HttpClientInterface $client)
public function __construct(private HttpClientInterface $client, private string $outgoingIp)
{
}
public function orderDomain(Domain $domain, $dryRun): void
{
$addresses = $this->call('namecheap.users.address.getList');
$addresses = $this->call('namecheap.users.address.getList', [], $dryRun);
if (count($addresses) < 1) {
throw new \Exception('Namecheap account requires at least one address to purchase a domain');
}
$addressId = $addresses->{0}->AddressId;
$address = $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId]);
$address = $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId], $dryRun);
$domainAddresses = [];
@@ -38,30 +38,26 @@ class NamecheapConnector extends AbstractConnector
'Years' => 1,
'AddFreeWhoisguard' => 'yes',
'WGEnabled' => 'yes',
], $domainAddresses));
], $domainAddresses), $dryRun);
}
private static function mergePrefixKeys(string $prefix, array|object $src, array &$dest)
{
foreach ($src as $key => $value) {
$dest[$prefix.$key] = $value;
$dest[$prefix . $key] = $value;
}
}
private function call(string $command, array $parameters = [], ?array $authData = null): object
private function call(string $command, array $parameters = [], bool $dryRun = true): object
{
if (is_null($authData)) {
$authData = $this->authData;
}
$actualParams = array_merge([
'Command' => $command,
'ApiUser' => $authData['ApiUser'],
'ApiKey' => $authData['ApiKey'],
'ClientIp' => '', // TODO DW instance IP envvar
'ApiUser' => $this->authData['ApiUser'],
'ApiKey' => $this->authData['ApiKey'],
'ClientIp' => $this->outgoingIp,
], $parameters);
$response = $this->client->request('POST', self::BASE_URL, [
$response = $this->client->request('POST', $dryRun ? self::SANDBOX_BASE_URL : self::BASE_URL, [
'query' => $actualParams,
]);