Skip to content

Commit

Permalink
Add support to List Domains
Browse files Browse the repository at this point in the history
This change helps facilitate bulks actions like managing ACME from a client-side app.

After one calls $powerDns->listZones();
knowing what zone is being returned is extremely helpful.
`$zone->getCanonicalName(): string;`
  • Loading branch information
jackdpeterson committed Oct 8, 2019
1 parent 7c1fdf2 commit fed0eb4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/AbstractZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,12 @@ protected function getZonePath(?string $path = null) : string
{
return sprintf('zones/%s%s', $this->zone, $path);
}

/**
* @return string
*/
public function getCanonicalName(): string
{
return substr($this->zone, 0, strlen($this->zone) - 1);
}
}
13 changes: 13 additions & 0 deletions src/Powerdns.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ public function deleteZone(string $canonicalDomain) : bool
return true;
}

/**
* @return Zone[]
*/
public function listZones() : array
{
return array_map(
function (array $args) {
return new Zone($this->connector, $args['id']);
},
$this->connector->get('zones')
);
}

/**
* Get a cryptokey instance to work with.
*
Expand Down
42 changes: 42 additions & 0 deletions tests/PowerdnsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,46 @@ public function testZone() : void
$this->assertInstanceOf(Zone::class, $zone);
$this->assertTrue($powerDns->deleteZone('test.nl.'));
}

public function testListZones() : void
{
$connector = Mockery::mock(Connector::class);
$connector->shouldReceive('get')->withArgs(['zones'])->once()->andReturn(
[
[
'account' => '',
'dnssec' => false,
'id' => 'example.co.uk',
'kind' => 'Native',
'last_check' => 0,
'masters' => [],
'name' => 'example.',
'notified_serial' => 0,
'serial' => 2019100101,
'url' => '/api/v1/servers/localhost/zones/example.co.uk',
],
[
'account' => '',
'dnssec' => false,
'id' => 'example.com',
'kind' => 'Native',
'last_check' => 0,
'masters' => [],
'name' => 'example.',
'notified_serial' => 0,
'serial' => 2019100102,
'url' => '/api/v1/servers/localhost/zones/example.com',
],
]
);

$powerDns = new Powerdns(null, null, null, null, $connector);

$response = $powerDns->listZones();
$this->assertIsArray($response);
$this->assertCount(2, $response);
foreach ($response as $zone) {
$this->assertInstanceOf(Zone::class, $zone);
}
}
}
7 changes: 7 additions & 0 deletions tests/ZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,11 @@ public function testFindResourceRecords() : void
$this->assertSame(1, $zone->find('record01.test.nl.')->count());
$this->assertSame(0, $zone->find('record01.test.nl.', 'MX')->count());
}

public function testGetCanonicalName(): void
{
$connector = Mockery::mock(Connector::class);
$zone = new Zone($connector, 'test.nl');
$this->assertSame('test.nl', $zone->getCanonicalName());
}
}

0 comments on commit fed0eb4

Please sign in to comment.