|
@@ -1,5 +1,7 @@
|
|
|
let { appKey, appSecret, consumerKey } = require('./credentials.json');
|
|
let { appKey, appSecret, consumerKey } = require('./credentials.json');
|
|
|
const fs = require('fs');
|
|
const fs = require('fs');
|
|
|
|
|
+const Promise = require('bluebird');
|
|
|
|
|
+const _ = require('lodash');
|
|
|
const ovh = require('ovh')({
|
|
const ovh = require('ovh')({
|
|
|
endpoint: 'ovh-eu',
|
|
endpoint: 'ovh-eu',
|
|
|
appKey,
|
|
appKey,
|
|
@@ -12,7 +14,11 @@ function requestConsumerKey() {
|
|
|
'accessRules': [
|
|
'accessRules': [
|
|
|
{ 'method': 'GET', 'path': '/me'},
|
|
{ 'method': 'GET', 'path': '/me'},
|
|
|
{ 'method': 'GET', 'path': '/domain/zone'},
|
|
{ 'method': 'GET', 'path': '/domain/zone'},
|
|
|
- // { 'method': 'POST', 'path': '/domain/*'},
|
|
|
|
|
|
|
+ { 'method': 'GET', 'path': '/domain/zone/*'},
|
|
|
|
|
+ { 'method': 'GET', 'path': '/domain/zone/*/record'},
|
|
|
|
|
+ { 'method': 'GET', 'path': '/domain/zone/*/record/*'},
|
|
|
|
|
+ { 'method': 'POST', 'path': '/domain/zone/*/record'},
|
|
|
|
|
+ { 'method': 'POST', 'path': '/domain/zone/*/refresh'},
|
|
|
// { 'method': 'PUT', 'path': '/domain/*'},
|
|
// { 'method': 'PUT', 'path': '/domain/*'},
|
|
|
// { 'method': 'DELETE', 'path': '/domain/*'}
|
|
// { 'method': 'DELETE', 'path': '/domain/*'}
|
|
|
]
|
|
]
|
|
@@ -34,12 +40,34 @@ function readDomains() {
|
|
|
console.log('readDomains');
|
|
console.log('readDomains');
|
|
|
return ovh.requestPromised('GET', '/domain/zone')
|
|
return ovh.requestPromised('GET', '/domain/zone')
|
|
|
.then(response => {
|
|
.then(response => {
|
|
|
- console.log(response)
|
|
|
|
|
|
|
+ console.log(response, typeof response, Object.prototype.toString.call(Object.values(response)) );
|
|
|
|
|
+ return Object.values(response);
|
|
|
})
|
|
})
|
|
|
.catch(err => {
|
|
.catch(err => {
|
|
|
- console.log(err);
|
|
|
|
|
|
|
+ console.log('readDomains ERR', err);
|
|
|
|
|
+ throw err;
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function readRecords(domain) {
|
|
|
|
|
+ console.log('readRecords');
|
|
|
|
|
+ return ovh.requestPromised('GET', '/domain/zone/' + domain + '/record')
|
|
|
|
|
+ .then(response => {
|
|
|
|
|
+ return Object.values(response);
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(recordIds => Promise.map(recordIds,
|
|
|
|
|
+ recordId => ovh.requestPromised('GET', '/domain/zone/' + domain + '/record/' + recordId)
|
|
|
|
|
+ ))
|
|
|
|
|
+ .then(response => {
|
|
|
|
|
+ return Object.values(response);
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(err => {
|
|
|
|
|
+ console.log('readRecords ERR', err);
|
|
|
|
|
+ throw err;
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
function readMe() {
|
|
function readMe() {
|
|
|
console.log('readMe');
|
|
console.log('readMe');
|
|
|
return ovh.requestPromised('GET', '/me')
|
|
return ovh.requestPromised('GET', '/me')
|
|
@@ -51,9 +79,32 @@ function readMe() {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function passLog(label) {
|
|
|
|
|
+ return obj => {
|
|
|
|
|
+ console.log(label, obj);
|
|
|
|
|
+ return obj;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
if(consumerKey) {
|
|
if(consumerKey) {
|
|
|
- readMe();
|
|
|
|
|
- readDomains();
|
|
|
|
|
|
|
+ let domains;
|
|
|
|
|
+ readDomains()
|
|
|
|
|
+ .then(passLog('domains'))
|
|
|
|
|
+ .then(_domains => {
|
|
|
|
|
+ domains = _domains;
|
|
|
|
|
+ return Promise.map(_domains, domain => readRecords(domain));
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(passLog('subdomains'))
|
|
|
|
|
+ .then(results => {
|
|
|
|
|
+ // console.log('## results for all domains', results);
|
|
|
|
|
+ results.forEach((recordsForDomain, index) => {
|
|
|
|
|
+ const domain = domains[index];
|
|
|
|
|
+ console.log('### DOMAIN: ' + domain);
|
|
|
|
|
+ const filtered = recordsForDomain.filter(r => (r.fieldType === 'A' || (r.fieldType === 'CNAME' && r.target === domain + '.')));
|
|
|
|
|
+ const lines = filtered.map(r => (r.subDomain + ' => ' + r.fieldType));
|
|
|
|
|
+ console.log(lines.join('\n'));
|
|
|
|
|
+ })
|
|
|
|
|
+ });
|
|
|
// readCurrentConsumerKey();
|
|
// readCurrentConsumerKey();
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|