From 026603cfcb3742ec83ba7372fae896127dada250 Mon Sep 17 00:00:00 2001 From: jash Date: Fri, 19 Oct 2018 09:18:21 +0200 Subject: [PATCH] asking for runtime username --- .../generators/app/index.js | 20 +++++++++++++------ .../app/prompters/000_cyphernode.js | 8 ++++++++ .../app/templates/installer/config.sh | 1 + 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/install/generator-cyphernode/generators/app/index.js b/install/generator-cyphernode/generators/app/index.js index a2ced84..ff02fcb 100644 --- a/install/generator-cyphernode/generators/app/index.js +++ b/install/generator-cyphernode/generators/app/index.js @@ -9,6 +9,7 @@ const featureChoices = require(path.join(__dirname, "features.json")); const coinstring = require('coinstring'); const uaCommentRegexp = /^[a-zA-Z0-9 \.,:_\-\?\/@]+$/; // TODO: look for spec of unsafe chars +const userRegexp = /^[a-zA-Z0-9\._\-]+$/; const reset = '\u001B8\u001B[u'; const clear = '\u001Bc'; @@ -75,15 +76,15 @@ module.exports = class extends Generator { if( fs.existsSync(this.destinationPath('config.json')) ) { this.props = require(this.destinationPath('config.json')); } else { - this.props = { - 'derivation_path': '0/n', - 'installer': 'docker', - 'devmode': false, - 'devregistry': false - }; + this.props = {}; } + this.props.derivation_path = this.props.derivation_path || '0/n'; + this.props.installer = this.props.installer ||  'docker'; this.props.devmode = this.props.devmode || false; + this.props.devregistry = this.props.devregistry || false; + this.props.devmode = this.props.devmode || false; + this.props.username = this.props.username || 'cyphernode'; this.featureChoices = featureChoices; for( let c of this.featureChoices ) { @@ -187,6 +188,13 @@ module.exports = class extends Generator { return true; } + _usernameValidator( user ) { + if( !userRegexp.test( user ) ) { + throw new Error('Choose a valid username'); + } + return true; + } + _UACommentValidator( comment ) { if( !uaCommentRegexp.test( comment ) ) { throw new Error('Unsafe characters in UA comment. Please use only a-z, A-Z, 0-9, SPACE and .,:_?@'); diff --git a/install/generator-cyphernode/generators/app/prompters/000_cyphernode.js b/install/generator-cyphernode/generators/app/prompters/000_cyphernode.js index c283348..30838db 100644 --- a/install/generator-cyphernode/generators/app/prompters/000_cyphernode.js +++ b/install/generator-cyphernode/generators/app/prompters/000_cyphernode.js @@ -36,6 +36,14 @@ module.exports = { value: "mainnet" }] }, + { + type: 'input', + name: 'username', + default: utils._getDefault( 'username' ), + message: prefix()+'What username will cyphernode run under?'+'\n', + filter: utils._trimFilter, + validate: utils._usernameValidator + }, { type: 'input', name: 'xpub', diff --git a/install/generator-cyphernode/generators/app/templates/installer/config.sh b/install/generator-cyphernode/generators/app/templates/installer/config.sh index a06e790..b89579c 100644 --- a/install/generator-cyphernode/generators/app/templates/installer/config.sh +++ b/install/generator-cyphernode/generators/app/templates/installer/config.sh @@ -8,3 +8,4 @@ BITCOIN_DATAPATH=<%= bitcoin_datapath %> LIGHTNING_DATAPATH=<%= lightning_datapath %> PROXY_DATAPATH=<%= proxy_datapath %> DOCKER_MODE=<%= docker_mode %> +USERNAME=<%= username %>