From f0e6644b3802bda535b8ec715f972594dedc25ae Mon Sep 17 00:00:00 2001 From: SKP Date: Mon, 3 Jun 2019 16:34:15 +0200 Subject: [PATCH] Added installation info endpoint and data generation --- cyphernodeconf_docker/lib/app.js | 139 +++++++++++++++++- .../prompters/000_cyphernode.js | 2 +- .../templates/cyphernode/info.json | 1 + .../templates/gatekeeper/api.properties | 1 + dist/setup.sh | 1 + proxy_docker/app/script/requesthandler.sh | 10 ++ 6 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 cyphernodeconf_docker/templates/cyphernode/info.json diff --git a/cyphernodeconf_docker/lib/app.js b/cyphernodeconf_docker/lib/app.js index 93683a7..68ca394 100644 --- a/cyphernodeconf_docker/lib/app.js +++ b/cyphernodeconf_docker/lib/app.js @@ -134,14 +134,16 @@ module.exports = class App { this.config = new Config( { setup_version: this.sessionData.setup_version, docker_versions: { - 'gatekeeper': this.sessionData.gatekeeper_version, - 'proxy': this.sessionData.proxy_version, - 'proxycron': this.sessionData.proxycron_version, - 'pycoin': this.sessionData.pycoin_version, - 'otsclient': this.sessionData.otsclient_version, - 'bitcoincore': this.sessionData.bitcoin_version, - 'clightning': this.sessionData.lightning_version, - 'notifier': this.sessionData.notifier_version + 'cyphernode/bitcoin': this.sessionData.bitcoin_version, + 'cyphernode/gatekeeper': this.sessionData.gatekeeper_version, + 'cyphernode/proxy': this.sessionData.proxy_version, + 'cyphernode/proxycron': this.sessionData.proxycron_version, + 'cyphernode/pycoin': this.sessionData.pycoin_version, + 'cyphernode/otsclient': this.sessionData.otsclient_version, + 'cyphernode/clightning': this.sessionData.lightning_version, + 'cyphernode/notifier': this.sessionData.notifier_version, + 'traefik': 'v1.7.9-alpine', + 'eclipse-mosquitto': '1.6' } } ); @@ -338,6 +340,8 @@ module.exports = class App { } } + this.sessionData.installationInfo = this.installationInfo(); + for( let m of prompters ) { const name = m.name(); for( let t of m.templates(this.config.data) ) { @@ -378,6 +382,125 @@ module.exports = class App { } + installationInfo() { + + const core_features = [ + { + name: 'Bitcoin core node', + label: 'bitcoin', + host: 'bitcoin', + networks: ['cyphernodenet'], + docker: 'cyphernode/bitcoin:'+this.config.docker_versions['cyphernode/bitcoin'] + }, + { + name: 'Gatekeeper', + label: 'gatekeeper', + host: 'gatekeeper', + networks: ['cyphernodenet'], + docker: 'cyphernode/gatekeeper:'+this.config.docker_versions['cyphernode/gatekeeper'] + }, + { + name: 'Proxy', + label: 'proxy', + host: 'proxy', + networks: ['cyphernodenet'], + docker: 'cyphernode/proxy:'+this.config.docker_versions['cyphernode/proxy'] + }, + { + name: 'Proxy cron', + label: 'proxycron', + host: 'proxycron', + networks: ['cyphernodenet'], + docker: 'cyphernode/proxycron:'+this.config.docker_versions['cyphernode/proxycron'] + }, + { + name: 'Pycoin', + label: 'pycoin', + host: 'pycoin', + networks: ['cyphernodenet'], + docker: 'cyphernode/pycoin:'+this.config.docker_versions['cyphernode/pycoin'] + }, + { + name: 'Notifier', + label: 'notifier', + host: 'notifier', + networks: ['cyphernodenet', 'cyphernodeappsnet'], + docker: 'cyphernode/notifier:'+this.config.docker_versions['cyphernode/notifier'] + }, + { + name: 'MQ broker', + label: 'broker', + host: 'broker', + networks: ['cyphernodenet'], + docker: 'eclipse-mosquitto:'+this.config.docker_versions['eclipse-mosquitto'] + } + + ]; + + const optional_features = []; + + const optional_features_docker = { + otsclient: "cyphernode/otsclient:"+this.config.docker_versions['cyphernode/otsclient'], + lightning: "cyphernode/clightning:"+this.config.docker_versions['cyphernode/clightning'] + } + + for( let feature of this.features ) { + optional_features.push( { + active: feature.checked, + name: feature.name, + label: feature.value, + host: feature.value, + networks: ['cyphernodenet'], + docker: optional_features_docker[feature.value] + }); + } + + let bitcoin_version = this.config.docker_versions['cyphernode/bitcoin']; + + if( bitcoin_version[0] === 'v' ) { + bitcoin_version = bitcoin_version.substr(1); + } + + const cert = new Cert(); + const gatekeeper_cns = cert.cns( this.config.data.gatekeeper_cns ); + + const ii = { + api_versions: ['v0'], + setup_version: this.config.setup_version, + bitcoin_version: bitcoin_version, + core_features: core_features, + optional_features: optional_features, + devmode: this.sessionData.devmode, + bitcoin_prune: this.config.data.bitcoin_prune, + bitcoin_prune_size: this.config.data.bitcoin_prune_size, + bitcoin_expose: this.config.data.bitcoin_expose, + bitcoin_uacomment: this.config.data.bitcoin_uacomment, + gatekeeper_port: this.config.data.gatekeeper_port, + gatekeeper_cns: gatekeeper_cns + }; + + // add info about optional features + if( this.config.data.features.indexOf( 'lightning' ) != -1 ) { + ii.lightning_nodename = this.config.data.lightning_nodename; + ii.lightning_nodecolor = this.config.data.lightning_nodecolor; + ii.lightning_expose = this.config.data.lightning_expose; + ii.lightning_external_ip = this.config.data.lightning_external_ip; + ii.lightning_implementation = this.config.data.lightning_implementation; + + let clightning_version = this.config.docker_versions['cyphernode/clightning']; + + if( clightning_version[0] === 'v' ) { + clightning_version = clightning_version.substr(1); + } + + ii.clightning_version = clightning_version; + } + + console.log( ii ); + + return ii; + } + async prompt( questions ) { if( !questions ) { return {}; diff --git a/cyphernodeconf_docker/prompters/000_cyphernode.js b/cyphernodeconf_docker/prompters/000_cyphernode.js index e5c1ed4..c848730 100644 --- a/cyphernodeconf_docker/prompters/000_cyphernode.js +++ b/cyphernodeconf_docker/prompters/000_cyphernode.js @@ -83,6 +83,6 @@ module.exports = { }]; }, templates: function( props ) { - return []; + return ['info.json']; } }; diff --git a/cyphernodeconf_docker/templates/cyphernode/info.json b/cyphernodeconf_docker/templates/cyphernode/info.json new file mode 100644 index 0000000..186bb31 --- /dev/null +++ b/cyphernodeconf_docker/templates/cyphernode/info.json @@ -0,0 +1 @@ +<%- JSON.stringify( installationInfo, null, 2 ) %> \ No newline at end of file diff --git a/cyphernodeconf_docker/templates/gatekeeper/api.properties b/cyphernodeconf_docker/templates/gatekeeper/api.properties index d3834fb..25ff442 100644 --- a/cyphernodeconf_docker/templates/gatekeeper/api.properties +++ b/cyphernodeconf_docker/templates/gatekeeper/api.properties @@ -5,6 +5,7 @@ # Stats can: action_getblockchaininfo=stats +action_installation_info=stats # Watcher can: action_watch=watcher diff --git a/dist/setup.sh b/dist/setup.sh index 253f810..47c7992 100755 --- a/dist/setup.sh +++ b/dist/setup.sh @@ -404,6 +404,7 @@ install_docker() { fi copy_file $current_path/installer/config.sh $PROXY_DATAPATH/config.sh 1 $SUDO_REQUIRED + copy_file $current_path/cyphernode/info.json $PROXY_DATAPATH/info.json 1 $SUDO_REQUIRED if [[ $BITCOIN_INTERNAL == true ]]; then if [ ! -d $BITCOIN_DATAPATH ]; then diff --git a/proxy_docker/app/script/requesthandler.sh b/proxy_docker/app/script/requesthandler.sh index d2093f3..1630973 100644 --- a/proxy_docker/app/script/requesthandler.sh +++ b/proxy_docker/app/script/requesthandler.sh @@ -72,6 +72,16 @@ main() trace "[main] line=${line}" fi case "${cmd}" in + installation_info) + # GET http://192.168.111.152:8080/info + if [ -f "$DB_PATH/info.json" ]; then + response=$( cat "$DB_PATH/info.json" ) + else + response='{ "error": "missing installation data" }' + fi + response_to_client "${response}" ${?} + break + ;; watch) # POST http://192.168.111.152:8080/watch # BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","unconfirmedCallbackURL":"192.168.111.233:1111/callback0conf","confirmedCallbackURL":"192.168.111.233:1111/callback1conf"}