Bug fix
Fixed: Session secret not set in configuration - Ignore optional Yes or No when config file is not available already.
This commit is contained in:
parent
96b9d3b6e9
commit
8c6142af98
@ -1,15 +1,13 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const getInput = require('./getInput');
|
const getInput = require('./getInput');
|
||||||
|
|
||||||
var config, flag = false;
|
var config, flag_new;
|
||||||
try {
|
try {
|
||||||
config = require('./args/config.json');
|
config = require('./args/config.json');
|
||||||
flag = true;
|
flag_new = false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
config = {
|
config = {
|
||||||
"secret": null,
|
"secret": null,
|
||||||
"blockchain_id": null,
|
|
||||||
"blockchain_private": null,
|
|
||||||
"port": "8080",
|
"port": "8080",
|
||||||
|
|
||||||
"sql_user": null,
|
"sql_user": null,
|
||||||
@ -17,8 +15,21 @@ try {
|
|||||||
"sql_db": "exchange",
|
"sql_db": "exchange",
|
||||||
"sql_host": "localhost"
|
"sql_host": "localhost"
|
||||||
};
|
};
|
||||||
|
flag_new = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function flaggedYesOrNo(text) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (flag_new)
|
||||||
|
resolve(true);
|
||||||
|
else
|
||||||
|
getInput.YesOrNo(text)
|
||||||
|
.then(result => resolve(result))
|
||||||
|
.catch(error => reject(error))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function configurePort() {
|
function configurePort() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
getInput.Text('Enter port', config["port"]).then(port => {
|
getInput.Text('Enter port', config["port"]).then(port => {
|
||||||
@ -30,7 +41,7 @@ function configurePort() {
|
|||||||
|
|
||||||
function configureSQL() {
|
function configureSQL() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
getInput.YesOrNo('Do you want to re-configure mySQL connection').then(value => {
|
flaggedYesOrNo('Do you want to re-configure mySQL connection').then(value => {
|
||||||
if (value) {
|
if (value) {
|
||||||
console.log('Enter mySQL connection values: ')
|
console.log('Enter mySQL connection values: ')
|
||||||
getInput.Text('Host', config['sql_host']).then(host => {
|
getInput.Text('Host', config['sql_host']).then(host => {
|
||||||
@ -52,32 +63,51 @@ function configureSQL() {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function randomizeSessionSecret() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
flaggedYesOrNo('Do you want to randomize the session secret').then(value => {
|
||||||
|
if (value) {
|
||||||
|
let N = Math.floor(Math.random() * (64 - 32 + 1)) + 32;
|
||||||
|
var secret = '';
|
||||||
|
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
for (var i = 0; i < N; i++)
|
||||||
|
secret += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||||
|
config['secret'] = secret
|
||||||
|
resolve(true);
|
||||||
|
} else
|
||||||
|
resolve(false);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function configure() {
|
function configure() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
configurePort().then(port_result => {
|
configurePort().then(port_result => {
|
||||||
configureSQL().then(sql_result => {
|
randomizeSessionSecret().then(secret_result => {
|
||||||
fs.writeFile(__dirname + '/../args/config.json', JSON.stringify(config), 'utf8', (err) => {
|
configureSQL().then(sql_result => {
|
||||||
if (err) {
|
fs.writeFile(__dirname + '/../args/config.json', JSON.stringify(config), 'utf8', (err) => {
|
||||||
console.error(err);
|
if (err) {
|
||||||
return reject(false);
|
console.error(err);
|
||||||
}
|
return reject(false);
|
||||||
console.log('Configuration successful!');
|
}
|
||||||
if (sql_result) {
|
console.log('Configuration successful!');
|
||||||
getInput.YesOrNo('Do you want to create schema in the database').then(value => {
|
if (sql_result) {
|
||||||
if (value) {
|
getInput.YesOrNo('Do you want to create schema in the database').then(value => {
|
||||||
const createSchema = require('./create-schema');
|
if (value) {
|
||||||
createSchema().then(result => resolve(result))
|
const createSchema = require('./create-schema');
|
||||||
.catch(error => {
|
createSchema().then(result => resolve(result))
|
||||||
console.log('Retry using: \n' + 'npm run create-schema');
|
.catch(error => {
|
||||||
reject(error);
|
console.log('Retry using: \n' + 'npm run create-schema');
|
||||||
});
|
reject(error);
|
||||||
} else {
|
});
|
||||||
console.log('To create schema, use: \n' + 'npm run create-schema');
|
} else {
|
||||||
resolve(true);
|
console.log('To create schema, use: \n' + 'npm run create-schema');
|
||||||
}
|
resolve(true);
|
||||||
});
|
}
|
||||||
} else
|
});
|
||||||
resolve(true);
|
} else
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user