refactor getting mail auth
This commit is contained in:
+27
@@ -26,6 +26,7 @@ exports = module.exports = {
|
||||
startMail: restartMail,
|
||||
restartMail: restartMail,
|
||||
handleCertChanged: handleCertChanged,
|
||||
getMailAuth: getMailAuth,
|
||||
|
||||
sendTestMail: sendTestMail,
|
||||
|
||||
@@ -55,6 +56,7 @@ var assert = require('assert'),
|
||||
constants = require('./constants.js'),
|
||||
debug = require('debug')('box:mail'),
|
||||
dns = require('./native-dns.js'),
|
||||
docker = require('./docker.js'),
|
||||
domains = require('./domains.js'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
hat = require('./hat.js'),
|
||||
@@ -661,6 +663,31 @@ function configureMail(mailFqdn, mailDomain, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getMailAuth(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
docker.inspect('mail', function (error, data) {
|
||||
if (error) return callback(error);
|
||||
|
||||
const ip = safe.query(data, 'NetworkSettings.Networks.cloudron.IPAddress');
|
||||
if (!ip) return callback(new BoxError(BoxError.MAIL_ERROR, 'Error querying mail server IP'));
|
||||
|
||||
// extract the relay token for auth
|
||||
const env = safe.query(data, 'Config.Env', null);
|
||||
if (!env) return callback(new BoxError(BoxError.MAIL_ERROR, 'Error getting mail env'));
|
||||
const tmp = env.find(function (e) { return e.indexOf('CLOUDRON_RELAY_TOKEN') === 0; });
|
||||
if (!tmp) return callback(new BoxError(BoxError.MAIL_ERROR, 'Error getting CLOUDRON_RELAY_TOKEN env var'));
|
||||
const relayToken = tmp.slice('CLOUDRON_RELAY_TOKEN'.length + 1); // +1 for the = sign
|
||||
if (!relayToken) return callback(new BoxError(BoxError.MAIL_ERROR, 'Error parsing CLOUDRON_RELAY_TOKEN'));
|
||||
|
||||
callback(null, {
|
||||
ip,
|
||||
port: constants.INTERNAL_SMTP_PORT,
|
||||
relayToken
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function restartMail(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user