asyncify the vultr and DO backend

This commit is contained in:
Girish Ramakrishnan
2022-02-04 09:37:02 -08:00
parent bd4097098d
commit 856b23d940
6 changed files with 203 additions and 311 deletions
+1 -7
View File
@@ -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}`) };