DC-004: Fix all 19 ESLint warnings (zero remaining)
Removed unused imports (path, validateStartupConfig, platformPaths), renamed unused destructures (_timeout, _logEntry), replaced nested ternaries with lookup tables, added eslint-disable comments on require-await functions that are intentionally async for API stability, and extracted helper functions to reduce max-depth and complexity in app.js, dns.js, provider-dns.js, and site.js. All 879 tests pass.
This commit is contained in:
@@ -34,35 +34,30 @@ function createProviderDnsContext(siteConfig, buildDomain, credentialManager, fe
|
||||
/** Get provider-specific config from site config */
|
||||
function getProviderConfig(providerId) {
|
||||
const dnsConfig = siteConfig.dns || {};
|
||||
|
||||
switch (providerId) {
|
||||
case 'technitium':
|
||||
return {
|
||||
serverIp: siteConfig.dnsServerIp || dnsConfig.ip || '',
|
||||
serverPort: siteConfig.dnsServerPort || dnsConfig.port || '5380',
|
||||
dnsServers: siteConfig.dnsServers || {},
|
||||
dnsId: Object.keys(siteConfig.dnsServers || {})[0] || 'dns1'
|
||||
};
|
||||
case 'cloudflare':
|
||||
return {
|
||||
apiToken: dnsConfig.apiToken || '',
|
||||
zoneId: dnsConfig.zoneId || '',
|
||||
domain: siteConfig.domain || ''
|
||||
};
|
||||
case 'rfc2136':
|
||||
return {
|
||||
server: dnsConfig.server || siteConfig.dnsServerIp || '',
|
||||
port: dnsConfig.port || 53,
|
||||
zone: siteConfig.tld?.replace(/^\./, '') || '',
|
||||
tsigAlgorithm: dnsConfig.tsigAlgorithm || 'hmac-sha256',
|
||||
tsigKeyName: dnsConfig.tsigKeyName || '',
|
||||
tsigSecret: dnsConfig.tsigSecret || ''
|
||||
};
|
||||
case 'manual':
|
||||
return {};
|
||||
default:
|
||||
return dnsConfig;
|
||||
}
|
||||
const builders = {
|
||||
technitium: () => ({
|
||||
serverIp: siteConfig.dnsServerIp || dnsConfig.ip || '',
|
||||
serverPort: siteConfig.dnsServerPort || dnsConfig.port || '5380',
|
||||
dnsServers: siteConfig.dnsServers || {},
|
||||
dnsId: Object.keys(siteConfig.dnsServers || {})[0] || 'dns1'
|
||||
}),
|
||||
cloudflare: () => ({
|
||||
apiToken: dnsConfig.apiToken || '',
|
||||
zoneId: dnsConfig.zoneId || '',
|
||||
domain: siteConfig.domain || ''
|
||||
}),
|
||||
rfc2136: () => ({
|
||||
server: dnsConfig.server || siteConfig.dnsServerIp || '',
|
||||
port: dnsConfig.port || 53,
|
||||
zone: siteConfig.tld?.replace(/^\./, '') || '',
|
||||
tsigAlgorithm: dnsConfig.tsigAlgorithm || 'hmac-sha256',
|
||||
tsigKeyName: dnsConfig.tsigKeyName || '',
|
||||
tsigSecret: dnsConfig.tsigSecret || ''
|
||||
}),
|
||||
manual: () => ({})
|
||||
};
|
||||
const builder = builders[providerId];
|
||||
return builder ? builder() : dnsConfig;
|
||||
}
|
||||
|
||||
/** Get or create the active provider adapter */
|
||||
@@ -120,6 +115,25 @@ function createProviderDnsContext(siteConfig, buildDomain, credentialManager, fe
|
||||
return null;
|
||||
}
|
||||
|
||||
async function tryServerRoleCredentials(dnsId, role, primaryIp) {
|
||||
try {
|
||||
const username = await credentialManager.retrieve(`dns.${dnsId}.${role}.username`);
|
||||
const password = await credentialManager.retrieve(`dns.${dnsId}.${role}.password`);
|
||||
if (username && password) return await refreshDnsToken(username, password, primaryIp);
|
||||
} catch (err) { /* try next */ }
|
||||
return null;
|
||||
}
|
||||
|
||||
async function tryGlobalCredentials(primaryIp) {
|
||||
try {
|
||||
const username = await credentialManager.retrieve('dns.username');
|
||||
const password = await credentialManager.retrieve('dns.password');
|
||||
const server = await credentialManager.retrieve('dns.server');
|
||||
if (username && password) return await refreshDnsToken(username, password, server || primaryIp);
|
||||
} catch (err) { /* no global creds */ }
|
||||
return null;
|
||||
}
|
||||
|
||||
async function ensureValidDnsToken() {
|
||||
if (dnsToken && dnsTokenExpiry && new Date() < new Date(dnsTokenExpiry)) {
|
||||
return { success: true, token: dnsToken };
|
||||
@@ -129,20 +143,13 @@ function createProviderDnsContext(siteConfig, buildDomain, credentialManager, fe
|
||||
const dnsId = dnsIpToDnsId(primaryIp);
|
||||
if (dnsId) {
|
||||
for (const role of ['admin', 'readonly']) {
|
||||
try {
|
||||
const username = await credentialManager.retrieve(`dns.${dnsId}.${role}.username`);
|
||||
const password = await credentialManager.retrieve(`dns.${dnsId}.${role}.password`);
|
||||
if (username && password) return await refreshDnsToken(username, password, primaryIp);
|
||||
} catch (err) { /* try next */ }
|
||||
const result = await tryServerRoleCredentials(dnsId, role, primaryIp);
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
const username = await credentialManager.retrieve('dns.username');
|
||||
const password = await credentialManager.retrieve('dns.password');
|
||||
const server = await credentialManager.retrieve('dns.server');
|
||||
if (username && password) return await refreshDnsToken(username, password, server || primaryIp);
|
||||
} catch (err) { /* no global creds */ }
|
||||
const globalResult = await tryGlobalCredentials(primaryIp);
|
||||
if (globalResult) return globalResult;
|
||||
return { success: false, error: 'No DNS credentials configured' };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user