domains: remove SECRET_PLACEHOLDER from responses

This commit is contained in:
Girish Ramakrishnan
2025-10-08 12:04:31 +02:00
parent f1fb5f2530
commit 01d7d41c17
21 changed files with 266 additions and 267 deletions

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -36,12 +26,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.accessKey = constants.SECRET_PLACEHOLDER;
delete domainObject.config.accessKey;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.accessKey === constants.SECRET_PLACEHOLDER) newConfig.accessKey = currentConfig.accessKey;
if (!Object.hasOwn(newConfig, 'accessKey')) newConfig.accessKey = currentConfig.accessKey;
}
async function getZoneId(domainConfig, zoneName) {
@@ -255,3 +245,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -25,12 +15,12 @@ const assert = require('node:assert'),
const CLOUDFLARE_ENDPOINT = 'https://api.cloudflare.com/client/v4';
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.token;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'token')) newConfig.token = currentConfig.token;
}
function translateResponseError(response) {
@@ -291,3 +281,13 @@ async function verifyDomainConfig(domainObject) {
return sanitizedConfig;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
constants = require('../constants.js'),
BoxError = require('../boxerror.js'),
@@ -28,12 +18,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.token;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'token')) newConfig.token = currentConfig.token;
}
async function get(domainObject, location, type) {
@@ -62,6 +52,29 @@ async function get(domainObject, location, type) {
return response.body.records;
}
async function del(domainObject, location, type, values) {
assert.strictEqual(typeof domainObject, 'object');
assert.strictEqual(typeof location, 'string');
assert.strictEqual(typeof type, 'string');
assert(Array.isArray(values));
const domainConfig = domainObject.config,
zoneName = domainObject.zoneName,
name = dns.getName(domainObject, location, type) || '@';
await timers.setTimeout(1000); // https://desec.readthedocs.io/en/latest/rate-limits.html
const [error, response] = await safe(superagent.del(`${DESEC_ENDPOINT}/domains/${zoneName}/rrsets/${name}/${type}/`)
.set('Authorization', `Token ${domainConfig.token}`)
.timeout(30 * 1000)
.retry(5)
.ok(() => true));
if (error) throw new BoxError(BoxError.NETWORK_ERROR, error);
if (response.status === 404) return;
if (response.status === 403 || response.status === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
if (response.status !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
}
async function upsert(domainObject, location, type, values) {
assert.strictEqual(typeof domainObject, 'object');
assert.strictEqual(typeof location, 'string');
@@ -94,29 +107,6 @@ async function upsert(domainObject, location, type, values) {
if (response.status !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
}
async function del(domainObject, location, type, values) {
assert.strictEqual(typeof domainObject, 'object');
assert.strictEqual(typeof location, 'string');
assert.strictEqual(typeof type, 'string');
assert(Array.isArray(values));
const domainConfig = domainObject.config,
zoneName = domainObject.zoneName,
name = dns.getName(domainObject, location, type) || '@';
await timers.setTimeout(1000); // https://desec.readthedocs.io/en/latest/rate-limits.html
const [error, response] = await safe(superagent.del(`${DESEC_ENDPOINT}/domains/${zoneName}/rrsets/${name}/${type}/`)
.set('Authorization', `Token ${domainConfig.token}`)
.timeout(30 * 1000)
.retry(5)
.ok(() => true));
if (error) throw new BoxError(BoxError.NETWORK_ERROR, error);
if (response.status === 404) return;
if (response.status === 403 || response.status === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
if (response.status !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
}
async function wait(domainObject, subdomain, type, value, options) {
assert.strictEqual(typeof domainObject, 'object');
assert.strictEqual(typeof subdomain, 'string');
@@ -166,3 +156,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -27,12 +17,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.token;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'token')) newConfig.token = currentConfig.token;
}
async function getZoneRecords(domainConfig, zoneName, name, type) {
@@ -252,3 +242,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -27,12 +17,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.accessToken = constants.SECRET_PLACEHOLDER;
delete domainObject.config.accessToken;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.accessToken === constants.SECRET_PLACEHOLDER) newConfig.accessToken = currentConfig.accessToken;
if (!Object.hasOwn(newConfig, 'accessToken')) newConfig.accessToken = currentConfig.accessToken;
}
async function getAccountId(domainConfig) {
@@ -264,3 +254,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -27,12 +17,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.token;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'token')) newConfig.token = currentConfig.token;
}
function createRequest(method, url, domainConfig) {
@@ -171,3 +161,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,17 +1,5 @@
'use strict';
const safe = require('safetydance');
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -19,16 +7,17 @@ const assert = require('node:assert'),
dig = require('../dig.js'),
dns = require('../dns.js'),
GCDNS = require('@google-cloud/dns').DNS,
safe = require('safetydance'),
waitForDns = require('./waitfordns.js'),
_ = require('../underscore.js');
function removePrivateFields(domainObject) {
domainObject.config.credentials.private_key = constants.SECRET_PLACEHOLDER;
delete domainObject.config.credentials.private_key;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.credentials.private_key === constants.SECRET_PLACEHOLDER && currentConfig.credentials) newConfig.credentials.private_key = currentConfig.credentials.private_key;
if (!Object.hasOwn(newConfig.credentials, 'private_key') && currentConfig.credentials) newConfig.credentials.private_key = currentConfig.credentials.private_key;
}
function getDnsCredentials(domainConfig) {
@@ -193,3 +182,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -28,12 +18,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.apiSecret = constants.SECRET_PLACEHOLDER;
delete domainObject.config.apiSecret;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.apiSecret === constants.SECRET_PLACEHOLDER) newConfig.apiSecret = currentConfig.apiSecret;
if (!Object.hasOwn(newConfig, 'apiSecret')) newConfig.apiSecret = currentConfig.apiSecret;
}
async function upsert(domainObject, location, type, values) {
@@ -192,3 +182,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -27,12 +17,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.token;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'token')) newConfig.token = currentConfig.token;
}
async function getZone(domainConfig, zoneName) {
@@ -258,3 +248,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const { ApiClient, Language } = require('domrobot-client'),
assert = require('node:assert'),
BoxError = require('../boxerror.js'),
@@ -25,12 +15,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.password = constants.SECRET_PLACEHOLDER;
delete domainObject.config.password;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.password === constants.SECRET_PLACEHOLDER) newConfig.password = currentConfig.password;
if (!Object.hasOwn(newConfig, 'password')) newConfig.password = currentConfig.password;
}
// https://www.inwx.com/en/help/apidoc/f/ch04.html
@@ -217,3 +207,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
constants = require('../constants.js'),
BoxError = require('../boxerror.js'),
@@ -27,12 +17,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.token;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'token')) newConfig.token = currentConfig.token;
}
async function getZoneId(domainConfig, zoneName) {
@@ -267,3 +257,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
verifyDomainConfig,
wait
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -27,12 +17,12 @@ const assert = require('node:assert'),
const ENDPOINT = 'https://api.namecheap.com/xml.response';
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.token;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'token')) newConfig.token = currentConfig.token;
}
async function getQuery(domainConfig) {
@@ -284,3 +274,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
verifyDomainConfig,
wait
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -27,12 +17,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.token;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'token')) newConfig.token = currentConfig.token;
}
async function addRecord(domainConfig, zoneName, name, type, values) {
@@ -250,3 +240,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -28,12 +18,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.apiPassword;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'apiPassword')) newConfig.apiPassword = currentConfig.apiPassword;
}
// returns a api session id
@@ -262,3 +252,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -25,12 +15,12 @@ function formatError(error) {
}
function removePrivateFields(domainObject) {
domainObject.config.appSecret = constants.SECRET_PLACEHOLDER;
delete domainObject.config.appSecret;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.appSecret === constants.SECRET_PLACEHOLDER) newConfig.appSecret = currentConfig.appSecret;
if (!Object.hasOwn(newConfig, 'appSecret')) newConfig.appSecret = currentConfig.appSecret;
}
function createClient(domainConfig) {
@@ -234,3 +224,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
@@ -30,12 +20,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.secretapikey = constants.SECRET_PLACEHOLDER;
delete domainObject.config.secretapikey;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.secretapikey === constants.SECRET_PLACEHOLDER) newConfig.secretapikey = currentConfig.secretapikey;
if (!Object.hasOwn(newConfig, 'secretapikey')) newConfig.secretapikey = currentConfig.secretapikey;
}
async function createRequest(method, url, data) {
@@ -226,3 +216,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig,
};
const assert = require('node:assert'),
BoxError = require('../boxerror.js'),
{ ConfiguredRetryStrategy } = require('@smithy/util-retry'),
@@ -23,12 +13,12 @@ const assert = require('node:assert'),
_ = require('../underscore.js');
function removePrivateFields(domainObject) {
domainObject.config.secretAccessKey = constants.SECRET_PLACEHOLDER;
delete domainObject.config.secretAccessKey;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.secretAccessKey === constants.SECRET_PLACEHOLDER) newConfig.secretAccessKey = currentConfig.secretAccessKey;
if (!Object.hasOwn(newConfig, 'secretAccessKey')) newConfig.secretAccessKey = currentConfig.secretAccessKey;
}
function createRoute53Client(domainConfig) {
@@ -270,3 +260,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig,
};

View File

@@ -1,15 +1,5 @@
'use strict';
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};
const assert = require('node:assert'),
constants = require('../constants.js'),
BoxError = require('../boxerror.js'),
@@ -27,12 +17,12 @@ function formatError(response) {
}
function removePrivateFields(domainObject) {
domainObject.config.token = constants.SECRET_PLACEHOLDER;
delete domainObject.config.token;
return domainObject;
}
function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
if (!Object.hasOwn(newConfig, 'token')) newConfig.token = currentConfig.token;
}
async function getZoneRecords(domainConfig, zoneName, name, type) {
@@ -237,3 +227,13 @@ async function verifyDomainConfig(domainObject) {
return credentials;
}
exports = module.exports = {
removePrivateFields,
injectPrivateFields,
upsert,
get,
del,
wait,
verifyDomainConfig
};