diff --git a/CHANGELOG.md b/CHANGELOG.md index e4c66289..b6f1bf6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to the Zlux App Server package will be documented in this file. +## v2.10.0 + +- Enhancement: Migrated app-server configuration options into a "defaults.yaml" file which adheres to the schema of the Zowe config. This allows users to see the default behaviors more clearly, and can serve as an example by which users can customize their Zowe config to override such defaults. (#247) +- Bugfix: Fixed the URLs app-server would print in the logs describing where it was accessible from. Messages were incorrectly pointing at the discovery server instead of the gateway server. (#247) + ## v2.9.0 - Bugfix: Recognizers from multiple plugins could not be merged due to an error in the merge code execution at startup. diff --git a/bin/app-server.sh b/bin/app-server.sh index eccb81f4..1277a7cd 100755 --- a/bin/app-server.sh +++ b/bin/app-server.sh @@ -7,119 +7,4 @@ # # Copyright Contributors to the Zowe Project. - -# Required variables on shell: -# - ZWE_zowe_runtimeDirectory -# - ZWE_zowe_workspaceDirectory -# - NODE_HOME -# -# Optional variables on shell: -# - APIML_ENABLE_SSO -# - GATEWAY_PORT -# - DISCOVERY_PORT -# - ZWED_SSH_PORT -# - ZWED_TN3270_PORT -# - ZWED_TN3270_SECURITY - -if [ -z "${ZWE_zowe_runtimeDirectory}" ] -then - #this may be a dev environment, or backward compat, so stay in current dir and check node - . ./validate.sh -fi - -if [ ! -e "${dir}/utils/convert-env.sh" ] -then - if [ -n "$CONDA_PREFIX" ] - then - dir="$CONDA_PREFIX/share/zowe/app-server/zlux-app-server/bin" - cd $dir - fi -fi - -. ./utils/convert-env.sh -. ./init/node-init.sh - -if [ -e "$ZLUX_CONFIG_FILE" ] -then - CONFIG_FILE=$ZLUX_CONFIG_FILE -elif [ -e "$ZWE_CLI_PARAMETER_CONFIG" ] -then - CONFIG_FILE="$ZWE_CLI_PARAMETER_CONFIG" -elif [ -z "${ZWE_zowe_runtimeDirectory}" ] -then - #dev env or backwards compat, do late configure - # should we also export ZWE_zowe_workspaceDirectory=~/.zowe/zowe.yaml? - # potentially zowe.yaml in there could point workspaceDirectory elsewhere to cause further confusion - . ./init/workspace-init.sh - CONFIG_FILE=~/.zowe/zowe.yaml -fi - -# Will skip log trimming if ZWED_NODE_LOG_FILE already defined (such as by start.sh) -. ./utils/setup-logs.sh - -#Determined log file. Run node appropriately. -cd ../lib - -export ZOWE_LIB_DIR=$(pwd) -export ZLUX_ROOT_DIR=$(cd ../..; pwd) - -export "_CEE_RUNOPTS=XPLINK(ON),HEAPPOOLS(ON)" - -echo Show Environment -env - -if [ -z "$ZOWE_WORKING_DIR" ] -then - export ZOWE_WORKING_DIR=$ZOWE_LIB_DIR -else - echo "Server is about to start with a non default working directory. Working dir=$ZOWE_WORKING_DIR" -fi - -cd $ZOWE_WORKING_DIR - -export ZWED_NODE_LOG_FILE=$ZWED_NODE_LOG_FILE - -echo Starting node -if [ -z "$ZLUX_NO_CLUSTER" ] -then - ZLUX_SERVER_FILE=zluxCluster.js - if [ -z "$ZLUX_MIN_WORKERS" ] - then - export ZLUX_MIN_WORKERS=2 - fi -else - ZLUX_SERVER_FILE=zluxServer.js -fi - -# Tells node whether to prefer ipv4 or ipv6 results to DNS lookups -ZLUX_DNS_ORDER="--dns-result-order=ipv4first" -if [ "$ZWE_components_app_server_dns_lookupOrder" = "ipv6" ]; then - ZLUX_DNS_ORDER="--dns-result-order=verbatim" -fi - -# not all versions of node support the above (14.18+ generally) so we can just try it to see what happens. -v4_check=$(${NODE_BIN} ${ZLUX_DNS_ORDER} -e "console.log('success');") -if [ "${v4_check}" != "success" ]; then - ZLUX_DNS_ORDER= -fi - -if [ -z "$ZLUX_NO_LOGFILE" ]; then - __UNTAGGED_READ_MODE=V6 \ - _BPX_JOBNAME=${ZOWE_PREFIX}DS \ - ${NODE_BIN} \ - --harmony \ - ${ZLUX_DNS_ORDER} \ - ${ZOWE_LIB_DIR}/${ZLUX_SERVER_FILE} \ - --config="${CONFIG_FILE}" "$@" 2>&1 | tee $ZWED_NODE_LOG_FILE -else - __UNTAGGED_READ_MODE=V6 \ - _BPX_JOBNAME=${ZOWE_PREFIX}DS \ - ${NODE_BIN} \ - --harmony \ - ${ZLUX_DNS_ORDER} \ - ${ZOWE_LIB_DIR}/${ZLUX_SERVER_FILE} \ - --config="${CONFIG_FILE}" "$@" - echo "Ended with rc=$?" -fi - - +./start.sh diff --git a/bin/configure.sh b/bin/configure.sh index ec367a54..ec64045e 100755 --- a/bin/configure.sh +++ b/bin/configure.sh @@ -22,10 +22,38 @@ if [ "${ZWE_RUN_ON_ZOS}" != "true" ]; then fi cd ${COMPONENT_HOME}/share/zlux-app-server/bin -. ./utils/convert-env.sh + +if [ -n "$ZWE_components_app_server_node_mediationLayer_enabled" -a -z "$ZWE_components_app_server_agent_mediationLayer_enabled" ]; then + if [ "${ZWE_RUN_ON_ZOS}" != "true" ]; then + zss_def_template="zss.apiml_static_reg.yaml.template" + zss_configured=false + if [ -n "${ZWE_components_app_server_agent_https_port}" ]; then + export ZSS_PORT="${ZWE_components_app_server_agent_https_port}" + export ZSS_PROTOCOL=https + zss_configured=true + elif [ -n "${ZWED_components_app_server_agent_http_port}" ]; then + export ZSS_PORT="${ZWE_components_app_server_http_port}" + export ZSS_PROTOCOL=http + zss_configured=true + fi + + if [ "${zss_configured}" = "true" ] && [ -n "${ZWE_STATIC_DEFINITIONS_DIR}" ]; then + zss_registration_yaml=${ZWE_STATIC_DEFINITIONS_DIR}/zss.apiml_static_reg_yaml_template.${ZWE_CLI_PARAMETER_HA_INSTANCE}.yml + zss_def="../${zss_def_template}" + zss_parsed_def=$( ( echo "cat <&1) + echo "${zss_parsed_def}" > "${zss_registration_yaml}" + chmod 770 "${zss_registration_yaml}" + fi + + unset ZSS_PORT + unset ZSS_PROTOCOL + fi +fi + + . ./init/node-init.sh cd ../lib -__UNTAGGED_READ_MODE=V6 $NODE_BIN initInstance.js +CONFIG_FILE=$ZWE_CLI_PARAMETER_CONFIG $NODE_BIN initInstance.js cd ${COMPONENT_HOME}/share/zlux-app-server/bin/init if [ "${ZWE_zowe_useConfigmgr}" = "true" ]; then diff --git a/bin/init/node-init.sh b/bin/init/node-init.sh index 2a77f9fd..663d1df2 100644 --- a/bin/init/node-init.sh +++ b/bin/init/node-init.sh @@ -1,37 +1,28 @@ -if [ -n "$NODE_HOME" ] -then - NODE_BIN=${NODE_HOME}/bin/node +#!/bin/sh +# This program and the accompanying materials are +# made available under the terms of the Eclipse Public License v2.0 which accompanies +# this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html +# +# SPDX-License-Identifier: EPL-2.0 +# +# Copyright Contributors to the Zowe Project. + +if [ -n "$NODE_HOME" ]; then + export NODE_BIN=${NODE_HOME}/bin/node export PATH=${NODE_HOME}/bin:$PATH -elif [ -n "$ZOWE_NODE_HOME" ] -then - NODE_BIN=${ZOWE_NODE_HOME}/bin/node - export PATH=${ZOWE_NODE_HOME}/bin:$PATH else - NODE_BIN=node + export NODE_BIN=node fi -export NODE_BIN - -if [ ! -e "${ZWE_zowe_runtimeDirectory}/bin/internal/zowe-set-env.sh" ]; then - RUN_ON_ZOS=$(test `uname` = "OS/390" && echo "true") - if [ "${RUN_ON_ZOS}" = "true" ]; then - export "_CEE_RUNOPTS=XPLINK(ON),HEAPPOOLS(ON)" - export _BPXK_AUTOCVT=ON - export __UNTAGGED_READ_MODE=V6 - - nodeVersion="$(${NODE_BIN} --version)" - nodeMajorVersion=$(echo ${nodeVersion} | cut -c2-3) - if [ $nodeMajorVersion -ge "12" ] - then - export _TAG_REDIR_ERR=txt - export _TAG_REDIR_IN=txt - export _TAG_REDIR_OUT=txt - fi - - fi -else - . ${ZWE_zowe_runtimeDirectory}/bin/internal/zowe-set-env.sh -fi +# These are used on z/OS and ignored elsewhere. +# Some are already applied by zwe, but in dev, we add them. +# They control text encoding primarily. +export "_CEE_RUNOPTS=XPLINK(ON),HEAPPOOLS(ON)" +export _BPXK_AUTOCVT=ON +export __UNTAGGED_READ_MODE=V6 +export _TAG_REDIR_ERR=txt +export _TAG_REDIR_IN=txt +export _TAG_REDIR_OUT=txt export NODE_PATH=../..:../../zlux-server-framework/node_modules:$NODE_PATH diff --git a/bin/init/workspace-init.sh b/bin/init/workspace-init.sh index afefb59d..59e2aa29 100644 --- a/bin/init/workspace-init.sh +++ b/bin/init/workspace-init.sh @@ -10,32 +10,4 @@ #ZLUX_CONFIG_FILE and ZWE_zowe_workspaceDirectory are for official Zowe environment use. #If none found, will assume dev environment and consider ~/.zowe/workspace as ZWE_zowe_workspaceDirectory -if [ -n "${ZWE_zowe_workspaceDirectory}" ] -then - if [ -e "${ZWE_zowe_workspaceDirectory}/app-server/serverConfig/zowe.yaml" ] - then - export CONFIG_FILE="${ZWE_zowe_workspaceDirectory}/app-server/serverConfig/zowe.yaml" - else - cd ../../lib - __UNTAGGED_READ_MODE=V6 $NODE_BIN initInstance.js - export CONFIG_FILE="${ZWE_zowe_workspaceDirectory}/app-server/serverConfig/zowe.yaml" - fi -elif [ -e "${HOME}/.zowe/workspace/app-server/serverConfig/zowe.yaml" ] -then - export CONFIG_FILE="${HOME}/.zowe/workspace/app-server/serverConfig/zowe.yaml" - if [ -z "${ZWE_zowe_logDirectory}" ]; then - export ZWE_zowe_logDirectory="${HOME}/.zowe/logs" - fi - mkdir -p ${ZWE_zowe_logDirectory} - export WORKSPACE_DIR="${HOME}/.zowe/workspace" -else - echo "No config file found, initializing..." - export WORKSPACE_DIR="${HOME}/.zowe/workspace" - if [ -z "${ZWE_zowe_logDirectory}" ]; then - export ZWE_zowe_logDirectory="${HOME}/.zowe/logs" - fi - mkdir -p ${ZWE_zowe_logDirectory} - cd ../../lib - __UNTAGGED_READ_MODE=V6 $NODE_BIN initInstance.js - export CONFIG_FILE="${HOME}/.zowe/workspace/app-server/serverConfig/zowe.yaml" -fi + diff --git a/bin/install-app.sh b/bin/install-app.sh index d72cc089..b535c3d1 100755 --- a/bin/install-app.sh +++ b/bin/install-app.sh @@ -7,10 +7,9 @@ # # Copyright Contributors to the Zowe Project. -if [ $# -eq 0 ] - then - echo "Usage: $0 AppPath [PluginsDir]" - exit 1 +if [ $# -eq 0 ]; then + echo "Usage: $0 AppPath [PluginsDir]" + exit 1 fi setVars() { @@ -21,12 +20,7 @@ setVars() { . ${zlux_path}/zlux-app-server/bin/init/node-init.sh } -dir=$(cd `dirname $0` && pwd) -. ${dir}/utils/plugin-utils.sh -. ${dir}/utils/convert-env.sh - -if [ -n "${ZWE_zowe_workspaceDirectory}" -a -n "${ZWE_zowe_runtimeDirectory}" ] -then +if [ -n "${ZWE_zowe_workspaceDirectory}" -a -n "${ZWE_zowe_runtimeDirectory}" ]; then COMPONENT_HOME=${ZWE_zowe_runtimeDirectory}/components/app-server # containers only @@ -41,26 +35,24 @@ then if [ -z "$INSTALL_NO_NODE" ]; then zlux_path="$COMPONENT_HOME/share" setVars - if [ ! -d "${ZWE_zowe_workspaceDirectory}/app-server" ] - then + if [ ! -e "${ZWE_zowe_workspaceDirectory}/app-server/plugins/org.zowe.zlux.json" ]; then cd ${zlux_path}/zlux-app-server/lib - __UNTAGGED_READ_MODE=V6 $NODE_BIN initInstance.js + CONFIG_FILE=$ZWE_CLI_PARAMETER_CONFIG $NODE_BIN initInstance.js fi fi -elif [ -d "${dir}/../../zlux-server-framework" ] -then +else zlux_path=$(cd $(dirname "$0")/../..; pwd) setVars -elif [ -n "$CONDA_PREFIX" ] -then - zlux_path="$CONDA_PREFIX/share/zowe/app-server" - setVars fi +. ${zlux_path}/zlux-app-server/bin/utils/plugin-utils.sh + + + utils_path=$zlux_path/zlux-server-framework/utils -app_path=$(cd "$1"; pwd) -if [ $# -gt 1 ] -then +#app_path=$(cd "$1"; pwd) +app_path=$1 +if [ $# -gt 1 ]; then plugin_dir=$2 shift else @@ -75,13 +67,13 @@ if [ -z "$plugin_dir" ]; then fi mkdir -p $plugin_dir + # Installs a zowe plugin by finding its ID and writing the locator json WITHOUT using install-app.js # This is to be used in cases where there are issues using JS, or nodejs is not found. # Input: relative or fully qualified path to a directory containing a plugindir=$(cd `dirname $0` && pwd) installNojs() { id=$(getPluginID "${app_path}") - if [ -n "${id}" ] - then + if [ -n "${id}" ]; then echo "Found plugin=${id}" cat <${plugin_dir}/${id}.json @@ -92,53 +84,47 @@ cat <${plugin_dir}/${id}.json EOF echo "Plugin registration ended with rc=$?" - if [ -f "${plugin_dir}/${id}.json" ] - then + if [ -f "${plugin_dir}/${id}.json" ]; then chmod 0771 "${plugin_dir}/${id}.json" fi else - echo "Error: could not find plugin id for path=${app_path}" - exit 1 + echo "Error: could not find plugin id for path=${app_path}" + exit 1 fi } -if [ -n "$INSTALL_NO_NODE" ] -then - installNojs -else + +if [ -n "$INSTALL_NO_NODE" ]; then + installNojs +else cd $zlux_path/zlux-app-server/bin echo "Testing if node exists" type ${NODE_BIN} rc=$? - if [ $rc -ne 0 ] - then + if [ $rc -ne 0 ]; then installNojs else -# normal case follows -if [ -z "$ZLUX_INSTALL_LOG_DIR" ] -then - if [ -d "${ZWE_zowe_logDirectory}" ] - then - ZLUX_INSTALL_LOG_DIR="$ZWE_zowe_logDirectory" - fi -fi + # normal case follows + if [ -z "$ZLUX_INSTALL_LOG_DIR" ]; then + if [ -d "${ZWE_zowe_logDirectory}" ]; then + ZLUX_INSTALL_LOG_DIR="$ZWE_zowe_logDirectory" + fi + fi -PLUGIN_LOG_FILE=/dev/null -if [ ! -z "$ZLUX_INSTALL_LOG_DIR" ] -then - if [ ! -d "$ZLUX_INSTALL_LOG_DIR" ] - then - echo "Will make log directory $ZLUX_INSTALL_LOG_DIR" - mkdir -p $ZLUX_INSTALL_LOG_DIR - fi - PLUGIN_LOG_FILE="$ZLUX_INSTALL_LOG_DIR/install-app.log" -fi + PLUGIN_LOG_FILE=/dev/null + if [ ! -z "$ZLUX_INSTALL_LOG_DIR" ]; then + if [ ! -d "$ZLUX_INSTALL_LOG_DIR" ]; then + echo "Will make log directory $ZLUX_INSTALL_LOG_DIR" + mkdir -p $ZLUX_INSTALL_LOG_DIR + fi + PLUGIN_LOG_FILE="$ZLUX_INSTALL_LOG_DIR/install-app.log" + fi -echo "Running app-server plugin registration. Log=$PLUGIN_LOG_FILE" -echo "utils_path=${utils_path}\napp_path=${app_path}" -echo "plugin_dir=${plugin_dir}" -{ __UNTAGGED_READ_MODE=V6 ${NODE_BIN} ${utils_path}/install-app.js -i "$app_path" -p "$plugin_dir" $@ 2>&1 ; echo "Plugin registration ended with rc=$?" ; } | tee -a $PLUGIN_LOG_FILE -fi + echo "Running app-server plugin registration. Log=$PLUGIN_LOG_FILE" + echo "utils_path=${utils_path}\napp_path=${app_path}" + echo "plugin_dir=${plugin_dir}" + { ${NODE_BIN} ${utils_path}/install-app.js -i "$app_path" -p "$plugin_dir" $@ 2>&1 ; echo "Plugin registration ended with rc=$?" ; } | tee -a $PLUGIN_LOG_FILE + fi fi diff --git a/bin/start.sh b/bin/start.sh index 749ef506..c8d5510d 100755 --- a/bin/start.sh +++ b/bin/start.sh @@ -12,19 +12,9 @@ # - ZWE_zowe_runtimeDirectory # - ZWE_zowe_workspaceDirectory # - NODE_HOME -# -# Optional variables on shell: -# - APIML_ENABLE_SSO -# - GATEWAY_PORT -# - DISCOVERY_PORT -# - ZWED_SSH_PORT -# - ZWED_TN3270_PORT -# - ZWED_TN3270_SECURITY - -if [ -n "${ZWE_zowe_runtimeDirectory}" ] -then - #not a dev env +if [ -n "${ZWE_zowe_runtimeDirectory}" ]; then + # not a dev env COMPONENT_HOME=${ZWE_zowe_runtimeDirectory}/components/app-server # containers only @@ -34,12 +24,98 @@ then fi fi - cd ${COMPONENT_HOME}/share/zlux-app-server/bin + # used for relativeTo plugins + export ZLUX_ROOT_DIR=$COMPONENT_HOME/share +else + # dev env + . ./validate.sh + COMPONENT_HOME=$(cd ../..; pwd) + + # used for relativeTo plugins + export ZLUX_ROOT_DIR=$COMPONENT_HOME fi +ZLUX_APP_SERVER_DIR=${ZLUX_ROOT_DIR}/zlux-app-server +cd ${ZLUX_APP_SERVER_DIR}/bin + +. ./init/node-init.sh . ./utils/setup-logs.sh -# Done to prevent app-server from making a logfile since we will be making one here instead. -export ZLUX_NO_LOGFILE=1 +# Get config path or fail +if [ -z "${ZWE_CLI_PARAMETER_CONFIG}" ]; then + echo "ZWE_CLI_PARAMETER_CONFIG is not defined. Only defaults will be used." + echo "To customize, rerun script with it defined to a list of paths to zowe.yaml files such as ZWE_CLI_PARAMETER_CONFIG=FILE(/yaml1.yaml):FILE(/path/to/yaml2.yaml)" + echo "FILE items specified on the right of the list will have properties overridden by FILE items on the left of the list, resulting in one merged configuration" + if [ -e "${HOME}/.zowe/zowe.yaml" ]; then + echo "Found and using ${HOME}/.zowe/zowe.yaml" + else + mkdir -p ${HOME}/.zowe + cp ${ZLUX_APP_SERVER_DIR}/defaults/serverConfig/defaults.yaml ${HOME}/.zowe/zowe.yaml + fi + CONFIG_FILE="FILE(${HOME}/.zowe/zowe.yaml):FILE(${ZLUX_APP_SERVER_DIR}/defaults/serverConfig/defaults.yaml)" +else + # Note in production, ZWE_CLI_PARAMETER_CONFIG is already a merged file, so no concern about PARMLIB here. + CONFIG_FILE="FILE(${ZWE_CLI_PARAMETER_CONFIG}):FILE(${ZLUX_APP_SERVER_DIR}/defaults/serverConfig/defaults.yaml)" +fi + +if [ -z "${ZWE_zowe_runtimeDirectory}" ]; then + # dev env or backwards compat, do late configure + if [ -z "${ZWE_zowe_workspaceDirectory}" ]; then + export ZWE_zowe_workspaceDirectory="${HOME}/.zowe/workspace" + fi + if [ ! -e "${ZWE_zowe_workspaceDirectory}/app-server/plugins/org.zowe.zlux.json}" ]; then + cd ${ZLUX_APP_SERVER_DIR}/lib + $NODE_BIN initInstance.js + fi +fi + +if [ -z "$ZLUX_NO_CLUSTER" ]; then + ZLUX_SERVER_FILE=zluxCluster.js + export ZLUX_MIN_WORKERS=${ZLUX_MIN_WORKERS:-2} +else + ZLUX_SERVER_FILE=zluxServer.js +fi + +if [ "$ZWE_zowe_verifyCertificates" = "DISABLED" ]; then + export NODE_TLS_REJECT_UNAUTHORIZED=0 +fi + +# set production mode if applicable +export NODE_ENV=${NODE_ENV:-production} + +echo Show Environment +env + +cd ${ZLUX_APP_SERVER_DIR}/lib +echo Starting node + +# Tells node whether to prefer ipv4 or ipv6 results to DNS lookups +ZLUX_DNS_ORDER="--dns-result-order=ipv4first" +if [ "$ZWE_components_app_server_dns_lookupOrder" = "ipv6" ]; then + ZLUX_DNS_ORDER="--dns-result-order=verbatim" +fi -./app-server.sh 2>&1 | tee $ZWED_NODE_LOG_FILE +# not all versions of node support the above (14.18+ generally) so we can just try it to see what happens. +v4_check=$(${NODE_BIN} ${ZLUX_DNS_ORDER} -e "console.log('success');") +if [ "${v4_check}" != "success" ]; then + ZLUX_DNS_ORDER= +fi + +if [ -z "${ZWED_FLAGS}" ]; then + ZWED_FLAGS="${ZLUX_DNS_ORDER} --harmony " +fi + +if [ -z "$ZLUX_NO_LOGFILE" ]; then + _BPX_JOBNAME=${ZWE_zowe_job_prefix}DS \ + ${NODE_BIN} \ + ${ZWED_FLAGS} \ + ${ZLUX_APP_SERVER_DIR}/lib/${ZLUX_SERVER_FILE} \ + --config="${CONFIG_FILE}" "$@" 2>&1 | tee $ZWED_NODE_LOG_FILE +else + _BPX_JOBNAME=${ZWE_zowe_job_prefix}DS \ + ${NODE_BIN} \ + ${ZWED_FLAGS} \ + ${ZLUX_APP_SERVER_DIR}/lib/${ZLUX_SERVER_FILE} \ + --config="${CONFIG_FILE}" "$@" + echo "Ended with rc=$?" +fi diff --git a/bin/utils/convert-env.sh b/bin/utils/convert-env.sh deleted file mode 100755 index 4b91f482..00000000 --- a/bin/utils/convert-env.sh +++ /dev/null @@ -1,401 +0,0 @@ -#!/bin/sh -# This program and the accompanying materials are -# made available under the terms of the Eclipse Public License v2.0 which accompanies -# this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html -# -# SPDX-License-Identifier: EPL-2.0 -# -# Copyright Contributors to the Zowe Project. - -OSNAME=$(uname) - -convert_v2_to_v1() { - while read old_name new_name; do - old_val=$(eval echo "\$${old_name}") - new_val=$(eval echo "\$${new_name}") - if [ -z "${old_val}" -a -n "${new_val}" ]; then - export "${old_name}=${new_val}" - fi - done <&1) - echo "${zss_parsed_def}" > "${zss_registration_yaml}" - chmod 770 "${zss_registration_yaml}" - export ZWED_agent_mediationLayer_enabled="true" - else - export ZWED_agent_mediationLayer_enabled="false" - fi - - unset ZSS_PORT - unset ZSS_PROTOCOL - fi -fi - -# Check if Caching Service is enabled -if [ "$ZWED_node_mediationLayer_enabled" = "true" -a "${ZWE_components_caching_service_enabled}" = "true" ]; then - export ZWED_node_mediationLayer_cachingService_enabled="true" -fi - -# eureka hostname handling -if [ -z "$ZWED_node_hostname" ]; then - if [ -n "$ZWE_INTERNAL_HOST" ]; then - export ZWED_node_hostname=$ZWE_INTERNAL_HOST - elif [ -n "$ZOWE_EXPLORER_HOST" ]; then - export ZWED_node_hostname=$ZOWE_EXPLORER_HOST - fi -fi - -if [ -n "$ZOWE_LOOPBACK_ADDRESS" ] -then - if [ -n "$ZOWE_IP_ADDRESS" ] - then - if [ "$BIND_TO_LOOPBACK" = "true" ] - then - export ZWED_node_https_ipAddresses="${ZOWE_LOOPBACK_ADDRESS},${ZOWE_IP_ADDRESS}", - fi - fi - export ZWED_node_loopbackAddress=$ZOWE_LOOPBACK_ADDRESS -fi - -if [ -z "$ZWED_node_https_ipAddresses" ] -then - if [ -n "$ZOWE_IP_ADDRESS" ] - then - export ZWED_node_https_ipAddresses="${ZOWE_IP_ADDRESS}", - fi -fi - -# certificates -if [ "$ZWE_zowe_verifyCertificates" = "DISABLED" ]; then - export ZWED_node_allowInvalidTLSProxy=true - export NODE_TLS_REJECT_UNAUTHORIZED=0 -fi - -if [ -z "$ZWED_node_https_certificates" ] -then - if [ "$KEYSTORE_TYPE" = "JCERACFKS" ] - then - #, at end turns it into an array - export ZWED_node_https_certificates="${KEYSTORE}&${KEY_ALIAS}", - elif [ -n "$KEYSTORE_CERTIFICATE" ] - then - #, at end turns it into an array - export ZWED_node_https_certificates=$KEYSTORE_CERTIFICATE, - fi -fi - -if [ -z "$ZWED_node_https_certificateAuthorities" ]; then - if [ "$ZWE_zowe_certificate_truststore_type" = "JCERACFKS" ]; then - #, at end turns it into an array - # zfs will do ca lookup from truststore - export ZWED_node_https_certificateAuthorities=${ZWE_zowe_certificate_truststore_file}, - elif [ -n "$KEYSTORE_CERTIFICATE_AUTHORITY" ]; then - #, at end turns it into an array - export ZWED_node_https_certificateAuthorities=${KEYSTORE_CERTIFICATE_AUTHORITY}, - fi -fi - -if [ -z "$ZWED_node_https_keys" ] -then - if [ "$KEYSTORE_TYPE" = "JCERACFKS" ] - then - #, at end turns it into an array - export ZWED_node_https_keys="${KEYSTORE}&${KEY_ALIAS}", - elif [ -n "$KEYSTORE_KEY" ] - then - #, at end turns it into an array - export ZWED_node_https_keys=$KEYSTORE_KEY, - fi -fi - -#SSO -if [ -z "$ZWED_agent_jwt_fallback" ] -then - if [ -n "$SSO_FALLBACK_TO_NATIVE_AUTH" ] - then - export ZWED_agent_jwt_fallback=$SSO_FALLBACK_TO_NATIVE_AUTH - fi -fi - -# app server -if [ -z "$ZWED_SERVER_HTTPS_PORT" -a -n "$ZOWE_ZLUX_SERVER_HTTPS_PORT" ] -then - export ZWED_SERVER_HTTPS_PORT="${ZOWE_ZLUX_SERVER_HTTPS_PORT}" -fi -if [ -z "$ZWED_node_https_port" ] -then - if [ -n "$ZWED_SERVER_HTTPS_PORT" ] - then - export ZWED_node_https_port=$ZWED_SERVER_HTTPS_PORT - fi -fi -if [ -z "$ZWED_productDir" ] -then - if [ -n "$ROOT_DIR" ] - then - COMPONENT_HOME=${ROOT_DIR}/components/app-server - - # containers only - if [ "${ZWE_RUN_ON_ZOS}" != "true" ]; then - if [ -f "/component/manifest.yaml" ]; then - COMPONENT_HOME=/component - if [ -z "$ZWED_node_pluginScanIntervalSec" ]; then - # container needs plugin scanning logic on - export ZWED_node_pluginScanIntervalSec=60 - fi - fi - fi - export ZWED_productDir=$COMPONENT_HOME/share/zlux-app-server/defaults - fi -fi - -# v2 alias mapping -if [ -z "$ZWED_NODE_LOG_FILE" -a -n "$ZLUX_NODE_LOG_FILE" ] -then - export ZWED_NODE_LOG_FILE="${ZLUX_NODE_LOG_FILE}" -fi -if [ -z "$ZWED_NODE_LOG_DIR" -a -n "$ZLUX_NODE_LOG_DIR" ] -then - export ZWED_NODE_LOG_DIR="${ZLUX_NODE_LOG_DIR}" -fi -if [ -z "$ZWED_NODE_LOGS_TO_KEEP" -a -n "$ZLUX_NODE_LOGS_TO_KEEP" ] -then - export ZWED_NODE_LOGS_TO_KEEP="${ZLUX_NODE_LOGS_TO_KEEP}" -fi -if [ -z "$ZWED_SSH_PORT" -a -n "$ZOWE_ZLUX_SSH_PORT" ] -then - export ZWED_SSH_PORT="${ZOWE_ZLUX_SSH_PORT}" -fi -if [ -z "$ZWED_TN3270_PORT" -a -n "$ZOWE_ZLUX_TELNET_PORT" ] -then - export ZWED_TN3270_PORT="${ZOWE_ZLUX_TELNET_PORT}" -fi -if [ -z "$ZWED_TN3270_SECURITY" -a -n "$ZOWE_ZLUX_SECURITY_TYPE" ] -then - export ZWED_TN3270_SECURITY="${ZOWE_ZLUX_SECURITY_TYPE}" -fi -if [ -z "$ZWED_SSH_HOST" -a -n "$ZOWE_ZLUX_SSH_HOST" ] -then - export ZWED_SSH_HOST="${ZOWE_ZLUX_SSH_HOST}" -fi -if [ -z "$ZWED_TN3270_HOST" -a -n "$ZOWE_ZLUX_TELNET_HOST" ] -then - export ZWED_TN3270_HOST="${ZOWE_ZLUX_TELNET_HOST}" -fi -if [ -z "$ZWED_TN3270_ROW" -a -n "$ZOWE_ZLUX_TN3270_ROW" ] -then - export ZWED_TN3270_ROW="${ZOWE_ZLUX_TN3270_ROW}" -fi -if [ -z "$ZWED_TN3270_COL" -a -n "$ZOWE_ZLUX_TN3270_COL" ] -then - export ZWED_TN3270_COL="${ZOWE_ZLUX_TN3270_COL}" -fi -if [ -z "$ZWED_TN3270_MOD" -a -n "$ZOWE_ZLUX_TN3270_MOD" ] -then - export ZWED_TN3270_MOD="${ZOWE_ZLUX_TN3270_MOD}" -fi -if [ -z "$ZWED_TN3270_CODEPAGE" -a -n "$ZOWE_ZLUX_TN3270_CODEPAGE" ] -then - export ZWED_TN3270_CODEPAGE="${ZOWE_ZLUX_TN3270_CODEPAGE}" -fi -# zss -if [ -z "$ZWES_SERVER_PORT" -a -n "$ZOWE_ZSS_SERVER_PORT" ] -then - export ZWES_SERVER_PORT="${ZOWE_ZSS_SERVER_PORT}" -fi -if [ -z "$ZWES_SERVER_TLS" -a -n "$ZOWE_ZSS_SERVER_TLS" ] -then - export ZWES_SERVER_TLS="${ZOWE_ZSS_SERVER_TLS}" -fi -if [ "$ZWES_SERVER_TLS" = "false" ] -then - # HTTP - if [ -z "$ZWED_agent_http_port" -a -n "$ZWES_SERVER_PORT" ] - then - export ZWED_agent_http_port="${ZWES_SERVER_PORT}" - fi -else - # HTTPS - if [ -z "$ZWED_agent_https_port" -a -n "$ZWES_SERVER_PORT" ] - then - export ZWED_agent_https_port="${ZWES_SERVER_PORT}" - fi - if [ -z "$ZWED_agent_host" -a -n "$ZOWE_EXPLORER_HOST" ] - then - export ZWED_agent_host="${ZOWE_EXPLORER_HOST}" - fi -fi -if [ -z "$ZWES_XMEM_SERVER_NAME" -a -n "$ZOWE_ZSS_XMEM_SERVER_NAME" ] -then - export ZWES_XMEM_SERVER_NAME="${ZOWE_ZSS_XMEM_SERVER_NAME}" -fi -if [ -z "$ZWED_privilegedServerName" ] -then - if [ -n "$ZWES_XMEM_SERVER_NAME" ] - then - export ZWED_privilegedServerName=$ZWES_XMEM_SERVER_NAME - fi -fi -if [ -z "$ZWES_LOG_FILE" -a -n "$ZSS_LOG_FILE" ] -then - export ZWES_LOG_FILE="${ZSS_LOG_FILE}" -fi -if [ -z "$ZWES_LOG_DIR" -a -n "$ZSS_LOG_DIR" ] -then - export ZWES_LOG_DIR="${ZSS_LOG_DIR}" -fi -if [ -z "$ZWES_LOGS_TO_KEEP" -a -n "$ZSS_LOGS_TO_KEEP" ] -then - export ZWES_LOGS_TO_KEEP="${ZSS_LOGS_TO_KEEP}" -fi -# cert verification -if [ -z "$ZWED_node_allowInvalidTLSProxy" -a -n "$VERIFY_CERTIFICATES" ]; then - if [ "$VERIFY_CERTIFICATES" = "false" ]; then - export ZWED_node_allowInvalidTLSProxy="true" - fi -fi - -# set production mode if applicable -if [ -n "$ROOT_DIR" -a -z "$NODE_ENV" ]; then - export NODE_ENV=production -fi - -# v2 logging -if [ -n "$ZWE_zowe_logDirectory" ]; then - if [ -z "$ZWED_NODE_LOG_DIR" ]; then - export ZWED_NODE_LOG_DIR="$ZWE_zowe_logDirectory" - fi - if [ -z "$ZWES_LOG_DIR" ]; then - export ZWES_LOG_DIR="$ZWE_zowe_logDirectory" - fi -fi - -if [ -n "$ZWE_zowe_workspaceDirectory" ] -then - WORKSPACE_LOCATION=$ZWE_zowe_workspaceDirectory -else - WORKSPACE_LOCATION="$HOME/.zowe/workspace" -fi -DESTINATION="$WORKSPACE_LOCATION/app-server" - - -if [ -z "$ZWE_components_app_server_productDir" ]; then - if [ -n "${ZWE_zowe_runtimeDirectory}" ]; then - export ZWED_productDir=$(cd "$ZWE_zowe_runtimeDirectory/components/app-server/share/zlux-app-server/defaults" && pwd) - else - export ZWED_productDir=$(cd "$PWD/../defaults" && pwd) - fi -fi -if [ -z "$ZWE_components_app_server_siteDir" ]; then - export ZWED_siteDir="$DESTINATION/site" -fi -if [ -z "$ZWE_components_app_server_groupsDir" ]; then - export ZWED_groupsDir="$DESTINATION/groups" -fi -if [ -z "$ZWE_components_app_server_usersDir" ]; then - export ZWED_usersDir="$DESTINATION/users" -fi -if [ -z "$ZWE_components_app_server_pluginsDir" ]; then - export ZWED_pluginsDir="$DESTINATION/plugins" -fi -if [ -z "$ZWE_components_app_server_instanceDir" ]; then - export ZWED_instanceDir="$DESTINATION" -fi diff --git a/bin/utils/setup-logs.sh b/bin/utils/setup-logs.sh index 7d7890ac..634cba14 100644 --- a/bin/utils/setup-logs.sh +++ b/bin/utils/setup-logs.sh @@ -7,7 +7,6 @@ # # Copyright Contributors to the Zowe Project. - if [ -n "$ZWED_NODE_LOG_FILE" ] then if [ -n "$ZWED_NODE_LOG_DIR" ] @@ -20,7 +19,9 @@ else then if [ -d "$ZWE_zowe_logDirectory" ] then - ZWED_NODE_LOG_DIR=${ZWE_zowe_logDirectory} + ZWED_NODE_LOG_DIR=${ZWE_zowe_logDirectory} + elif [ -n "${HOME}" ]; then + ZWED_NODE_LOG_DIR="${HOME}/.zowe/logs" else ZWED_NODE_LOG_DIR="../log" fi @@ -91,7 +92,6 @@ fi echo ZWED_NODE_LOG_FILE=${ZWED_NODE_LOG_FILE} -export ZLUX_LOG_PATH=$ZWED_NODE_LOG_FILE if [ ! -e $ZWED_NODE_LOG_FILE ] then @@ -114,3 +114,5 @@ then echo file "$ZWED_NODE_LOG_FILE" is not writable. Logging disabled. ZWED_NODE_LOG_FILE=/dev/null fi + +export ZWED_NODE_LOG_FILE diff --git a/defaults/serverConfig/defaults.yaml b/defaults/serverConfig/defaults.yaml new file mode 100644 index 00000000..6a0451fe --- /dev/null +++ b/defaults/serverConfig/defaults.yaml @@ -0,0 +1,141 @@ +zowe: + workspaceDirectory: ${{ process.env.HOME + '/.zowe/workspace' }} + externalDomains: ${{ function a() { if (process.env.ZWE_zowe_externalDomains) { return process.env.ZWE_zowe_externalDomains.split(','); } else { return [ os.hostname() ] } }; a() }} + environments: + ZWED_SSH_PORT: 22 + ZWED_TN3270_PORT: 23 + ZWED_TN3270_SECURITY: telnet + ZWED_SSH_HOST: ${{ zowe.externalDomains[0] }} + ZWED_TN3270_HOST: ${{ zowe.externalDomains[0] }} + ZWED_TN3270_ROW: 24 + ZWED_TN3270_COL: 80 + #5=Dynamic + ZWED_TN3270_MOD: "5" + # + # ZWED_TN3270_CODEPAGE: +components: + app-server: + debug: false + node: + hostname: "${{ function a(){ if (process.env.ZWE_INTERNAL_HOST) { return process.env.ZWE_INTERNAL_HOST; } else if (process.env.ZWE_haInstance_hostname) { return process.env.ZWE_haInstance_hostname; } else { return undefined; } }; a() }}" + https: + ipAddresses: "${{ function a(){ + if (process.env.ZOWE_LOOPBACK_ADDRESS && process.env.BIND_TO_LOOPBACK == 'true') { + return [ process.env.ZOWE_LOOPBACK_ADDRESS , '0.0.0.0' ]; + } else { return ['0.0.0.0'] } }; + a() }}" + port: "${{ function a(){ + if (process.env.ZWED_SERVER_HTTPS_PORT) { + return Number(process.env.ZWED_SERVER_HTTPS_PORT); + } else if (components['app-server'].port) { + return components['app-server'].port; + } else { return Number(7556); } }; + a() }}" + keys: '${{ function a() { + if (zowe.certificate?.keystore?.type == "JCERACFKS") { + return [ zowe.certificate.keystore.file+"&"+zowe.certificate.keystore.alias ]; + } else if (zowe.certificate?.pem?.key) { + return [ zowe.certificate.pem.key ]; + } else { + return [ "../defaults/serverConfig/zlux.keystore.key" ]; } }; + a() }}' + certificates: '${{ function a(){ + if (zowe.certificate?.keystore?.type == "JCERACFKS") { + return [ zowe.certificate.keystore.file+"&"+zowe.certificate.keystore.alias ]; + } else if (zowe.certificate?.pem?.certificate) { + return [ zowe.certificate.pem.certificate ]; + } else { + return [ "../defaults/serverConfig/zlux.keystore.cer" ]; } }; + a() }}' + certificateAuthorities: '${{ function a() { + if (zowe.certificate?.truststore?.type == "JCERACFKS") { + return [ zowe.certificate.truststore.file ]; + } else if(zowe.certificate?.pem?.certificateAuthorities) { + return [zowe.certificate.pem.certificateAuthorities]; + } else { return ["../defaults/serverConfig/apiml-localca.cer"]; } }; + a() }}' + loopbackAddress: "${{ function a(){ if (process.env.ZOWE_LOOPBACK_ADDRESS) { return process.env.ZOWE_LOOPBACK_ADDRESS; } else { return undefined; } }; a() }}" + mediationLayer: + server: + hostname: ${{ zowe.externalDomains[0] }} + gatewayHostname: ${{ zowe.externalDomains[0] }} + port: ${{ components.discovery.port }} + gatewayPort: ${{ zowe.externalPort }} + isHttps: true + cachingService: + enabled: ${{ components['app-server'].node.mediationLayer.enabled && components['caching-service'].enabled }} + enabled: ${{ components.gateway.enabled && components.discovery.enabled }} + headers: + X-frame-Options: + override: true + value: sameorigin + allowInvalidTLSProxy: ${{ zowe.verifyCertificates == 'DISABLED' }} + noChild: false + noPrompt: false + productCode: "ZLUX" + rootRedirectURL: '/ZLUX/plugins/org.zowe.zlux.bootstrap/web/' + pluginScanIntervalSec: "${{ os.platform == 'zos' ? undefined : 60 }}" + readBodyLimit: 102400 + checkReferrer: + enabled: "${{ process.env.ZWE_CHECK_REFERRER ? process.env.ZWE_CHECK_REFERRER : false }}" + hosts: "${{ process.env.ZWE_REFERRER_HOSTS ? process.env.ZWE_REFERRER_HOSTS.toLowerCase().split(',') : process.env.ZWE_REFERER_HOSTS ? process.env.ZWE_REFERER_HOSTS.toLowerCase().split(',') : [] }}" + # All paths relative to zlux-app-server/bin + # In real installations, these values will be configured during the install. + productDir: ${{ function a(){ if (zowe.runtimeDirectory) { return zowe.runtimeDirectory+'/components/app-server/share/zlux-app-server/defaults'; } else { return '../defaults'; } }; a() }} + instanceDir: ${{ zowe.workspaceDirectory }}/app-server + siteDir: ${{ components['app-server'].instanceDir }}/site + groupsDir: ${{ components['app-server'].instanceDir }}/groups + usersDir: ${{ components['app-server'].instanceDir }}/users + pluginsDir: ${{ components['app-server'].instanceDir }}/plugins + dataserviceAuthentication: + # this specifies the default authentication type for dataservices that didn't specify which type to use. These dataservices therefore should not expect a particular type of authentication to be used. + defaultAuthentication: "${{ function a(){ if ((components.zss?.enabled == true) || (components.gateway?.enabled == true)) { return 'saf'; } else { return 'fallback'; } }; a() }}" + rbac: false + instanceID: ${{ zowe.rbacProfileIdentifier }} + cookieIdentifier: ${{ zowe.cookieIdentifier }} + # Specifies the default language for the server framework logging + logLanguage: en + logLevels: + _zsf.*: "${{ components['app-server'].debug === true ? 5 : 2 }}" + agent: ${{ components.zss.agent }} + zss: + # section used to define a connection to a server that can handle native or high privilege commands that the app server cannot + agent: + http: "${{ function a(){ if (components.zss.tls == false && components.zss.port) { return { port: components.zss.port }; } else { return undefined; } }; a() }}" + https: "${{ function a(){ if (components.zss.tls != false && components.zss.port) { return { port: components.zss.port }; } else { return undefined; } }; a() }}" + host: "${{ function a(){ if (components.zss.tls != false && process.env.ZWE_haInstance_hostname) { return process.env.ZWE_haInstance_hostname; } }; a() }}" + mediationLayer: + enabled: "${{ components['app-server'].node.mediationLayer.enabled }}" + serviceName: "zss" + rootServices: + - url: '/login' + method: '*' + requiresAuth: false + - url: '/logout' + method: '*' + requiresAuth: false + - url: '/unixfile' + method: '*' + - url: '/datasetContents' + method: '*' + - url: '/jes' + method: '*' + - url: '/VSAMdatasetContents' + method: '*' + - url: '/datasetMetadata' + method: '*' + - url: '/datasetCopy' + method: '*' + - url: '/omvs' + method: '*' + - url: '/ras' + method: '*' + - url: '/security-mgmt' + method: '*' + - url: '/saf-auth' + method: '*' + - url: '/password' + method: '*' + requiresAuth: false + - url: '/user-info' + method: '*' diff --git a/defaults/serverConfig/zowe.yaml b/defaults/serverConfig/zowe.yaml deleted file mode 100644 index 6e0db3b0..00000000 --- a/defaults/serverConfig/zowe.yaml +++ /dev/null @@ -1,54 +0,0 @@ -components: - app-server: - node: - https: - ipAddresses: - - 0.0.0.0 - port: 7556 - # pfx (string), keys, certificates, certificateAuthorities, and certificateRevocationLists are all valid here. - keys: - - "../defaults/serverConfig/zlux.keystore.key" - certificates: - - "../defaults/serverConfig/zlux.keystore.cer" - certificateAuthorities: - - "../defaults/serverConfig/apiml-localca.cer" - mediationLayer: - server: - hostname: localhost - port: 10011 - gatewayPort: 10012 - isHttps: true - enabled: false - headers: - X-frame-Options: - override: true - value: sameorigin - # All paths relative to zlux-app-server/bin - # In real installations, these values will be configured during the install. - # productDir: "../defaults" - # siteDir: "../deploy/site" - # instanceDir: "../deploy/instance" - # groupsDir: "../deploy/instance/groups" - # usersDir: "../deploy/instance/users" - # pluginsDir: "../defaults/plugins" - dataserviceAuthentication: - # this specifies the default authentication type for dataservices that didn't specify which type to use. These dataservices therefore should not expect a particular type of authentication to be used. - defaultAuthentication: fallback - rbac: false - # Specifies the default language for the server framework logging - logLanguage: en - zss: - # section used to define a connection to a server that can handle native or high privilege commands that the app server cannot - # agent: - # # for the app server to know, not the agent - # host: localhost - # # used by the agent - # http: - # ipAddresses: - # - 127.0.0.1 - # port: 7557 - # attls: false - # gateway: - # name: zss - # prefix: "/api/v1" - # enabled: false diff --git a/lib/initInstance.js b/lib/initInstance.js index da1cf123..4aa2b1f3 100644 --- a/lib/initInstance.js +++ b/lib/initInstance.js @@ -11,29 +11,35 @@ const fs = require('fs'); const path = require('path'); const argParser = require('../../zlux-server-framework/utils/argumentParser'); -const jsonUtils = require('../../zlux-server-framework/lib/jsonUtils'); const mergeUtils = require('../../zlux-server-framework/utils/mergeUtils'); +const yamlConfig = require('../../zlux-server-framework/utils/yamlConfig'); const initUtils = require('./initUtils'); -const upgradeInstance = require('./upgradeInstance'); +//const upgradeInstance = require('./upgradeInstance'); const os = require('os'); const ncp = require('ncp').ncp; const { execSync } = require('child_process'); const mkdirp = require('mkdirp'); +const haInstanceId = yamlConfig.getCurrentHaInstanceId(); +let config = {}; +if (process.env.CONFIG_FILE) { + config = yamlConfig.parseZoweDotYaml(process.env.CONFIG_FILE, haInstanceId); +} +const envConfig = argParser.environmentVarsToObject("ZWED_"); +if (Object.keys(envConfig).length > 0) { + config = mergeUtils.deepAssign(config, envConfig); +} - -//Where are we: dev environment? Official install? -const workspaceLocation = process.env.WORKSPACE_DIR && process.env.WORKSPACE_DIR != '""' - ? process.env.WORKSPACE_DIR - : process.env.ZWE_zowe_workspaceDirectory && process.env.ZWE_zowe_workspaceDirectory != '""' - ? process.env.ZWE_zowe_workspaceDirectory - : path.join(process.env.HOME, '.zowe', 'workspace'); +const workspaceLocation = config.zowe && config.zowe.workspaceDirectory + ? config.zowe.workspaceDirectory + : process.env.ZWE_zowe_workspaceDirectory; const destination = path.join(workspaceLocation, 'app-server'); + const versionLocation = path.join(destination, 'component.json'); -let config = argParser.environmentVarsToObject("ZWED_"); + config.productDir = path.join(__dirname, '..', 'defaults'); diff --git a/lib/zluxArgs.js b/lib/zluxArgs.js index 73d7c76c..c914fe7f 100644 --- a/lib/zluxArgs.js +++ b/lib/zluxArgs.js @@ -18,70 +18,25 @@ const mergeUtils = require('zlux-server-framework/utils/mergeUtils'); const yamlConfig = require('zlux-server-framework/utils/yamlConfig'); const mkdirp = require('mkdirp'); const cluster = require('cluster'); -const PRODUCT_CODE = 'ZLUX'; - -const DEFAULT_CONFIG = { - "productDir":"../defaults", - "siteDir":"../deploy/site", - "instanceDir":"../deploy/instance", - "groupsDir":"../deploy/instance/groups", - "usersDir":"../deploy/instance/users", - "pluginsDir":"../defaults/plugins", - - "node": { - "rootRedirectURL": '/' + PRODUCT_CODE + '/plugins/org.zowe.zlux.bootstrap/web/', - "allowInvalidTLSProxy": false, - "noChild": false, - "noPrompt": false, - "https": { - "ipAddresses": ["0.0.0.0"], - "port": 7556, - "keys": ["../defaults/serverConfig/zlux.keystore.key"], - "certificates": ["../defaults/serverConfig/zlux.keystore.cer"] - } - }, - "dataserviceAuthentication": { - "rbac": false, - "defaultAuthentication": "fallback" - } -}; const MVD_ARGS = [ new argParser.CLIArgument(null, 'D', argParser.constants.ARG_TYPE_JSON), - new argParser.CLIArgument('config', 'c', argParser.constants.ARG_TYPE_VALUE), - new argParser.CLIArgument('hostServer', 'h', argParser.constants.ARG_TYPE_VALUE), - new argParser.CLIArgument('hostPort', 'P', argParser.constants.ARG_TYPE_VALUE), - new argParser.CLIArgument('port', 'p', argParser.constants.ARG_TYPE_VALUE), - new argParser.CLIArgument('securePort', 's', argParser.constants.ARG_TYPE_VALUE), - new argParser.CLIArgument('noPrompt', null, argParser.constants.ARG_TYPE_FLAG), - new argParser.CLIArgument('noChild', null, argParser.constants.ARG_TYPE_FLAG), - new argParser.CLIArgument('allowInvalidTLSProxy', null, - argParser.constants.ARG_TYPE_VALUE), - new argParser.CLIArgument('mlUser', 'mu', argParser.constants.ARG_TYPE_VALUE), - new argParser.CLIArgument('mlPass', 'mp', argParser.constants.ARG_TYPE_VALUE) + new argParser.CLIArgument('config', 'c', argParser.constants.ARG_TYPE_VALUE) ]; -var config; -let agentHost = undefined; -let agentPort = undefined; var commandArgs = process.argv.slice(2); var argumentParser = argParser.createParser(MVD_ARGS); var userInput = argumentParser.parse(commandArgs); -var noPrompt = false; -var allowInvalidTLS = false; const haInstanceId = yamlConfig.getCurrentHaInstanceId(); -const componentOrder = ['zss', 'app-server']; // from lower to higher priority if (!userInput.config) { console.log('ZWED5018E - Missing one or more parameters required to run.\nConfig file was '+userInput.config); process.exit(-1); } -let configJSON = DEFAULT_CONFIG; //Overall config is a result of a heirarchy of overrides from defaults. -//CLI args > CLI -D arg > Env vars > YAML file > builtin defaults -const userConfig = yamlConfig.getConfig(userInput.config, haInstanceId, componentOrder); -//Config JSON overrides hardcoded defaults -configJSON = mergeUtils.deepAssign(configJSON, userConfig || {}); +//CLI -D arg > Env vars > YAML file +//Hack for enabling debug of this process... we need to read config before config is parsed, using env var here. env var translation misses _ and . and - +let configJSON = yamlConfig.parseZoweDotYaml(userInput.config, haInstanceId, Number(process.env['ZWE_components_app_server_logLevels_zsf_bootstrap'])>3); function getSafeToPrintEnvironment(env) { const keys = Object.keys(env).filter(key => { @@ -118,160 +73,17 @@ if(process.env.overrideFileConfig !== "false"){ } else { console.log("ZWED5017I - Using config JSON, discarding CLI args"); } -const forceHttpForAgent = (process.env['ZWES_SERVER_TLS'] === 'false'); -let useHttpsForAgent = !forceHttpForAgent; -if (configJSON.agent) { - if (!forceHttpForAgent && configJSON.agent.https && configJSON.agent.https.port) { - useHttpsForAgent = true; - agentPort = Number(configJSON.agent.https.port); - } else if (configJSON.agent.http && configJSON.agent.http.port) { - useHttpsForAgent = false; - agentPort = Number(configJSON.agent.http.port); - } else { - console.warn(`ZWED5006W - Invalid server configuration. Agent specified without http or https port`); - } - if(configJSON.agent.host){ - agentHost = configJSON.agent.host; - } -} else if (configJSON.zssPort) { - agentPort = Number(configJSON.zssPort); -} -if(configJSON.node.noChild === true){ - delete configJSON.node.childProcesses; -} -if(configJSON.node.allowInvalidTLSProxy){ - allowInvalidTLS = true; -} -//finally, specific CLI flags override any above -if(process.env.overrideFileConfig !== "false"){ - let eUser = userInput.mlUser; - let ePass = userInput.mlPass; - if(eUser && ePass){ - configJSON.node.mediationLayer.enabled = true; - configJSON.node.mediationLayer.instance.instanceId = `${configJSON.node.mediationLayer.instance.app}:${Math.floor(Math.random() * 9999)}`; - configJSON.node.mediationLayer.eureka.serviceUrls.default = [`http://${eUser}:${ePass}@${configJSON.node.mediationLayer.server.hostname}:${configJSON.node.mediationLayer.server.port}/eureka/apps/`]; - } - if (userInput.hostPort) { - agentPort = Number(userInput.hostPort); - } - if(userInput.noPrompt){ - noPrompt = true; - } - if(noPrompt){ - configJSON.node.noPrompt = true; - } - if (userInput.hostServer) { - agentHost = userInput.hostServer; - } - if (userInput.port) { - if (!configJSON.node.http) { configJSON.node.http = {}; } - configJSON.node.http.port = Number(userInput.port); - } - if (userInput.securePort && configJSON.node.https) { - configJSON.node.https.port = Number(userInput.securePort); - } - if (userInput.noChild) { - configJSON.node.noChild = true; - delete configJSON.node.childProcesses; - } - if (userInput.allowInvalidTLSProxy !== undefined) { - allowInvalidTLS = (userInput.allowInvalidTLSProxy === 'true'); - } -} - -if (agentHost && agentPort) { - configJSON.agent = configJSON.agent || {}; - configJSON.agent.host = agentHost; - if (useHttpsForAgent) { - configJSON.agent.https = configJSON.agent.https || {}; - configJSON.agent.https.port = agentPort; - configJSON.agent.http = {}; - } else { - configJSON.agent.http = configJSON.agent.http || {}; - configJSON.agent.http.port = agentPort; - configJSON.agent.https = {}; - } -} -const startUpConfig = { - proxiedHost: agentHost, - proxiedPort: agentPort, - allowInvalidTLSProxy: allowInvalidTLS -}; -const appConfig = { - productCode: PRODUCT_CODE, - rootRedirectURL: configJSON.node.rootRedirectURL -}; -if (startUpConfig.proxiedHost && startUpConfig.proxiedPort) { - appConfig.rootServices = configJSON.agent && Array.isArray(configJSON.agent.rootServices) - ? configJSON.agent.rootServices - : [{ - method: '*', - url: '/login', - requiresAuth: false - }, - { - method: '*', - url: '/logout', - requiresAuth: false - }, - { - method: '*', - url: '/unixfile' - }, - { - method: '*', - url: '/datasetContents' - }, - { - method: '*', - url: '/jes' - }, - { - method: '*', - url: '/VSAMdatasetContents' - }, - { - method: '*', - url: '/datasetMetadata' - }, - { - method: '*', - url: '/datasetCopy' - }, - { - method: '*', - url: '/omvs' - }, - { - method: '*', - url: '/ras' - }, - { - method: '*', - url: '/security-mgmt' - }, - { - method: '*', - url: '/saf-auth' - }, - { - method: '*', - url: '/password', - requiresAuth: false - }, - { - method: '*', - url: '/user-info' - } - ]; +if(configJSON.components['app-server'].node.noChild === true){ + delete configJSON.components['app-server'].node.childProcesses; } + if (cluster.isMaster) { console.log('\nZWED5018I - Initializing with configuration:\n',JSON.stringify(configJSON, null, 2)); } module.exports = function() { - return {appConfig: appConfig, configJSON: configJSON, startUpConfig: startUpConfig, configLocation: userInput.config} + return {configJSON: configJSON, configLocation: userInput.config} } /* diff --git a/lib/zluxCluster.js b/lib/zluxCluster.js index d32dd193..fe2770a0 100644 --- a/lib/zluxCluster.js +++ b/lib/zluxCluster.js @@ -11,12 +11,11 @@ 'use strict'; const clusterManager = require('zlux-server-framework/lib/clusterManager').clusterManager; -const {appConfig, configJSON, startUpConfig, configLocation} = require('./zluxArgs')(); +const {configJSON, configLocation} = require('./zluxArgs')(); -clusterManager.start(appConfig, configJSON, startUpConfig, configLocation); +clusterManager.start(configJSON, configLocation); -//run as: -//node --harmony zluxCluster.js --config=../deploy/instance/ZLUX/serverConfig/zluxserver.json -h -P +//run with start.sh /* This program and the accompanying materials are made available under the terms of the Eclipse Public License v2.0 which accompanies diff --git a/lib/zluxServer.js b/lib/zluxServer.js index 91eed1a7..5c898813 100644 --- a/lib/zluxServer.js +++ b/lib/zluxServer.js @@ -13,19 +13,15 @@ 'use strict'; const ProxyServer = require('zlux-server-framework'); -const {appConfig, configJSON, startUpConfig, configLocation} = require('./zluxArgs')(); -const proxyServer = new ProxyServer(appConfig, configJSON, startUpConfig, configLocation); +const {configJSON, configLocation} = require('./zluxArgs')(); +const proxyServer = new ProxyServer(configJSON, configLocation); proxyServer.start().then(() => { console.log("ZWED5019I - Started") }).catch(e => { console.log("ZWED5019E - Could not start the server: ", e) }); -// run as: -// node --harmony mvdServer.js --config=../config/zluxserver.json [--hostServer=] [--hostPort=#] - - - +//run with start.sh /* This program and the accompanying materials are made available under the terms of the Eclipse Public License v2.0 which accompanies diff --git a/schemas/app-server-config.json b/schemas/app-server-config.json index 186b1d68..e8155627 100644 --- a/schemas/app-server-config.json +++ b/schemas/app-server-config.json @@ -140,6 +140,29 @@ } } }, + "readBodyLimit": { + "type": "number", + "description": "Controls the default value for the maximum amount of bytes to accept when reading an HTTP body", + "default": 102400 + }, + "checkReferrer": { + "deprecated": true, + "enabled": { + "type": "boolean", + "deprecated": true, + "default": false, + "description": "Controls whether or not the server will block requests that dont have a valid referrer. This should not be needed due to using same-site cookies for the same purpose" + }, + "hosts": { + "type": "array", + "deprecated": true, + "description": "A list of hostnames that the server is hosted on so that if it sees referrers with any of these hostnames, the HTTP requests will be approved rather than rejected", + "items": { + "type": "string", + "description": "A hostname or IP as seen from a browser" + } + } + }, "internalRouting": { "type": "boolean", "description": "Controls if app-server should call one REST API from another by using a network call over a loopback address, or issue the request internal to the server by mimicking a network request",