-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from exonet/tsi/EXO-4327
Create zone from resource
- Loading branch information
Showing
8 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
require __DIR__.'/../vendor/autoload.php'; | ||
require __DIR__.'/CliLogger.php'; | ||
|
||
/* | ||
* This example will create a new domain and adds some default DNS records. | ||
*/ | ||
|
||
use Exonet\Powerdns\Powerdns; | ||
use Exonet\Powerdns\Resources\Record; | ||
|
||
$domain = 'dns-new-zone-test.nl'; | ||
|
||
// Update the key to the real PowerDNS API Key. | ||
$powerdns = new Powerdns('127.0.0.1', 'very_secret_secret'); | ||
|
||
// Uncomment this line to see what happens when executing this example on the command line. | ||
// $powerdns->setLogger(new CliLogger()); | ||
|
||
echo PHP_EOL; | ||
|
||
// Get all the resource records for the specified zone/domain. | ||
$zoneResourceSets = $powerdns->zone($domain)->get(); | ||
|
||
// Loop through all found resource records. | ||
foreach ($zoneResourceSets as $resourceSet) { | ||
/* | ||
* A resource set can contain multiple records. By mapping them it is possible | ||
* to extract only the content, which is the only necessary information for this example. | ||
*/ | ||
$recordContents = array_map(function (Record $record) { | ||
return $record->getContent(); | ||
}, $resourceSet->getRecords()); | ||
|
||
// Show for each resource set in the zone the type, name and values. | ||
echo sprintf( | ||
'| %-4s | %30s --> %-30s%s', | ||
$resourceSet->getType(), | ||
$resourceSet->getName(), | ||
implode(', ', $recordContents), | ||
PHP_EOL | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
require __DIR__.'/../vendor/autoload.php'; | ||
require __DIR__.'/CliLogger.php'; | ||
|
||
/* | ||
* This example will create a new domain based on a zone resource object with some more 'advanced' | ||
* settings and adds some default DNS records. | ||
*/ | ||
|
||
use Exonet\Powerdns\Powerdns; | ||
use Exonet\Powerdns\RecordType; | ||
use Exonet\Powerdns\Resources\Zone as ZoneResource; | ||
|
||
$canonicalDomain = 'dns-new-zone-resource-test.nl.'; | ||
$nameServers = ['ns1.example.com.', 'ns2.example.eu.']; | ||
$dnsRecords = [ | ||
['name' => '@', 'type' => RecordType::A, 'content' => '127.0.0.1', 'ttl' => 60], | ||
['name' => 'www', 'type' => RecordType::A, 'content' => '127.0.0.1', 'ttl' => 60], | ||
|
||
['name' => '@', 'type' => RecordType::AAAA, 'content' => '2a00:1e28:3:1629::1', 'ttl' => 60], | ||
['name' => 'www', 'type' => RecordType::AAAA, 'content' => '2a00:1e28:3:1629::1', 'ttl' => 60], | ||
]; | ||
|
||
// Update the key to the real PowerDNS API Key. | ||
$powerdns = new Powerdns('127.0.0.1', 'very_secret_secret'); | ||
|
||
// Uncomment this line to see what happens when executing this example on the command line. | ||
// $powerdns->setLogger(new CliLogger()); | ||
|
||
// Uncomment this line if you want to run this example multiple times. | ||
// $powerdns->deleteZone($canonicalDomain); | ||
|
||
// Create a new zone resource. | ||
$newZone = new ZoneResource(); | ||
$newZone->setName($canonicalDomain); | ||
$newZone->setKind('native'); | ||
$newZone->setDnssec(true); | ||
$newZone->setSoaEdit('epoch'); | ||
$newZone->setSoaEditApi('epoch'); | ||
// $newZone->setMasters([...]); | ||
$newZone->setNameservers($nameServers); | ||
$newZone->setApiRectify(false); | ||
$newZone->setNsec3param('1 0 100 1234567890'); | ||
|
||
// Create a new zone with the defined records and name servers. | ||
$powerdns->createZoneFromResource($newZone)->create($dnsRecords); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Exonet\Powerdns\tests\functional; | ||
|
||
use Exonet\Powerdns\Powerdns; | ||
use Exonet\Powerdns\Resources\Zone as ZoneResource; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AdvancedZoneCreationTest extends TestCase | ||
{ | ||
public function testCreateSoaIncrementZone(): void | ||
{ | ||
$powerdns = new Powerdns('127.0.0.1', 'apiKey'); | ||
// Create a unique zone/domain name. | ||
$canonicalDomain = 'advanced-zone.'.time().'.test.'; | ||
|
||
// Create a new zone resource. | ||
$newZone = new ZoneResource(); | ||
$newZone->setName($canonicalDomain); | ||
$newZone->setKind('native'); | ||
$newZone->setDnssec(true); | ||
$newZone->setSoaEdit('epoch'); | ||
$newZone->setSoaEditApi('epoch'); | ||
$newZone->setNameservers(['ns1.test.']); | ||
$newZone->setApiRectify(false); | ||
$newZone->setNsec3param('1 0 100 1234567890'); | ||
|
||
// Create a new zone with the defined records and name servers. | ||
$powerdns->createZoneFromResource($newZone); | ||
|
||
// Get the zone and check the results. | ||
$zone = $powerdns->zone($canonicalDomain); | ||
$zoneResource = $zone->resource(); | ||
$this->assertSame($canonicalDomain, $zone->getCanonicalName()); | ||
$this->assertSame($canonicalDomain, $zoneResource->getName()); | ||
$this->assertSame('Native', $zoneResource->getKind()); | ||
$this->assertTrue($zoneResource->hasDnssec(), 'DNSSEC not correctly set.'); | ||
$this->assertSame('EPOCH', $zoneResource->getSoaEdit()); | ||
$this->assertSame('EPOCH', $zoneResource->getSoaEditApi()); | ||
$this->assertSame(['ns1.test.'], $zoneResource->getNameservers()); | ||
$this->assertFalse($zoneResource->hasAutoRectify(), 'API Rectify not correctly set.'); | ||
$this->assertSame('1 0 100 1234567890', $zoneResource->getNsec3param()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters