asyncify the vultr and DO backend
This commit is contained in:
+1
-7
@@ -23,7 +23,6 @@ const assert = require('assert'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('./settings.js'),
|
||||
tld = require('tldjs'),
|
||||
util = require('util'),
|
||||
_ = require('underscore');
|
||||
|
||||
const DOMAINS_FIELDS = [ 'domain', 'zoneName', 'provider', 'configJson', 'tlsConfigJson', 'wellKnownJson', 'fallbackCertificateJson' ].join(',');
|
||||
@@ -67,11 +66,6 @@ function api(provider) {
|
||||
}
|
||||
}
|
||||
|
||||
function maybePromisify(func) {
|
||||
if (util.types.isAsyncFunction(func)) return func;
|
||||
return util.promisify(func);
|
||||
}
|
||||
|
||||
async function verifyDomainConfig(domainConfig, domain, zoneName, provider) {
|
||||
assert(domainConfig && typeof domainConfig === 'object'); // the dns config to test with
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
@@ -82,7 +76,7 @@ async function verifyDomainConfig(domainConfig, domain, zoneName, provider) {
|
||||
if (!backend) throw new BoxError(BoxError.BAD_FIELD, 'Invalid provider', { field: 'provider' });
|
||||
|
||||
const domainObject = { config: domainConfig, domain: domain, zoneName: zoneName };
|
||||
const [error, result] = await safe(maybePromisify(api(provider).verifyDomainConfig)(domainObject));
|
||||
const [error, result] = await safe(api(provider).verifyDomainConfig)(domainObject);
|
||||
if (error && error.reason === BoxError.ACCESS_DENIED) return { error: new BoxError(BoxError.BAD_FIELD, `Access denied: ${error.message}`) };
|
||||
if (error && error.reason === BoxError.NOT_FOUND) return { error: new BoxError(BoxError.BAD_FIELD, `Zone not found: ${error.message}`) };
|
||||
if (error && error.reason === BoxError.EXTERNAL_ERROR) return { error: new BoxError(BoxError.BAD_FIELD, `Configuration error: ${error.message}`) };
|
||||
|
||||
Reference in New Issue
Block a user