|
|
@@ -0,0 +1,72 @@
|
|
|
+let { appKey, appSecret, consumerKey } = require('./credentials.json');
|
|
|
+const fs = require('fs');
|
|
|
+const ovh = require('ovh')({
|
|
|
+ endpoint: 'ovh-eu',
|
|
|
+ appKey,
|
|
|
+ appSecret,
|
|
|
+ consumerKey
|
|
|
+});
|
|
|
+
|
|
|
+function requestConsumerKey() {
|
|
|
+ return ovh.requestPromised('POST', '/auth/credential', {
|
|
|
+ 'accessRules': [
|
|
|
+ { 'method': 'GET', 'path': '/me'},
|
|
|
+ { 'method': 'GET', 'path': '/domain/zone'},
|
|
|
+ // { 'method': 'POST', 'path': '/domain/*'},
|
|
|
+ // { 'method': 'PUT', 'path': '/domain/*'},
|
|
|
+ // { 'method': 'DELETE', 'path': '/domain/*'}
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ .then(function (credentials) {
|
|
|
+ console.log('requestConsumerKey', credentials);
|
|
|
+ consumerKey = credentials.consumerKey;
|
|
|
+ fs.writeFileSync('credentials.json', JSON.stringify({
|
|
|
+ appKey, appSecret, consumerKey
|
|
|
+ }));
|
|
|
+ })
|
|
|
+ .catch(function (err) {
|
|
|
+ console.log('requestConsumerKey err', err);
|
|
|
+ //Return an error object like this {error: statusCode, message: message}
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function readDomains() {
|
|
|
+ console.log('readDomains');
|
|
|
+ return ovh.requestPromised('GET', '/domain/zone')
|
|
|
+ .then(response => {
|
|
|
+ console.log(response)
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.log(err);
|
|
|
+ })
|
|
|
+}
|
|
|
+function readMe() {
|
|
|
+ console.log('readMe');
|
|
|
+ return ovh.requestPromised('GET', '/me')
|
|
|
+ .then(response => {
|
|
|
+ console.log(response)
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.log(err);
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+if(consumerKey) {
|
|
|
+ readMe();
|
|
|
+ readDomains();
|
|
|
+ // readCurrentConsumerKey();
|
|
|
+}
|
|
|
+else {
|
|
|
+ requestConsumerKey();
|
|
|
+}
|
|
|
+
|
|
|
+function readCurrentConsumerKey(){
|
|
|
+ console.log('readCurrentConsumerKey');
|
|
|
+ return ovh.requestPromised('GET', '/auth/currentCredential')
|
|
|
+ .then(response => {
|
|
|
+ console.log(response)
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.log(err);
|
|
|
+ })
|
|
|
+}
|