This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
698 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"esversion": 9, | ||
"strict": "global", | ||
"mocha": true, | ||
"node": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"use strict"; | ||
const defaultConfig = { | ||
api_key: undefined, | ||
endpoint: "https://dns.api.gandi.net/api/v5", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,61 @@ | ||
"use strict"; | ||
|
||
const request = require('request'); | ||
|
||
const messages = { | ||
"e401": "Gandi Authorization declined, check GANDI_API_KEY", | ||
"e404": "Record doesn't exists, Please create record in zone first (update only)", | ||
"e4xx": "Unknown Error: ", | ||
"error_domain": "Configuration error missing domain or record to manage", | ||
"e401": "Gandi Authorization declined, check GANDI_API_KEY", | ||
"e404": "Record doesn't exists, Please create record in zone first (update only)", | ||
"e4xx": "Unknown Error: ", | ||
"error_domain": "Configuration error missing domain or record to manage", | ||
}; | ||
|
||
module.exports = function(config) { | ||
let callAPI = function(data, func) { | ||
/* | ||
curl -H"X-Api-Key: $APIKEY" \ | ||
https://dns.api.gandi.net/api/v5/domains/example.com/records | ||
*/ | ||
|
||
let method = (func == undefined) ? 'GET': 'PUT'; | ||
let callback = (func == undefined) ? data: func; | ||
if ( typeof callback !== 'function' ) { | ||
throw("Unexpected null callback"); | ||
} | ||
if (config.domain == undefined || config.record == undefined) { | ||
callback(messages.error_domain); | ||
} | ||
let options = { | ||
method: method, | ||
url: config.endpoint + "/domains/" + config.domain + "/records/" + config.record + "/A", | ||
headers: { | ||
'X-Api-Key': config.api_key | ||
}, | ||
json: true | ||
}; | ||
if (method == 'PUT') { | ||
options.body = data; | ||
} | ||
if (config.debug) console.debug(method, options.url); | ||
request(options, function(err, res, body) { | ||
if(res.statusCode == 401) { | ||
callback(messages.e401); | ||
} else if (res.statusCode == 404) { | ||
callback(messages.e404); | ||
} else if (err || res.statusCode > 399) { | ||
callback(messages.e4xx + body.message + "(" + err || res.statusCode + ")" , body); | ||
} else { | ||
callback(false, body); | ||
} | ||
}); | ||
}; | ||
return { | ||
getRecord: function(callback) { | ||
callAPI(callback); | ||
}, | ||
updateRecord: function(data, callback) { | ||
callAPI(data, callback); | ||
} | ||
}; | ||
let callAPI = function(data, func) { | ||
/* | ||
curl -H"X-Api-Key: $APIKEY" \ | ||
https://dns.api.gandi.net/api/v5/domains/example.com/records | ||
*/ | ||
|
||
} | ||
let method = (func == undefined) ? 'GET': 'PUT'; | ||
let callback = (func == undefined) ? data: func; | ||
if ( typeof callback !== 'function' ) { | ||
throw("Unexpected null callback"); | ||
} | ||
if (config.domain == undefined || config.record == undefined) { | ||
callback(messages.error_domain); | ||
} | ||
let options = { | ||
method: method, | ||
url: config.endpoint + "/domains/" + config.domain + "/records/" + config.record + "/A", | ||
headers: { | ||
'X-Api-Key': config.api_key | ||
}, | ||
json: true | ||
}; | ||
if (method == 'PUT') { | ||
options.body = data; | ||
} | ||
if (config.debug) console.debug(method, options.url); | ||
request(options, function(err, res, body) { | ||
if(!res || err) { | ||
callback(messages.e4xx + "(" + err || 'no status' + ")" , body); | ||
} else if (res.statusCode && res.statusCode == 401) { | ||
callback(messages.e401); | ||
} else if (res && res.statusCode && res.statusCode == 404) { | ||
callback(messages.e404); | ||
} else if (res.statusCode > 399) { | ||
callback(messages.e4xx + body.message + "(" + res.statusCode + ")" , body); | ||
} else { | ||
callback(false, body); | ||
} | ||
}); | ||
}; | ||
return { | ||
getRecord: function(callback) { | ||
callAPI(callback); | ||
}, | ||
updateRecord: function(data, callback) { | ||
callAPI(data, callback); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.