Added support for authentication tokens + fix for #1 #2
14
lib/index.js
14
lib/index.js
|
@ -44,12 +44,12 @@ module.exports.create = function (config) {
|
|||
defaultHeaders['X-Auth-Key'] = config.authKey
|
||||
}
|
||||
function api (method, path, body, tokenType) {
|
||||
const headers = defaultHeaders;
|
||||
const headers = defaultHeaders
|
||||
if (tokenType && config.bearerTokens) {
|
||||
if (!(tokenType in config.bearerTokens)) {
|
||||
throw new Error('Unrecognized token type');
|
||||
throw new Error('Unrecognized token type')
|
||||
}
|
||||
headers['Authorization'] = 'Bearer ' + config.bearerTokens[tokenType];
|
||||
headers.Authorization = 'Bearer ' + config.bearerTokens[tokenType]
|
||||
}
|
||||
return request({
|
||||
url: baseUrl + path,
|
||||
|
@ -118,9 +118,9 @@ module.exports.create = function (config) {
|
|||
formatError('Could not read record', resp)
|
||||
}
|
||||
|
||||
let {result} = resp.body
|
||||
const { result } = resp.body
|
||||
|
||||
let record = result.filter(record => (record.type === 'TXT' && record.content === txtRecord))[0]
|
||||
const record = result.filter(record => (record.type === 'TXT' && record.content === txtRecord))[0]
|
||||
|
||||
if (record) {
|
||||
const resp = await api('DELETE', `/zones/${zone.id}/dns_records/${record.id}`, undefined, 'zone')
|
||||
|
@ -149,9 +149,9 @@ module.exports.create = function (config) {
|
|||
formatError('Could not read record', resp)
|
||||
}
|
||||
|
||||
let {result} = resp.body
|
||||
const { result } = resp.body
|
||||
|
||||
let record = result.filter(record => (record.type === 'TXT' && record.content === txtRecord))[0]
|
||||
const record = result.filter(record => (record.type === 'TXT' && record.content === txtRecord))[0]
|
||||
|
||||
if (record) {
|
||||
return { dnsAuthorization: record.content }
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,6 +25,13 @@
|
|||
"@root/request": "^1.3.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acme-dns-01-test": "^3.2.1"
|
||||
"acme-dns-01-test": "^3.2.1",
|
||||
"standard": "^14.1.0",
|
||||
"husky": "^3.0.4"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "npx standard --fix && git update-index --again"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue