mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Change param to accept only array
This commit is contained in:
@@ -18,13 +18,13 @@ class DNS extends BaseDNS
|
||||
* @param int $type Type of DNS record to validate
|
||||
* For value, use const from Record, such as Record::TYPE_A
|
||||
* When using CAA type, you can provide exact match, or just issuer domain as $target
|
||||
* @param string|array<string> $dnsServers DNS server IP(s) or domain(s) to use for validation
|
||||
* @param array<string> $dnsServers DNS server IP(s) or domain(s) to use for validation
|
||||
*/
|
||||
public function __construct(string $target, int $type = Record::TYPE_CNAME, string|array $dnsServers = self::DEFAULT_DNS_SERVER)
|
||||
public function __construct(string $target, int $type = Record::TYPE_CNAME, array $dnsServers = [])
|
||||
{
|
||||
parent::__construct($target, $type, is_array($dnsServers) ? $dnsServers[0] : $dnsServers);
|
||||
parent::__construct($target, $type, $dnsServers[0] ?? self::DEFAULT_DNS_SERVER);
|
||||
|
||||
$this->dnsServers = is_array($dnsServers) ? $dnsServers : [$dnsServers];
|
||||
$this->dnsServers = $dnsServers;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,10 +35,6 @@ class DNS extends BaseDNS
|
||||
*/
|
||||
public function isValid(mixed $value): bool
|
||||
{
|
||||
if (\count($this->dnsServers) === 1) {
|
||||
return $this->isValidWithDNSServer($value, $this->dnsServers[0]);
|
||||
}
|
||||
|
||||
$wg = new WaitGroup();
|
||||
$failedValidator = null;
|
||||
|
||||
@@ -71,24 +67,4 @@ class DNS extends BaseDNS
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate with a specific DNS server
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $dnsServer
|
||||
* @return bool
|
||||
*/
|
||||
protected function isValidWithDNSServer(mixed $value, string $dnsServer): bool
|
||||
{
|
||||
$validator = new BaseDNS($this->target, $this->type, $dnsServer);
|
||||
$result = $validator->isValid($value);
|
||||
|
||||
$this->count = $validator->count;
|
||||
$this->value = $validator->value;
|
||||
$this->reason = $validator->reason;
|
||||
$this->records = $validator->records;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,18 +19,6 @@ class Action extends PlatformAction
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse DNS servers from environment variable
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
protected function getDNSServers(): array
|
||||
{
|
||||
$dnsEnv = System::getEnv('_APP_DNS', '8.8.8.8');
|
||||
$servers = \array_map('trim', \explode(',', $dnsEnv));
|
||||
return \array_filter($servers, fn ($server) => !empty($server));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify or re-verify a rule
|
||||
*
|
||||
@@ -43,7 +31,9 @@ class Action extends PlatformAction
|
||||
public function verifyRule(Document $rule, ?Log $log = null, ?string $verificationDomainAPI = null, ?string $verificationDomainFunction = null): void
|
||||
{
|
||||
$dnsValidatorClass = $this->dnsValidatorClass;
|
||||
$dnsServers = $this->getDNSServers();
|
||||
$dnsEnv = System::getEnv('_APP_DNS', '8.8.8.8');
|
||||
$servers = \array_map('trim', \explode(',', $dnsEnv));
|
||||
$dnsServers = \array_filter($servers, fn ($server) => !empty($server));
|
||||
|
||||
$domain = new Domain($rule->getAttribute('domain', ''));
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class DNSTest extends TestCase
|
||||
{
|
||||
public function testSingleDNSServer(): void
|
||||
{
|
||||
$validator = new DNS('appwrite.io', Record::TYPE_CNAME, '8.8.8.8');
|
||||
$validator = new DNS('appwrite.io', Record::TYPE_CNAME, ['8.8.8.8']);
|
||||
|
||||
$this->assertEquals(false, $validator->isValid(''));
|
||||
$this->assertEquals(false, $validator->isValid(null));
|
||||
|
||||
Reference in New Issue
Block a user