Skip to content

Commit

Permalink
Merge pull request #153 from bennetgallein/feat/make-nameservers-auto…
Browse files Browse the repository at this point in the history
…-canoncial

feat: make nameservers auto canoncial
  • Loading branch information
trizz authored Sep 9, 2024
2 parents 45eb375 + 0055a27 commit 59dc5d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/Powerdns.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,8 @@ public function useKey(string $key): PowerdnsInterface
*/
public function createZone(string $canonicalDomain, array $nameservers, bool $useDnssec = false): Zone
{
$fixDot = substr($canonicalDomain, -1) !== '.';

if ($fixDot) {
$canonicalDomain .= '.';
}

$canonicalDomain = rtrim($canonicalDomain, ".") . ".";
$newZone = new ZoneResource();
$newZone->setName($canonicalDomain);
$newZone->setNameservers($nameservers);
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/Zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ public function setApiRectify(bool $apiRectify): self
*/
public function setNameservers(array $nameservers): self
{
$this->nameservers = $nameservers;
$this->nameservers = array_map(function($ns) {
return rtrim($ns, '.') . '.';
}, $nameservers);

return $this;
}
Expand Down
7 changes: 3 additions & 4 deletions tests/Resources/ZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ public function testSetApiResponseWithoutOptionalData(): void
$this->assertNull($zone->getAccount());
}

public function testSetNameservers(): void
{
public function testSetNameserversCanoncial(): void {
$zone = new Zone();
$zone->setNameservers(['foo', 'bar']);
$this->assertSame(['foo', 'bar'], $zone->getNameservers());
$zone->setNameservers(['ns1', 'ns2']);
$this->assertSame(['ns1.', 'ns2.'], $zone->getNameservers());
}

public function testSetKind(): void
Expand Down

0 comments on commit 59dc5d6

Please sign in to comment.