replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import assert from 'node:assert';
|
||||
import constants from '../constants.js';
|
||||
import BoxError from '../boxerror.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from '../logger.js';
|
||||
import dig from '../dig.js';
|
||||
import dns from '../dns.js';
|
||||
import safe from 'safetydance';
|
||||
import superagent from '@cloudron/superagent';
|
||||
import waitForDns from './waitfordns.js';
|
||||
|
||||
const debug = debugModule('box:dns/linode');
|
||||
const { log, trace } = logger('dns/linode');
|
||||
|
||||
|
||||
const LINODE_ENDPOINT = 'https://api.linode.com/v4';
|
||||
@@ -47,7 +47,7 @@ async function getZoneId(domainConfig, zoneName) {
|
||||
|
||||
if (!zone || !zone.id) throw new BoxError(BoxError.NOT_FOUND, 'Zone not found');
|
||||
|
||||
debug(`getZoneId: zone id of ${zoneName} is ${zone.id}`);
|
||||
log(`getZoneId: zone id of ${zoneName} is ${zone.id}`);
|
||||
|
||||
return zone.id;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ async function getZoneRecords(domainConfig, zoneName, name, type) {
|
||||
assert.strictEqual(typeof name, 'string');
|
||||
assert.strictEqual(typeof type, 'string');
|
||||
|
||||
debug(`getInternal: getting dns records of ${zoneName} with ${name} and type ${type}`);
|
||||
log(`getInternal: getting dns records of ${zoneName} with ${name} and type ${type}`);
|
||||
|
||||
const zoneId = await getZoneId(domainConfig, zoneName);
|
||||
|
||||
@@ -113,7 +113,7 @@ async function upsert(domainObject, location, type, values) {
|
||||
zoneName = domainObject.zoneName,
|
||||
name = dns.getName(domainObject, location, type) || '';
|
||||
|
||||
debug('upsert: %s for zone %s of type %s with values %j', name, zoneName, type, values);
|
||||
log('upsert: %s for zone %s of type %s with values %j', name, zoneName, type, values);
|
||||
|
||||
const { zoneId, records } = await getZoneRecords(domainConfig, zoneName, name, type);
|
||||
let i = 0; // used to track available records to update instead of create
|
||||
@@ -176,7 +176,7 @@ async function upsert(domainObject, location, type, values) {
|
||||
.retry(5)
|
||||
.ok(() => true));
|
||||
|
||||
if (error) debug(`upsert: error removing record ${records[j].id}: ${error.message}`);
|
||||
if (error) log(`upsert: error removing record ${records[j].id}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,17 +244,17 @@ async function verifyDomainConfig(domainObject) {
|
||||
if (error || !nameservers) throw new BoxError(BoxError.BAD_FIELD, error ? error.message : 'Unable to get nameservers');
|
||||
|
||||
if (nameservers.map(function (n) { return n.toLowerCase(); }).indexOf('ns1.linode.com') === -1) {
|
||||
debug('verifyDomainConfig: %j does not contains linode NS', nameservers);
|
||||
log('verifyDomainConfig: %j does not contains linode NS', nameservers);
|
||||
if (!domainConfig.customNameservers) throw new BoxError(BoxError.BAD_FIELD, 'Domain nameservers are not set to Linode');
|
||||
}
|
||||
|
||||
const location = 'cloudrontestdns';
|
||||
|
||||
await upsert(domainObject, location, 'A', [ ip ]);
|
||||
debug('verifyDomainConfig: Test A record added');
|
||||
log('verifyDomainConfig: Test A record added');
|
||||
|
||||
await del(domainObject, location, 'A', [ ip ]);
|
||||
debug('verifyDomainConfig: Test A record removed again');
|
||||
log('verifyDomainConfig: Test A record removed again');
|
||||
|
||||
return credentials;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user