@firstdorsal/powerdns-api
Advanced tools
Comparing version 1.3.2 to 1.4.2
203
index.js
@@ -85,5 +85,2 @@ 'use strict'; | ||
} | ||
/** | ||
@@ -99,6 +96,29 @@ * Takes domain name as string. Returns the domain name as string in absolute form with a . at the end. example.com -> example.com. and example.com. -> example.com. | ||
} | ||
/** | ||
* Returns array of all zones on pdns server. | ||
* takes array of records and sorts its contents by name into multiple arrays | ||
* @private | ||
* @param {Array} records array of records | ||
* @returns {Array} array of arrays with records with the same name | ||
* */ | ||
sortRecordsByDomainName(records) { | ||
const result = []; | ||
for (let i = 0; i < records.length; i++) { | ||
let p = false; | ||
for (let j = 0; j < result.length; j++) { | ||
if (records[i].name === result[j][0].name) { | ||
result[j].push(records[i]); | ||
p = true; | ||
break; | ||
} | ||
} | ||
if (!p) result.push([records[i]]); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Returns array of all zones from this pdns server. | ||
* @async | ||
* @returns {Array} array of zones on the server | ||
* @returns {Array} array of zones | ||
* @example | ||
@@ -118,3 +138,2 @@ await pdns.getZones(); | ||
} | ||
/** | ||
@@ -150,4 +169,2 @@ * Creates zone/domain and returns its SOA record on success. | ||
} | ||
/** | ||
@@ -159,3 +176,3 @@ * Returns single zone with meta information. | ||
* @example | ||
await pdns.getZoneWithMeta(); | ||
await pdns.getZoneWithMeta('example.com'); | ||
*/ | ||
@@ -198,5 +215,2 @@ getZoneWithMeta(zoneName) { | ||
} | ||
/** | ||
@@ -225,5 +239,4 @@ * Deletes the whole zone with all attached metadata and rrsets. | ||
} | ||
/** | ||
* Takes records as array and sets them. If records exist it replaces them. | ||
* Takes records for a SINGLE domain as array and sets them. If records exist it replaces them. | ||
* @async | ||
@@ -233,3 +246,3 @@ * @param {Records} records array containing the records | ||
* @example | ||
await pdns.setRecords([{ | ||
await pdns.setHomogeneousRecords([{ | ||
name: "example.com", | ||
@@ -241,4 +254,3 @@ type: "A", | ||
*/ | ||
setRecords(records) { | ||
setHomogeneousRecords(records) { | ||
if (!Array.isArray(records)) throw new TypeError('Parameter must be of type array'); | ||
@@ -286,6 +298,2 @@ | ||
} | ||
/** | ||
@@ -333,3 +341,2 @@ * Takes records as array and deletes them. | ||
} | ||
/** | ||
@@ -391,4 +398,2 @@ * Takes Search object and searches for matching elements in the pdns server. | ||
} | ||
/** | ||
@@ -400,6 +405,5 @@ * Creates a DNS Cryptokey and enables it for DNSSEC. If you want to import your own please read the original [documentation]{@link https://doc.powerdns.com/authoritative/http-api/cryptokey.html} and put it in the Cryptokey parameter. | ||
* @param {boolean} [returnPrivateKey=false] setting to true returns the private key with the answer | ||
* @returns {Object} ob success the public key and info will be returned | ||
* @returns {Object} on success the public key and info will be returned | ||
* @example | ||
await pdns.createCryptokey("example.com"); | ||
*/ | ||
@@ -429,2 +433,149 @@ createCryptokey(zoneName, cryptokey = { | ||
} | ||
/** | ||
* Takes records for single or mixed domains as array and sets them. If records exist it replaces them. | ||
* @async | ||
* @param {Records} records array containing the records | ||
* @returns {boolean} indicating the end of the operation | ||
* @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'] | ||
}]); | ||
*/ | ||
async setRecords(records) { | ||
records = this.sortRecordsByDomainName(records); | ||
let ir = []; | ||
for (let i = 0; i < records.length; i++) { | ||
ir.push(this.setHomogeneousRecords(records[i])) | ||
} | ||
await Promise.all(ir); | ||
return true; | ||
} | ||
/** | ||
* @async | ||
* @param {String} find string to search for | ||
* @param {String} replace string to replace the find string with | ||
* @param {String} zone zone to search through | ||
* @returns {Number} number of replaced entries | ||
* | ||
*/ | ||
async replaceRecords(find, replace, zone) { | ||
const toReplace = []; | ||
const zoneSets = await this.getZone(zone) | ||
if (zoneSets) { | ||
for (let j = 0; j < zoneSets.length; j++) { | ||
const content = []; | ||
let foundOne = false; | ||
for (let k = 0; k < zoneSets[j].records.length; k++) { | ||
if (zoneSets[j].records[k].content === find) { | ||
content.push(replace) | ||
foundOne = true; | ||
} else { | ||
content.push(zoneSets[j].records[k].content); | ||
} | ||
} | ||
if (foundOne) { | ||
toReplace.push({ | ||
name: zoneSets[j].name, | ||
type: zoneSets[j].type, | ||
ttl: zoneSets[j].ttl, | ||
content, | ||
}); | ||
} | ||
} | ||
} | ||
await this.setRecords(toReplace); | ||
return toReplace.length | ||
} | ||
/** | ||
* @async | ||
* @param {String} find string to search for | ||
* @param {String} replace string to replace the find string with | ||
* @returns {Number} number of replaced entries | ||
* | ||
*/ | ||
async replaceRecordsGlobal(find, replace) { | ||
const allZones = await this.getZones(); | ||
const toReplace = []; | ||
for (let i = 0; i < allZones.length; i++) { | ||
const zoneSets = await this.getZone(allZones[i].name) | ||
if (zoneSets) { | ||
for (let j = 0; j < zoneSets.length; j++) { | ||
const content = []; | ||
let foundOne = false; | ||
for (let k = 0; k < zoneSets[j].records.length; k++) { | ||
if (zoneSets[j].records[k].content === find) { | ||
content.push(replace) | ||
foundOne = true; | ||
} else { | ||
content.push(zoneSets[j].records[k].content); | ||
} | ||
} | ||
if (foundOne) { | ||
toReplace.push({ | ||
name: zoneSets[j].name, | ||
type: zoneSets[j].type, | ||
ttl: zoneSets[j].ttl, | ||
content, | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
await this.setRecords(toReplace); | ||
return toReplace.length | ||
} | ||
/** | ||
* search for records in a zone | ||
* @async | ||
* @param {String} find string to search for | ||
* @param {String} zone zone to search through | ||
* @returns {Array} records matching the find string in the content field | ||
* | ||
*/ | ||
async findRecords(find, zone) { | ||
const res = []; | ||
const zoneSets = await this.getZone(zone) | ||
if (zoneSets) { | ||
for (let j = 0; j < zoneSets.length; j++) { | ||
for (let k = 0; k < zoneSets[j].records.length; k++) { | ||
if (zoneSets[j].records[k].content === find) { | ||
res.push(zoneSets[j]); | ||
} | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
/** | ||
* search for records globally on the pdns server | ||
* @async | ||
* @param {String} find string to search for | ||
* @returns {Array} records matching the find string in the content field | ||
* | ||
*/ | ||
async findRecordsGlobal(find) { | ||
const allZones = await this.getZones(); | ||
const res = []; | ||
for (let i = 0; i < allZones.length; i++) { | ||
const zoneSets = await this.getZone(allZones[i].name) | ||
if (zoneSets) { | ||
for (let j = 0; j < zoneSets.length; j++) { | ||
for (let k = 0; k < zoneSets[j].records.length; k++) { | ||
if (zoneSets[j].records[k].content === find) { | ||
res.push(zoneSets[j]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
} |
{ | ||
"name": "@firstdorsal/powerdns-api", | ||
"version": "1.3.2", | ||
"description": "Nodejs wrapper for the most relevant powerdns api features.", | ||
"version": "1.4.2", | ||
"description": "Nodejs PowerDNS API.", | ||
"main": "index.js", | ||
@@ -13,2 +13,5 @@ "author": "Paul Colin Hennig", | ||
}, | ||
"scripts": { | ||
"makedoc": "./generateDoc.sh" | ||
}, | ||
"repository": { | ||
@@ -30,4 +33,7 @@ "type": "git", | ||
"devDependencies": { | ||
"eslint": "^7.7.0" | ||
"dotenv": "^8.2.0", | ||
"eslint": "^7.7.0", | ||
"jsdoc": "^3.6.5", | ||
"jsdoc-to-markdown": "^6.0.1" | ||
} | ||
} |
@@ -60,2 +60,3 @@ # Install | ||
[Code on Gitlab](https://git.firstdorsal.eu/firstdorsal/powerdns-api) | ||
[Code on Gitlab](https://git.firstdorsal.eu/firstdorsal/powerdns-api) | ||
104
README.md
@@ -94,3 +94,3 @@ # Install | ||
* [.deleteZone(zoneName)](#module_powerdns-api.PowerdnsClient+deleteZone) ⇒ <code>boolean</code> | ||
* [.setRecords(records)](#module_powerdns-api.PowerdnsClient+setRecords) ⇒ <code>boolean</code> | ||
* [.setHomogeneousRecords(records)](#module_powerdns-api.PowerdnsClient+setHomogeneousRecords) ⇒ <code>boolean</code> | ||
* [.deleteRecords(records)](#module_powerdns-api.PowerdnsClient+deleteRecords) ⇒ <code>boolean</code> | ||
@@ -100,2 +100,7 @@ * [.search(search)](#module_powerdns-api.PowerdnsClient+search) ⇒ <code>object</code> | ||
* [.createCryptokey(zoneName, [cryptokey], [returnPrivateKey])](#module_powerdns-api.PowerdnsClient+createCryptokey) ⇒ <code>Object</code> | ||
* [.setRecords(records)](#module_powerdns-api.PowerdnsClient+setRecords) ⇒ <code>boolean</code> | ||
* [.replaceRecords(find, replace, zone)](#module_powerdns-api.PowerdnsClient+replaceRecords) ⇒ <code>Number</code> | ||
* [.replaceRecordsGlobal(find, replace)](#module_powerdns-api.PowerdnsClient+replaceRecordsGlobal) ⇒ <code>Number</code> | ||
* [.findRecords(find, zone)](#module_powerdns-api.PowerdnsClient+findRecords) ⇒ <code>Array</code> | ||
* [.findRecordsGlobal(find)](#module_powerdns-api.PowerdnsClient+findRecordsGlobal) ⇒ <code>Array</code> | ||
@@ -116,3 +121,3 @@ <a name="module_powerdns-api.PowerdnsClient"></a> | ||
* [.deleteZone(zoneName)](#module_powerdns-api.PowerdnsClient+deleteZone) ⇒ <code>boolean</code> | ||
* [.setRecords(records)](#module_powerdns-api.PowerdnsClient+setRecords) ⇒ <code>boolean</code> | ||
* [.setHomogeneousRecords(records)](#module_powerdns-api.PowerdnsClient+setHomogeneousRecords) ⇒ <code>boolean</code> | ||
* [.deleteRecords(records)](#module_powerdns-api.PowerdnsClient+deleteRecords) ⇒ <code>boolean</code> | ||
@@ -122,2 +127,7 @@ * [.search(search)](#module_powerdns-api.PowerdnsClient+search) ⇒ <code>object</code> | ||
* [.createCryptokey(zoneName, [cryptokey], [returnPrivateKey])](#module_powerdns-api.PowerdnsClient+createCryptokey) ⇒ <code>Object</code> | ||
* [.setRecords(records)](#module_powerdns-api.PowerdnsClient+setRecords) ⇒ <code>boolean</code> | ||
* [.replaceRecords(find, replace, zone)](#module_powerdns-api.PowerdnsClient+replaceRecords) ⇒ <code>Number</code> | ||
* [.replaceRecordsGlobal(find, replace)](#module_powerdns-api.PowerdnsClient+replaceRecordsGlobal) ⇒ <code>Number</code> | ||
* [.findRecords(find, zone)](#module_powerdns-api.PowerdnsClient+findRecords) ⇒ <code>Array</code> | ||
* [.findRecordsGlobal(find)](#module_powerdns-api.PowerdnsClient+findRecordsGlobal) ⇒ <code>Array</code> | ||
@@ -152,6 +162,6 @@ <a name="new_module_powerdns-api.PowerdnsClient_new"></a> | ||
#### powerdnsClient.getZones() ⇒ <code>Array</code> | ||
Returns array of all zones on pdns server. | ||
Returns array of all zones from this pdns server. | ||
**Kind**: instance method of [<code>PowerdnsClient</code>](#module_powerdns-api.PowerdnsClient) | ||
**Returns**: <code>Array</code> - array of zones on the server | ||
**Returns**: <code>Array</code> - array of zones | ||
**Example** | ||
@@ -192,3 +202,3 @@ ```js | ||
```js | ||
await pdns.getZoneWithMeta(); | ||
await pdns.getZoneWithMeta('example.com'); | ||
``` | ||
@@ -227,6 +237,6 @@ <a name="module_powerdns-api.PowerdnsClient+getZone"></a> | ||
``` | ||
<a name="module_powerdns-api.PowerdnsClient+setRecords"></a> | ||
<a name="module_powerdns-api.PowerdnsClient+setHomogeneousRecords"></a> | ||
#### powerdnsClient.setRecords(records) ⇒ <code>boolean</code> | ||
Takes records as array and sets them. If records exist it replaces them. | ||
#### powerdnsClient.setHomogeneousRecords(records) ⇒ <code>boolean</code> | ||
Takes records for a SINGLE domain as array and sets them. If records exist it replaces them. | ||
@@ -242,3 +252,3 @@ **Kind**: instance method of [<code>PowerdnsClient</code>](#module_powerdns-api.PowerdnsClient) | ||
```js | ||
await pdns.setRecords([{ | ||
await pdns.setHomogeneousRecords([{ | ||
name: "example.com", | ||
@@ -316,3 +326,3 @@ type: "A", | ||
**Kind**: instance method of [<code>PowerdnsClient</code>](#module_powerdns-api.PowerdnsClient) | ||
**Returns**: <code>Object</code> - ob success the public key and info will be returned | ||
**Returns**: <code>Object</code> - on success the public key and info will be returned | ||
@@ -329,2 +339,76 @@ | Param | Type | Default | Description | | ||
``` | ||
<a name="module_powerdns-api.PowerdnsClient+setRecords"></a> | ||
#### powerdnsClient.setRecords(records) ⇒ <code>boolean</code> | ||
Takes records for single or mixed domains as array and sets them. If records exist it replaces them. | ||
**Kind**: instance method of [<code>PowerdnsClient</code>](#module_powerdns-api.PowerdnsClient) | ||
**Returns**: <code>boolean</code> - indicating the end of the operation | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| records | [<code>Records</code>](#Records) | array containing the records | | ||
**Example** | ||
```js | ||
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'] | ||
}]); | ||
``` | ||
<a name="module_powerdns-api.PowerdnsClient+replaceRecords"></a> | ||
#### powerdnsClient.replaceRecords(find, replace, zone) ⇒ <code>Number</code> | ||
**Kind**: instance method of [<code>PowerdnsClient</code>](#module_powerdns-api.PowerdnsClient) | ||
**Returns**: <code>Number</code> - number of replaced entries | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| find | <code>String</code> | string to search for | | ||
| replace | <code>String</code> | string to replace the find string with | | ||
| zone | <code>String</code> | zone to search through | | ||
<a name="module_powerdns-api.PowerdnsClient+replaceRecordsGlobal"></a> | ||
#### powerdnsClient.replaceRecordsGlobal(find, replace) ⇒ <code>Number</code> | ||
**Kind**: instance method of [<code>PowerdnsClient</code>](#module_powerdns-api.PowerdnsClient) | ||
**Returns**: <code>Number</code> - number of replaced entries | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| find | <code>String</code> | string to search for | | ||
| replace | <code>String</code> | string to replace the find string with | | ||
<a name="module_powerdns-api.PowerdnsClient+findRecords"></a> | ||
#### powerdnsClient.findRecords(find, zone) ⇒ <code>Array</code> | ||
search for records in a zone | ||
**Kind**: instance method of [<code>PowerdnsClient</code>](#module_powerdns-api.PowerdnsClient) | ||
**Returns**: <code>Array</code> - records matching the find string in the content field | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| find | <code>String</code> | string to search for | | ||
| zone | <code>String</code> | zone to search through | | ||
<a name="module_powerdns-api.PowerdnsClient+findRecordsGlobal"></a> | ||
#### powerdnsClient.findRecordsGlobal(find) ⇒ <code>Array</code> | ||
search for records globally on the pdns server | ||
**Kind**: instance method of [<code>PowerdnsClient</code>](#module_powerdns-api.PowerdnsClient) | ||
**Returns**: <code>Array</code> - records matching the find string in the content field | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| find | <code>String</code> | string to search for | | ||
<a name="Cryptokey"></a> | ||
@@ -331,0 +415,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40198
545
470
4