mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(distribute) import: do not import if env variable set
This commit is contained in:
parent
b8a83868da
commit
79f68d01c8
5 changed files with 121 additions and 3 deletions
|
|
@ -9,6 +9,7 @@ const io = require('socket.io-client');
|
|||
const forEachKey = currify(require('for-each-key'));
|
||||
|
||||
const log = require('./log');
|
||||
const env = require('../env');
|
||||
|
||||
const {
|
||||
importStr,
|
||||
|
|
@ -23,6 +24,8 @@ const {
|
|||
logWraped,
|
||||
} = log;
|
||||
|
||||
const {entries} = Object;
|
||||
|
||||
const equal = (a, b) => `${a}=${b}`;
|
||||
const append = currify((obj, a, b) => obj.value += b && equal(a, b) + '&');
|
||||
const wrapApply = (f, disconnect) => (status) => () => f(null, {
|
||||
|
|
@ -62,6 +65,16 @@ const emitAuth = wraptile((importUrl, config, socket) => {
|
|||
socket.emit('auth', config('importToken'));
|
||||
});
|
||||
|
||||
const updateConfig = currify((config, data) => {
|
||||
for (const [key, value] of entries(data)) {
|
||||
if (typeof env(key) !== 'undefined') {
|
||||
continue;
|
||||
}
|
||||
|
||||
config(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = (config, options, fn) => {
|
||||
fn = fn || options;
|
||||
|
||||
|
|
@ -96,7 +109,7 @@ module.exports = (config, options, fn) => {
|
|||
close,
|
||||
logWraped(isLog, importStr, `config received from ${colorUrl}`),
|
||||
statusStoreWraped('received'),
|
||||
forEachKey(config),
|
||||
updateConfig(config),
|
||||
);
|
||||
|
||||
const onError = squad(
|
||||
|
|
|
|||
|
|
@ -3,14 +3,18 @@
|
|||
const test = require('supertape');
|
||||
const {promisify} = require('util');
|
||||
const tryToCatch = require('try-to-catch');
|
||||
|
||||
const {connect} = require('../../test/before');
|
||||
const {createConfigManager} = require('../cloudcmd');
|
||||
|
||||
const distribute = {
|
||||
import: promisify(require('./import')),
|
||||
};
|
||||
|
||||
const config = createConfigManager();
|
||||
|
||||
process.on('unhandledRejection', console.log);
|
||||
|
||||
test('distribute: import: canceled', async (t) => {
|
||||
const {done} = await connect({
|
||||
config: {
|
||||
|
|
@ -189,5 +193,95 @@ test('distribute: import: config:change: no export', async (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', console.log);
|
||||
test('distribute: import: env', async (t) => {
|
||||
const configManager = createConfigManager();
|
||||
const configManagerImport = createConfigManager();
|
||||
|
||||
const exporter = await connect({
|
||||
configManager,
|
||||
config: {
|
||||
name: 'bill',
|
||||
import: false,
|
||||
importListen: false,
|
||||
export: true,
|
||||
exportToken: 'a',
|
||||
log: false,
|
||||
editor: 'edward',
|
||||
},
|
||||
});
|
||||
|
||||
const importer = await connect({
|
||||
configManager: configManagerImport,
|
||||
config: {
|
||||
name: 'jack',
|
||||
import: true,
|
||||
importToken: 'a',
|
||||
export: false,
|
||||
importListen: false,
|
||||
log: false,
|
||||
editor: 'deepword',
|
||||
},
|
||||
});
|
||||
|
||||
const {cloudcmd_editor} = process.env;
|
||||
process.env.cloudcmd_editor = 'some editor';
|
||||
|
||||
configManagerImport('importUrl', `http://localhost:${exporter.port}`);
|
||||
|
||||
await distribute.import(configManagerImport);
|
||||
|
||||
await importer.done();
|
||||
await exporter.done();
|
||||
|
||||
process.env.cloudcmd_editor = cloudcmd_editor;
|
||||
|
||||
const result = configManagerImport('editor');
|
||||
const expected = 'deepword';
|
||||
|
||||
t.equal(expected, result);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('distribute: import: no env', async (t) => {
|
||||
const configManager = createConfigManager();
|
||||
const configManagerImport = createConfigManager();
|
||||
|
||||
const exporter = await connect({
|
||||
configManager,
|
||||
config: {
|
||||
name: 'bill',
|
||||
import: false,
|
||||
importListen: false,
|
||||
export: true,
|
||||
exportToken: 'a',
|
||||
log: false,
|
||||
editor: 'edward',
|
||||
},
|
||||
});
|
||||
|
||||
const importer = await connect({
|
||||
configManager: configManagerImport,
|
||||
config: {
|
||||
name: 'jack',
|
||||
import: true,
|
||||
importToken: 'a',
|
||||
export: false,
|
||||
importListen: false,
|
||||
log: false,
|
||||
editor: 'deepword',
|
||||
},
|
||||
});
|
||||
|
||||
configManagerImport('importUrl', `http://localhost:${exporter.port}`);
|
||||
|
||||
await distribute.import(configManagerImport);
|
||||
|
||||
await importer.done();
|
||||
await exporter.done();
|
||||
|
||||
const result = configManagerImport('editor');
|
||||
const expected = 'edward';
|
||||
|
||||
t.equal(expected, result);
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue