This repository has been archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (58 loc) · 1.79 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require('dotenv').config();
const rp = require('request-promise');
/**
* Constant variables
**/
const zone = process.env.ZONE;
const accountId = process.env.ACCOUNT_ID;
const uriEncodedAuth = process.env.URI_ENCODED_AUTH;
const uriToPost = `https://${uriEncodedAuth}@aperture.section.io/api/v1/account/${accountId}/zone/${zone}`;
/**
* variable recordsToPost is in array of objects with keys:
*
* recordName - string
* recordData - array of strings or string
* recordType - string
* ttl - number (default 300)
**/
let recordsToPost = [
{ recordName: 'test.com', recordData: '1.1.1.1', recordType: 'A' },
{ recordName: 'www.test.com', recordData: 'test.abc.com', recordType: 'CNAME' },
{ recordName: 'www.test.com', recordData: 'someTypeofString', recordType: 'TXT' },
];
recordsToPost = require('./records.json');
const count = recordsToPost.length - 1;
let counter = 0;
const main = () => {
if (count < counter) return Promise.resolve();
const record = recordsToPost[counter];
const options = {
method: 'POST',
uri: uriToPost,
body: {
recordName: record.recordName,
recordType: record.recordType,
ttl: record.ttl || 300,
recordData: Array.isArray(record.recordData) ? record.recordData : [record.recordData],
},
json: true,
};
return rp(options)
.then(parsedBody => {
console.log('Counter:', counter);
counter += 1;
return main();
})
.catch(err => {
console.log('Error at counter (record not inputed):', counter);
counter += 1;
return main();
});
}
main()
.then(() => {
console.log('Done!');
})
.catch(err => {
console.log('Something bad happened:', err);
});