Skip to content

Commit bf4c2fd

Browse files
authored
Merge branch 'develop' into master
2 parents 43ff263 + 2d0ed7f commit bf4c2fd

File tree

4 files changed

+53
-49
lines changed

4 files changed

+53
-49
lines changed

scripts/postinstall.js

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* *******************************************************************************
1111
*
1212
*/
13-
13+
const sqlite3 = require('sqlite3');//.verbose(); //use verbose in dev to get stack traces
1414
const os = require('os');
1515
const execSync = require('child_process').execSync;
1616
const fs = require('fs');
@@ -64,7 +64,7 @@ try {
6464

6565
fs.unlinkSync(installationVariablesFile);
6666
} catch (e) {
67-
console.log('no previous version')
67+
console.log('no previous version');
6868
}
6969

7070
//init db
@@ -102,52 +102,46 @@ function moveFileIfExists(from, to) {
102102

103103
function insertSeeds() {
104104
console.log(' inserting seeds meta info in db');
105-
const options = {
106-
env: {
107-
"PATH": process.env.PATH
108-
},
109-
stdio: [process.stdin, process.stdout, process.stderr]
110-
};
111-
112-
execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928110125-insert-registry.js');"`, options);
113-
execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928111532-insert-catalog-item.js');"`, options);
114-
execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928112152-insert-iofog-type.js');"`, options);
115-
execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928121334-insert-catalog-item-image.js');"`, options);
105+
const sqlite3ProdDb = new sqlite3.Database(prodDb);
106+
const seeds = [
107+
'20180928110125-insert-registry.js',
108+
'20180928111532-insert-catalog-item.js',
109+
'20180928112152-insert-iofog-type.js',
110+
'20180928121334-insert-catalog-item-image.js'
111+
];
112+
sqlite3ProdDb.serialize(function() {
113+
const stmt = sqlite3ProdDb.prepare("INSERT INTO SequelizeMeta (name) VALUES (?)");
114+
seeds.map(s => stmt.run(s));
115+
stmt.finalize();
116+
});
117+
sqlite3ProdDb.close();
116118
}
117119

118120
function updateEncryptionMethodForUsersPassword(decryptionFunc) {
119-
const options = {
120-
env: {
121-
"PATH": process.env.PATH
122-
}
123-
};
124-
125-
const usersOutput = execSync(`sqlite3 ${prodDb} "select id, email, password from Users;"`, options).toString();
126-
const usersLines = usersOutput.match(/[^\r\n]+/g);
127-
for (let line of usersLines) {
128-
let id, email, oldEncryptedPassword;
129-
try {
130-
const vals = line.split('|');
131-
id = vals[0];
132-
email = vals[1];
133-
oldEncryptedPassword = vals[2];
134-
135-
const decryptedPassword = decryptionFunc(oldEncryptedPassword, email);
136-
137-
const AppHelper = require('../src/helpers/app-helper');
138-
const newEncryptedPassword = AppHelper.encryptText(decryptedPassword, email);
139-
140-
const options = {
141-
env: {
142-
"PATH": process.env.PATH
143-
},
144-
stdio: [process.stdin, process.stdout, process.stderr]
145-
};
146-
execSync(`sqlite3 ${prodDb} "update Users set password='${newEncryptedPassword}' where id=${id};"`, options);
147-
} catch (e) {
148-
console.log('db problem');
149-
}
150-
}
121+
console.log(' updating encryption in DB');
122+
const sqlite3ProdDb = new sqlite3.Database(prodDb);
123+
sqlite3ProdDb.all('select id, email, password from Users', function(err, rows) {
124+
const stmt = sqlite3ProdDb.prepare('update Users set password=? where id=?');
125+
126+
rows.map(user => {
127+
try {
128+
const id = user.id;
129+
const email = user.email;
130+
const oldEncryptedPassword = user.password;
131+
132+
const decryptedPassword = decryptionFunc(oldEncryptedPassword, email);
133+
const AppHelper = require('../src/helpers/app-helper');
134+
const newEncryptedPassword = AppHelper.encryptText(decryptedPassword, email);
135+
136+
stmt.run(newEncryptedPassword, id);
137+
} catch (e) {
138+
console.log('db problem');
139+
console.log(e);
140+
}
141+
});
142+
stmt.finalize();
143+
});
144+
sqlite3ProdDb.close();
151145
}
152146

153147
function updateEncryptionMethodForEmailService(configFile, decryptionFunc) {
@@ -191,6 +185,7 @@ function updateEncryptionMethod() {
191185
}
192186

193187
updateEncryptionMethodForUsersPassword(decryptTextVer30);
188+
console.log(' updating encryption for email services in configs');
194189
updateEncryptionMethodForEmailService(defConfig, decryptTextVer30);
195190
updateEncryptionMethodForEmailService(devConfig, decryptTextVer30);
196191
updateEncryptionMethodForEmailService(prodConfig, decryptTextVer30);

src/cli/iofog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ async function _getHalHardwareInfo(obj) {
354354
if (data.hasOwnProperty('info')) {
355355
data.info = JSON.parse(data.info);
356356
}
357-
357+
358358
logger.info(JSON.stringify(data, null, 2));
359359
}
360360

src/services/microservices-service.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,11 @@ async function updateMicroservice(microserviceUuid, microserviceData, user, isCL
128128
userId: user.id
129129
};
130130

131+
const config = _validateMicroserviceConfig(microserviceData.config);
132+
131133
const microserviceToUpdate = {
132134
name: microserviceData.name,
133-
config: microserviceData.config,
135+
config: config,
134136
rebuild: microserviceData.rebuild,
135137
iofogUuid: microserviceData.iofogUuid,
136138
rootHostAccess: microserviceData.rootHostAccess,
@@ -481,12 +483,20 @@ async function listVolumeMappings(microserviceUuid, user, isCLI, transaction) {
481483
return await VolumeMappingManager.findAll(volumeMappingWhere, transaction);
482484
}
483485

486+
// this function works with escape and unescape config, in case of unescaped config, the first split will not work,
487+
// but the second will work
488+
function _validateMicroserviceConfig(config) {
489+
return config.split('\\"').join('"').split('"').join('\"');
490+
}
491+
484492
async function _createMicroservice(microserviceData, user, isCLI, transaction) {
485493

494+
const config = _validateMicroserviceConfig(microserviceData.config);
495+
486496
let newMicroservice = {
487497
uuid: AppHelper.generateRandomString(32),
488498
name: microserviceData.name,
489-
config: microserviceData.config,
499+
config: config,
490500
catalogItemId: microserviceData.catalogItemId,
491501
flowId: microserviceData.flowId,
492502
iofogUuid: microserviceData.iofogUuid,

test/src/services/iofog-service.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,6 @@ describe('ioFog Service', () => {
814814
return expect($subject).to.be.rejectedWith(error);
815815
})
816816
});
817-
818817
context('when ChangeTrackingService#update() succeeds', () => {
819818
it('fulfills the promise', () => {
820819
return expect($subject).to.eventually.equal(undefined);

0 commit comments

Comments
 (0)