appstore and support: async'ify
This commit is contained in:
@@ -11,7 +11,6 @@ const assert = require('assert'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
constants = require('./constants.js'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
once = require('once'),
|
||||
path = require('path'),
|
||||
paths = require('./paths.js'),
|
||||
safe = require('safetydance'),
|
||||
@@ -30,38 +29,26 @@ function sshInfo() {
|
||||
filePath = '/home/ubuntu/.ssh/authorized_keys';
|
||||
user = 'ubuntu';
|
||||
} else {
|
||||
filePath = '/root/.ssh/authorized_keys';
|
||||
user = 'root';
|
||||
}
|
||||
|
||||
return { filePath, user };
|
||||
}
|
||||
|
||||
function getRemoteSupport(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
async function getRemoteSupport() {
|
||||
const [error, stdoutResult] = await safe(shell.promises.sudo('support', [ AUTHORIZED_KEYS_CMD, 'is-enabled', sshInfo().filePath ], {}));
|
||||
if (error) throw new BoxError(BoxError.FS_ERROR, error);
|
||||
|
||||
callback = once(callback); // exit may or may not be called after an 'error'
|
||||
|
||||
let result = '';
|
||||
let cp = shell.sudo('support', [ AUTHORIZED_KEYS_CMD, 'is-enabled', sshInfo().filePath ], {}, function (error) {
|
||||
if (error) callback(new BoxError(BoxError.FS_ERROR, error));
|
||||
|
||||
callback(null, { enabled: result.trim() === 'true' });
|
||||
});
|
||||
cp.stdout.on('data', (data) => result = result + data.toString('utf8'));
|
||||
return stdoutResult.trim() === 'true';
|
||||
}
|
||||
|
||||
function enableRemoteSupport(enable, auditSource, callback) {
|
||||
async function enableRemoteSupport(enable, auditSource) {
|
||||
assert.strictEqual(typeof enable, 'boolean');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const si = sshInfo();
|
||||
shell.sudo('support', [ AUTHORIZED_KEYS_CMD, enable ? 'enable' : 'disable', si.filePath, si.user ], {}, function (error) {
|
||||
if (error) callback(new BoxError(BoxError.FS_ERROR, error));
|
||||
const [error] = await safe(shell.promises.sudo('support', [ AUTHORIZED_KEYS_CMD, enable ? 'enable' : 'disable', si.filePath, si.user ], {}));
|
||||
if (error) throw new BoxError(BoxError.FS_ERROR, error);
|
||||
|
||||
eventlog.add(eventlog.ACTION_SUPPORT_SSH, auditSource, { enable });
|
||||
|
||||
callback();
|
||||
});
|
||||
await eventlog.add(eventlog.ACTION_SUPPORT_SSH, auditSource, { enable });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user