PowerdnsClient

powerdns-api. PowerdnsClient

Class representing the powerdns client

Constructor

new PowerdnsClient(baseurl, apikey)

Source:
Create a powerdns client.
Example
(async () => {
    require('dotenv').config();

    const {
        PowerdnsClient
    } = require('@firstdorsal/powerdns-api');

    const pdns = new PowerdnsClient(process.env.PDNS_API_ENDPOINT, process.env.PDNS_API_KEY);

    console.log(await pdns.getZone('example.com'));
})();
Parameters:
Name Type Description
baseurl string The base url where the api can be found
apikey string The api key for the powerdns endpoint

Methods

(async) appendRecord(record) → {boolean}

Source:
Takes ONE record as object and appends it not replacing other records with the same name.
Example
await pdns.appendRecord({
           name: "example.com",
           type: "A",
           ttl: 300,
           content: ['1.1.1.1','2.2.2.2']
       });
Parameters:
Name Type Description
record Record array containing the records to be appended
Returns:
boolean indicating the success of the operation
Type
boolean

(async) createAndSetupZone(zone) → {Boolean}

Source:
Higher level function for creating a zone with a custom soa record, name servers and dnssec/cryptokey. Skips creating zone and/or cryptokey if it exists.
Example
await pdns.createAndSetupZone({
             domain: 'example.com',
             nameserver: ['ns1.paulisttoll.somedomain', 'ns2.paulisttoll.somedomain', 'ns3.paulisttoll.somedomain'],
             hostmasterEmail:'hostmaster@paulisttoll.somedomain',
        
    })
Parameters:
Name Type Description
zone Object string to search for
Returns:
true on success
Type
Boolean

(async) createCryptokey(zoneName, cryptokeyopt, returnPrivateKeyopt) → {Object}

Source:
Creates a DNS Cryptokey and enables it for DNSSEC. If you want to import your own please read the original documentation and put it in the Cryptokey parameter.
Example
await pdns.createCryptokey("example.com");
Parameters:
Name Type Attributes Default Description
zoneName string name of the zone/domain
cryptokey Cryptokey <optional>
{keytype: "ksk", active: true} a Cryptokey
returnPrivateKey boolean <optional>
false setting to true returns the private key with the answer
Returns:
on success the public key and info will be returned
Type
Object

(async) createZone(zoneName, kindopt) → {Object}

Source:
Creates zone/domain and returns its SOA record on success.
Example
await pdns.createZone('example.com');
Parameters:
Name Type Attributes Default Description
zoneName string takes a domain name
kind 'Native' | 'Master' | 'Slave' <optional>
Native takes the kind of zone you want
Returns:
just the rrsets of the zone
Type
Object

(async) deleteCryptoKey(zoneName, cryptokeyId) → {boolean}

Source:
Delete a cryptokey with specified id from specified zone.
Example
await pdns.deleteCryptoKey("example.com",171);
Parameters:
Name Type Description
zoneName string name of the zone/domain
cryptokeyId string id of the cryptokey
Returns:
true on success
Type
boolean

(async) deleteRecords(records) → {boolean}

Source:
Takes records as array and deletes them.
Example
await pdns.deleteRecords([{
           name: "example.com",
           type: "A"
       }]);
Parameters:
Name Type Description
records Records array containing the records to be deleted
Returns:
boolean indicating the success of the operation
Type
boolean

(async) deleteZone(zoneName) → {boolean}

Source:
Deletes the whole zone with all attached metadata and rrsets.
Example
await pdns.deleteZone('example.com');
Parameters:
Name Type Description
zoneName string takes a domain name
Returns:
true on success
Type
boolean

(async) findRecords(find, zone) → {Array}

Source:
Searches for records in a zone by comparing the RECORDS field NOT the name field
Example
await pdns.findRecords('1.1.1.1', 'example.com');
Parameters:
Name Type Description
find String string to search for
zone String zone to search through
Returns:
records matching the find string in the content field
Type
Array

(async) findRecordsGlobal(find) → {Array}

Source:
Searches for records on the pdns server by comparing the RECORDS field NOT the name field
Example
await pdns.findRecordsGlobal('1.1.1.1');
Parameters:
Name Type Description
find String string to search for
Returns:
records matching the find string in the content field
Type
Array

(async) getCryptoKeys(zoneName) → {Array.<Cryptokey>}

Source:
Get the crypotkeys for a given zone.
Example
await pdns.getCryptoKeys("example.com");
Parameters:
Name Type Description
zoneName string name of the zone/domain
Returns:
on success the cryptokeys of the zone will be returned
Type
Array.<Cryptokey>

(async) getZone(zoneName) → {object}

Source:
Returns array with rrsets for zone.
Example
await pdns.getZone('example.com');
Parameters:
Name Type Description
zoneName string takes a domain name
Returns:
just the rrsets of the zone
Type
object

(async) getZones() → {Array}

Source:
Returns array of all zones from this pdns server.
Example
await pdns.getZones();
Returns:
array of zones
Type
Array

(async) getZoneWithMeta(zoneName) → {object}

Source:
Returns single zone with meta information.
Example
await pdns.getZoneWithMeta('example.com');
Parameters:
Name Type Description
zoneName string takes a domain name
Returns:
the zone with meta information
Type
object

(async) replaceRecords(find, replace, zone) → {Number}

Source:
Searches for records in a zone by comparing the RECORDS field NOT the name field. Replaces the found records with the replace string.
Example
await pdns.replaceRecords('1.1.1.1','2.2.2.2','example.com');
Parameters:
Name Type Description
find String string to search for
replace String string to replace the find string with
zone String zone to search through
Returns:
number of replaced entries
Type
Number

(async) replaceRecordsGlobal(find, replace) → {Number}

Source:
Searches for records on the pdns server by comparing the RECORDS field NOT the name field. Replaces the found records with the replace string.
Example
await pdns.replaceRecordsGlobal('1.1.1.1','2.2.2.2');
Parameters:
Name Type Description
find String string to search for
replace String string to replace the find string with
Returns:
number of replaced entries
Type
Number
Source:
Takes Search object and searches for matching elements in the pdns server.
Example
await pdns.search({
           query: 'example.com',
           max: 100,
           object_type: "zone"
       });
Parameters:
Name Type Description
search Search object with the query paramters
Returns:
search results
Type
object

(async) setHomogeneousRecords(records, domainopt) → {boolean}

Source:
Takes records for a SINGLE domain as array and sets them. If records exist it replaces them.
Example
await pdns.setHomogeneousRecords([{
           name: "example.com",
           type: "A",
           ttl: 300,
           content: ['1.1.1.1']
       }]);
Parameters:
Name Type Attributes Description
records Records array containing the records
domain string <optional>
optional domain name
Returns:
boolean indicating the success of the operation
Type
boolean

(async) setRecords(records) → {Array}

Source:
Takes records for single or mixed domains as array and sets them. If records exist it replaces them.
Example
await pdns.setRecords([{
           name: "example.com",
           type: "A",
           ttl: 300,
           content: ['1.1.1.1']
       },{
           name: "example.org",
           type: "A",
           ttl: 300,
           content: ['1.1.1.1']
       },{
           name: "example.me",
           type: "A",
           ttl: 300,
           content: ['1.1.1.1','2.2.2.2.']
       }]);
Parameters:
Name Type Description
records Records array containing the records
Returns:
array of booleans indicating the success of each entry
Type
Array