Install
npm i @firstdorsal/powerdns-api
Usage
(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'));
})();
What is dotenv?
The line "require('dotenv').config();" gets the contents of a file called ".env" in which you should store your global and secret variables.
1. Install the module "dotenv" with
npm i dotenv
2. Create a file named ".env" in your applications root directory
.env
PDNS_API_KEY='YOUR PDNS API KEY'
PDNS_API_ENDPOINT='https://example.com/api/v1/servers/localhost'
3. Use your secret variables
process.env.PDNS_API_ENDPOINT
process.env.PDNS_API_KEY
Documentation
Documentation
Need help?
Feel free to contact me via xl9jthv_7bvgakv9o9wg0jabn2ylm91xxrzzgt0e@firstdorsal.eu in english or german
Automatic Let's Encrypt certificates via DNS
acme-dns-01-powerdns
Modules
- powerdns-api
Typedefs
- Search :
object
- Records :
Array.<Record>
- Record :
object
powerdns-api
powerdns-api.PowerdnsClient
Class representing the powerdns client
Kind: static class of powerdns-api
new module.exports.PowerdnsClient(baseurl, apikey)
Create a powerdns client.
Param | Type | Description |
---|
baseurl | string | The base url where the api can be found |
apikey | string | The api key for the powerdns endpoint |
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'));
})();
powerdnsClient.getZones() ⇒ Array
Returns array of zones on pdns server.
Kind: instance method of PowerdnsClient
Returns: Array
- array of zones on the server
Example
await pdns.getZones();
powerdnsClient.getZoneWithMeta(zoneName) ⇒ object
Returns single zone with meta information.
Kind: instance method of PowerdnsClient
Returns: object
- the zone with meta information
Param | Type | Description |
---|
zoneName | string | takes a domain name |
Example
await pdns.getZoneWithMeta();
powerdnsClient.getZone(zoneName) ⇒ object
Returns array with rrsets.
Kind: instance method of PowerdnsClient
Returns: object
- just the rrsets of the zone
Param | Type | Description |
---|
zoneName | string | takes a domain name |
Example
await pdns.getZone('example.com');
powerdnsClient.setRecords(records) ⇒ boolean
Takes records as array and sets them. If records exist it replaces them.
Kind: instance method of PowerdnsClient
Returns: boolean
- boolean indicating the success of the operation
Param | Type | Description |
---|
records | Records | array containing the records |
Example
await pdns.setRecords([{
name: "example.com",
type: "A",
ttl: 300,
content: ['1.1.1.1']
}]);
powerdnsClient.deleteRecords(records) ⇒ boolean
Takes records as array and deletes them.
Kind: instance method of PowerdnsClient
Returns: boolean
- boolean indicating the success of the operation
Param | Type | Description |
---|
records | Records | array containing the records to be deleted |
Example
await pdns.deleteRecords([{
name: "example.com",
type: "A"
}]);
powerdnsClient.search(search) ⇒ object
Takes Search object and searches for matching elements in the pdns server.
Kind: instance method of PowerdnsClient
Returns: object
- search results
Param | Type | Description |
---|
search | Search | object with the query paramter |
Example
await pdns.search({
query: 'example.com',
max: 100,
object_type: "zone"
});
powerdnsClient.appendRecord(record) ⇒ boolean
Takes ONE record as object and appends it not replacing other records with the same name.
Kind: instance method of PowerdnsClient
Returns: boolean
- boolean indicating the success of the operation
Param | Type | Description |
---|
record | Record | array containing the records to be deleted |
Example
await pdns.appendRecord({
name: "example.com",
type: "A",
ttl: 300,
content: ['1.1.1.1','2.2.2.2']
});
Search : object
Kind: global typedef
Properties
Name | Type | Default | Description |
---|
query | string | | query to search for |
[max] | number | 10 | limits the ammount of returned values |
[object_type] | string | "record" | for what kind of pdns object to search |
Example
{query: 'example.com', max: 100, object_type: "zone"}
Kind: global typedef
Example
[{
name: "example.com",
type: "A",
ttl: 300,
content: ['1.1.1.1', '8.8.8.8']
}, {
name: "*.example.com",
type: "A",
ttl: 300,
content: ['1.1.1.1', '8.8.8.8']
}]
Record : object
Kind: global typedef
Properties
Name | Type | Description |
---|
name | string | key name of the record |
type | string | type of the record |
ttl | number | time to live of the record |
content | Array | value array with content of the record |
Example
{name: "example.com", type: "A", ttl: 300, content: ['1.1.1.1', '8.8.8.8']}