From 1204450a35d7195f72a3f40610e37f0947c3b793 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Wed, 24 Jan 2024 08:35:16 -0700 Subject: [PATCH] Add checks for environment completness (and fix a couple places where it was not) slight modification on code from @gflyer, separated the environment check into runtime and build time variable checks. Note that this reflects the reality of current dependencies (and we should always be looking for ways to reduce the dependencies). It also does not check for additional variables required for HW mode support. Signed-off-by: Mic Bowman --- bin/lib/common.sh | 47 +++++++++++++++---- build/__tools__/build.sh | 1 + build/__tools__/clean.sh | 1 + build/__tools__/run-benchmarks.sh | 1 + build/__tools__/run-perf-tests.sh | 1 + build/__tools__/run-tests.sh | 1 + build/__tools__/verify-pre-build.sh | 1 + build/__tools__/verify-pre-conf.sh | 1 + build/tests/multi-user.sh | 1 + build/tests/service-test.sh | 1 + build/tests/unit-test.sh | 1 + .../fetch_ias_certificates.sh | 1 + docker/tools/build_client.sh | 6 +-- docker/tools/build_services.sh | 6 +-- docker/tools/run_ccf_tests.sh | 2 + docker/tools/run_client_tests.sh | 3 +- docker/tools/run_services_tests.sh | 3 +- docker/tools/start_ccf.sh | 2 + docker/tools/start_client.sh | 2 + docker/tools/start_development.sh | 2 + docker/tools/start_services.sh | 2 + eservice/bin/es-start.sh | 1 + eservice/bin/es-status.sh | 1 + eservice/bin/es-stop.sh | 1 + eservice/bin/register-with-ledger.sh | 1 + ledgers/ccf/scripts/start_ccf_network.sh | 1 + ledgers/ccf/scripts/stop_cchost.sh | 1 + pservice/bin/ps-start.sh | 1 + pservice/bin/ps-status.sh | 1 + pservice/bin/ps-stop.sh | 1 + sservice/bin/ss-start.sh | 1 + sservice/bin/ss-status.sh | 1 + sservice/bin/ss-stop.sh | 1 + 33 files changed, 81 insertions(+), 17 deletions(-) diff --git a/bin/lib/common.sh b/bin/lib/common.sh index d464f7b6..1d0c2328 100644 --- a/bin/lib/common.sh +++ b/bin/lib/common.sh @@ -47,7 +47,7 @@ function yell () { } function die() { - recho "$(basename $0): $*" >&2 + recho "$(basename $0): ERROR: $*" >&2 exit 111 } @@ -80,12 +80,41 @@ function force_to_ip() } # ----------------------------------------- -# Check the environment for completeness +# Check for build time environment variables # ----------------------------------------- -: "${PDO_HOME:-$(die Missing environment variable PDO_HOME)}" -: "${PDO_HOSTNAME:-$(die Missing environment variable PDO_HOSTNAME)}" -: "${PDO_INTERPRETER:-$(die Missing environment variable PDO_INTERPRETER)}" -: "${PDO_LEDGER_KEY_ROOT:-$(die Missing environment variable PDO_LEDGER_KEY_ROOT)}" -: "${PDO_LEDGER_TYPE:-$(die Missing environment variable PDO_LEDGER_TYPE)}" -: "${PDO_LEDGER_URL:-$(die Missing environment variable PDO_LEDGER_URL)}" -: "${PDO_SOURCE_ROOT:-$(die Missing environment variable PDO_SOURCE_ROOT)}" +function check_pdo_build_env() +{ + # note: despite the 'die' below this does _not_ terminate, just prints error! + : "${PDO_SOURCE_ROOT:-$(die Missing environment variable PDO_SOURCE_ROOT)}" + : "${PDO_HOME:-$(die Missing environment variable PDO_HOME)}" + : "${PDO_INTERPRETER:-$(die Missing environment variable PDO_INTERPRETER)}" + : "${PDO_LEDGER_TYPE:-$(die Missing environment variable PDO_LEDGER_TYPE)}" + : "${PDO_LEDGER_KEY_ROOT:-$(die Missing environment variable PDO_LEDGER_KEY_ROOT)}" +} + +# ----------------------------------------- +# Check for runtime environment variables +# ----------------------------------------- +function check_pdo_runtime_env() +{ + # PDO_SOURCE_ROOT is a runtime dependency we should remove + : "${PDO_SOURCE_ROOT:-$(die Missing environment variable PDO_SOURCE_ROOT)}" + + # Base path for finding libraries and configuration files + : "${PDO_HOME:-$(die Missing environment variable PDO_HOME)}" + + # Used for building contracts + : "${PDO_INTERPRETER:-$(die Missing environment variable PDO_INTERPRETER)}" + + # Used for selection of key formats + : "${PDO_LEDGER_TYPE:-$(die Missing environment variable PDO_LEDGER_TYPE)}" + + # Used to find the ledger keys + : "${PDO_LEDGER_KEY_ROOT:-$(die Missing environment variable PDO_LEDGER_KEY_ROOT)}" + + # Used to find the ledger + : "${PDO_LEDGER_URL:-$(die Missing environment variable PDO_LEDGER_URL)}" + + # Used to identify the interface for services + : "${PDO_HOSTNAME:-$(die Missing environment variable PDO_HOSTNAME)}" +} diff --git a/build/__tools__/build.sh b/build/__tools__/build.sh index e6c6daa3..bb186816 100755 --- a/build/__tools__/build.sh +++ b/build/__tools__/build.sh @@ -20,6 +20,7 @@ SCRIPTDIR="$(dirname $(readlink --canonicalize ${BASH_SOURCE}))" SRCDIR="$(realpath ${SCRIPTDIR}/../..)" source ${SRCDIR}/bin/lib/common.sh +check_pdo_build_env check_python_version # Automatically determine how many cores the host system has diff --git a/build/__tools__/clean.sh b/build/__tools__/clean.sh index 58bce307..abbc96d1 100755 --- a/build/__tools__/clean.sh +++ b/build/__tools__/clean.sh @@ -18,6 +18,7 @@ SCRIPTDIR="$(dirname $(readlink --canonicalize ${BASH_SOURCE}))" SRCDIR="$(realpath ${SCRIPTDIR}/../..)" source ${SRCDIR}/bin/lib/common.sh +check_pdo_build_env check_python_version # ----------------------------------------------------------------- diff --git a/build/__tools__/run-benchmarks.sh b/build/__tools__/run-benchmarks.sh index 68eb91b2..03b9bc92 100755 --- a/build/__tools__/run-benchmarks.sh +++ b/build/__tools__/run-benchmarks.sh @@ -20,6 +20,7 @@ SCRIPTDIR="$(dirname $(readlink --canonicalize ${BASH_SOURCE}))" SRCDIR="$(realpath ${SCRIPTDIR}/../..)" source ${SRCDIR}/bin/lib/common.sh +check_pdo_runtime_env check_python_version # ----------------------------------------------------------------- diff --git a/build/__tools__/run-perf-tests.sh b/build/__tools__/run-perf-tests.sh index a91286de..a9f17152 100755 --- a/build/__tools__/run-perf-tests.sh +++ b/build/__tools__/run-perf-tests.sh @@ -20,6 +20,7 @@ SCRIPTDIR="$(dirname $(readlink --canonicalize ${BASH_SOURCE}))" SRCDIR="$(realpath ${SCRIPTDIR}/../..)" source ${SRCDIR}/bin/lib/common.sh +check_pdo_runtime_env check_python_version # ----------------------------------------------------------------- diff --git a/build/__tools__/run-tests.sh b/build/__tools__/run-tests.sh index 2bb0f7e9..ee34b587 100755 --- a/build/__tools__/run-tests.sh +++ b/build/__tools__/run-tests.sh @@ -17,6 +17,7 @@ # ----------------------------------------------------------------- # ----------------------------------------------------------------- source ${PDO_SOURCE_ROOT}/bin/lib/common.sh +check_pdo_runtime_env check_python_version PDO_LOG_LEVEL=${PDO_LOG_LEVEL:-info} diff --git a/build/__tools__/verify-pre-build.sh b/build/__tools__/verify-pre-build.sh index 5083376b..52c33fae 100755 --- a/build/__tools__/verify-pre-build.sh +++ b/build/__tools__/verify-pre-build.sh @@ -25,6 +25,7 @@ SCRIPTDIR="$(dirname $(readlink --canonicalize ${BASH_SOURCE}))" SRCDIR="$(realpath ${SCRIPTDIR}/../..)" source ${SRCDIR}/bin/lib/common.sh +check_pdo_build_env function warn () { recho "WARNING: $*" diff --git a/build/__tools__/verify-pre-conf.sh b/build/__tools__/verify-pre-conf.sh index 4d31fa6b..c549dce3 100755 --- a/build/__tools__/verify-pre-conf.sh +++ b/build/__tools__/verify-pre-conf.sh @@ -25,6 +25,7 @@ SCRIPTDIR="$(dirname $(readlink --canonicalize ${BASH_SOURCE}))" SRCDIR="$(realpath ${SCRIPTDIR}/../..)" source ${SRCDIR}/bin/lib/common.sh +check_pdo_build_env function warn () { recho "WARNING: $*" diff --git a/build/tests/multi-user.sh b/build/tests/multi-user.sh index 13264c3e..87f19cb4 100755 --- a/build/tests/multi-user.sh +++ b/build/tests/multi-user.sh @@ -17,6 +17,7 @@ # ----------------------------------------------------------------- # ----------------------------------------------------------------- source ${PDO_SOURCE_ROOT}/bin/lib/common.sh +check_pdo_runtime_env check_python_version # ----------------------------------------------------------------- diff --git a/build/tests/service-test.sh b/build/tests/service-test.sh index 62aba446..ae413e43 100755 --- a/build/tests/service-test.sh +++ b/build/tests/service-test.sh @@ -17,6 +17,7 @@ # ----------------------------------------------------------------- # ----------------------------------------------------------------- source ${PDO_SOURCE_ROOT}/bin/lib/common.sh +check_pdo_runtime_env check_python_version # ----------------------------------------------------------------- diff --git a/build/tests/unit-test.sh b/build/tests/unit-test.sh index bcdd2ab4..6f566cb1 100755 --- a/build/tests/unit-test.sh +++ b/build/tests/unit-test.sh @@ -17,6 +17,7 @@ # ----------------------------------------------------------------- # ----------------------------------------------------------------- source ${PDO_SOURCE_ROOT}/bin/lib/common.sh +check_pdo_runtime_env check_python_version PDO_LOG_LEVEL=${PDO_LOG_LEVEL:-info} diff --git a/common/crypto/verify_ias_report/fetch_ias_certificates.sh b/common/crypto/verify_ias_report/fetch_ias_certificates.sh index f9c51c62..3ab8e5bf 100755 --- a/common/crypto/verify_ias_report/fetch_ias_certificates.sh +++ b/common/crypto/verify_ias_report/fetch_ias_certificates.sh @@ -23,6 +23,7 @@ # ----------------------------------------------------------------- # ----------------------------------------------------------------- source ${PDO_SOURCE_ROOT}/bin/lib/common.sh +check_pdo_build_env IAS_CERTIFICATE_URL=$1 diff --git a/docker/tools/build_client.sh b/docker/tools/build_client.sh index 6f7bac7d..a52266d3 100755 --- a/docker/tools/build_client.sh +++ b/docker/tools/build_client.sh @@ -15,9 +15,9 @@ source /project/pdo/tools/environment.sh -# these variables should be unused during build -export PDO_HOSTNAME= -export PDO_LEDGER_URL= +# to get build without (ignored) errors +export PDO_HOSTNAME=localhost +export PDO_LEDGER_URL=https://127.0.0.1:6600 make -C ${PDO_SOURCE_ROOT}/build environment make -C ${PDO_SOURCE_ROOT}/build template diff --git a/docker/tools/build_services.sh b/docker/tools/build_services.sh index b352dd34..96f5d859 100755 --- a/docker/tools/build_services.sh +++ b/docker/tools/build_services.sh @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -# these variables should be unused during build -export PDO_HOSTNAME= -export PDO_LEDGER_URL= +# to get build without (ignored) errors +export PDO_HOSTNAME=localhost +export PDO_LEDGER_URL=https://127.0.0.1:6600 source /opt/intel/sgxsdk/environment source /project/pdo/tools/environment.sh diff --git a/docker/tools/run_ccf_tests.sh b/docker/tools/run_ccf_tests.sh index ed756086..b8d36f33 100755 --- a/docker/tools/run_ccf_tests.sh +++ b/docker/tools/run_ccf_tests.sh @@ -21,6 +21,8 @@ export PDO_HOSTNAME=localhost export PDO_LEDGER_ADDRESS=$(force_to_ip ${PDO_HOSTNAME}) export PDO_LEDGER_URL="http://${PDO_LEDGER_ADDRESS}:6600" +check_pdo_runtime_env + export no_proxy=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$no_proxy export NO_PROXY=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$NO_PROXY diff --git a/docker/tools/run_client_tests.sh b/docker/tools/run_client_tests.sh index faa328c7..ed6053b6 100755 --- a/docker/tools/run_client_tests.sh +++ b/docker/tools/run_client_tests.sh @@ -14,7 +14,6 @@ # limitations under the License. # Tests are run EXCLUSIVELY with all services running on localhost - source /project/pdo/tools/environment.sh source ${PDO_HOME}/bin/lib/common.sh @@ -22,6 +21,8 @@ export PDO_HOSTNAME=localhost export PDO_LEDGER_ADDRESS=$(force_to_ip ${PDO_HOSTNAME}) export PDO_LEDGER_URL="http://${PDO_LEDGER_ADDRESS}:6600" +check_pdo_runtime_env + export no_proxy=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$no_proxy export NO_PROXY=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$NO_PROXY diff --git a/docker/tools/run_services_tests.sh b/docker/tools/run_services_tests.sh index b1a2c949..5f35b148 100755 --- a/docker/tools/run_services_tests.sh +++ b/docker/tools/run_services_tests.sh @@ -14,7 +14,6 @@ # limitations under the License. # Tests are run EXCLUSIVELY with all services running on localhost - source /opt/intel/sgxsdk/environment source /project/pdo/tools/environment.sh source ${PDO_HOME}/bin/lib/common.sh @@ -23,6 +22,8 @@ export PDO_HOSTNAME=localhost export PDO_LEDGER_ADDRESS=$(force_to_ip ${PDO_HOSTNAME}) export PDO_LEDGER_URL="http://${PDO_LEDGER_ADDRESS}:6600" +check_pdo_runtime_env + export no_proxy=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$no_proxy export NO_PROXY=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$NO_PROXY diff --git a/docker/tools/start_ccf.sh b/docker/tools/start_ccf.sh index 5d5b52de..dc15ff08 100755 --- a/docker/tools/start_ccf.sh +++ b/docker/tools/start_ccf.sh @@ -66,6 +66,8 @@ fi export PDO_LEDGER_ADDRESS=$(force_to_ip ${PDO_HOSTNAME}) export PDO_LEDGER_URL="http://${PDO_LEDGER_ADDRESS}:6600" +check_pdo_runtime_env + export no_proxy=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$no_proxy export NO_PROXY=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$NO_PROXY diff --git a/docker/tools/start_client.sh b/docker/tools/start_client.sh index 89c1fcee..ebea4be0 100755 --- a/docker/tools/start_client.sh +++ b/docker/tools/start_client.sh @@ -68,6 +68,8 @@ if [ ! -z "${F_LEDGER_URL}" ] ; then export PDO_LEDGER_URL=${F_LEDGER_URL} fi +check_pdo_runtime_env + export no_proxy=$PDO_HOSTNAME,$no_proxy export NO_PROXY=$PDO_HOSTNAME,$NO_PROXY diff --git a/docker/tools/start_development.sh b/docker/tools/start_development.sh index d7ec7781..1865387f 100755 --- a/docker/tools/start_development.sh +++ b/docker/tools/start_development.sh @@ -13,6 +13,8 @@ fi source /project/pdo/tools/environment.sh source ${PDO_SOURCE_ROOT}/bin/lib/common.sh +check_pdo_runtime_env + export no_proxy=$PDO_HOSTNAME,$no_proxy export NO_PROXY=$PDO_HOSTNAME,$NO_PROXY diff --git a/docker/tools/start_services.sh b/docker/tools/start_services.sh index e815fd68..b5b85277 100755 --- a/docker/tools/start_services.sh +++ b/docker/tools/start_services.sh @@ -77,6 +77,8 @@ if [ ! -z "${F_LEDGER_URL}" ] ; then export PDO_LEDGER_ADDRESS=$( echo $PDO_LEDGER_URL | awk -F[/:] '{print $4}' ) fi +check_pdo_runtime_env + export no_proxy=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$no_proxy export NO_PROXY=$PDO_HOSTNAME,$PDO_LEDGER_ADDRESS,$NO_PROXY diff --git a/eservice/bin/es-start.sh b/eservice/bin/es-start.sh index 46a1796c..cda2a207 100755 --- a/eservice/bin/es-start.sh +++ b/eservice/bin/es-start.sh @@ -16,6 +16,7 @@ F_SERVICEHOME="$( cd -P "$( dirname ${BASH_SOURCE[0]} )/.." && pwd )" source ${F_SERVICEHOME}/bin/lib/common.sh +check_pdo_runtime_env source ${F_SERVICEHOME}/bin/lib/common_service.sh check_python_version diff --git a/eservice/bin/es-status.sh b/eservice/bin/es-status.sh index c5c44587..c6e16121 100755 --- a/eservice/bin/es-status.sh +++ b/eservice/bin/es-status.sh @@ -16,6 +16,7 @@ F_SERVICEHOME="$( cd -P "$( dirname ${BASH_SOURCE[0]} )/.." && pwd )" source ${F_SERVICEHOME}/bin/lib/common.sh +check_pdo_runtime_env source ${F_SERVICEHOME}/bin/lib/common_service.sh diff --git a/eservice/bin/es-stop.sh b/eservice/bin/es-stop.sh index f6cd6e22..065fc737 100755 --- a/eservice/bin/es-stop.sh +++ b/eservice/bin/es-stop.sh @@ -16,6 +16,7 @@ F_SERVICEHOME="$( cd -P "$( dirname ${BASH_SOURCE[0]} )/.." && pwd )" source ${F_SERVICEHOME}/bin/lib/common.sh +check_pdo_runtime_env source ${F_SERVICEHOME}/bin/lib/common_service.sh diff --git a/eservice/bin/register-with-ledger.sh b/eservice/bin/register-with-ledger.sh index 7b34ffe8..9395ebfe 100755 --- a/eservice/bin/register-with-ledger.sh +++ b/eservice/bin/register-with-ledger.sh @@ -29,6 +29,7 @@ PDO_IAS_KEY_PEM=${PDO_SGX_KEY_ROOT}/sgx_ias_key.pem eservice_enclave_info_file=$(mktemp /tmp/pdo-test.XXXXXXXXX) source ${SRCDIR}/bin/lib/common.sh +check_pdo_runtime_env check_python_version function cleanup { diff --git a/ledgers/ccf/scripts/start_ccf_network.sh b/ledgers/ccf/scripts/start_ccf_network.sh index c48bf500..e9352fca 100755 --- a/ledgers/ccf/scripts/start_ccf_network.sh +++ b/ledgers/ccf/scripts/start_ccf_network.sh @@ -17,6 +17,7 @@ # ----------------------------------------------------------------- # ----------------------------------------------------------------- source ${PDO_HOME}/bin/lib/common.sh +check_pdo_runtime_env check_python_version # ----------------------------------------------------------------- diff --git a/ledgers/ccf/scripts/stop_cchost.sh b/ledgers/ccf/scripts/stop_cchost.sh index 019dc932..8996337a 100755 --- a/ledgers/ccf/scripts/stop_cchost.sh +++ b/ledgers/ccf/scripts/stop_cchost.sh @@ -17,6 +17,7 @@ # ----------------------------------------------------------------- # ----------------------------------------------------------------- source ${PDO_HOME}/bin/lib/common.sh +check_pdo_runtime_env if [ -f ${PDO_HOME}/ccf/workspace/sandbox_0/node.pid ]; then kill $(cat ${PDO_HOME}/ccf/workspace/sandbox_0/node.pid) diff --git a/pservice/bin/ps-start.sh b/pservice/bin/ps-start.sh index fd63605f..4d4bbba8 100755 --- a/pservice/bin/ps-start.sh +++ b/pservice/bin/ps-start.sh @@ -16,6 +16,7 @@ F_SERVICEHOME="$( cd -P "$( dirname ${BASH_SOURCE[0]} )/.." && pwd )" source ${F_SERVICEHOME}/bin/lib/common.sh +check_pdo_runtime_env source ${F_SERVICEHOME}/bin/lib/common_service.sh check_python_version diff --git a/pservice/bin/ps-status.sh b/pservice/bin/ps-status.sh index fe70a845..fd9158ed 100755 --- a/pservice/bin/ps-status.sh +++ b/pservice/bin/ps-status.sh @@ -16,6 +16,7 @@ F_SERVICEHOME="$( cd -P "$( dirname ${BASH_SOURCE[0]} )/.." && pwd )" source ${F_SERVICEHOME}/bin/lib/common.sh +check_pdo_runtime_env source ${F_SERVICEHOME}/bin/lib/common_service.sh F_BASENAME='pservice' diff --git a/pservice/bin/ps-stop.sh b/pservice/bin/ps-stop.sh index 4edbac33..73f5b034 100755 --- a/pservice/bin/ps-stop.sh +++ b/pservice/bin/ps-stop.sh @@ -16,6 +16,7 @@ F_SERVICEHOME="$( cd -P "$( dirname ${BASH_SOURCE[0]} )/.." && pwd )" source ${F_SERVICEHOME}/bin/lib/common.sh +check_pdo_runtime_env source ${F_SERVICEHOME}/bin/lib/common_service.sh F_BASENAME='pservice' diff --git a/sservice/bin/ss-start.sh b/sservice/bin/ss-start.sh index e55573b9..00fb5ba9 100755 --- a/sservice/bin/ss-start.sh +++ b/sservice/bin/ss-start.sh @@ -16,6 +16,7 @@ F_SERVICEHOME="$( cd -P "$( dirname ${BASH_SOURCE[0]} )/.." && pwd )" source ${F_SERVICEHOME}/bin/lib/common.sh +check_pdo_runtime_env source ${F_SERVICEHOME}/bin/lib/common_service.sh check_python_version diff --git a/sservice/bin/ss-status.sh b/sservice/bin/ss-status.sh index 165bd486..1a2d857f 100755 --- a/sservice/bin/ss-status.sh +++ b/sservice/bin/ss-status.sh @@ -16,6 +16,7 @@ F_SERVICEHOME="$( cd -P "$( dirname ${BASH_SOURCE[0]} )/.." && pwd )" source ${F_SERVICEHOME}/bin/lib/common.sh +check_pdo_runtime_env source ${F_SERVICEHOME}/bin/lib/common_service.sh diff --git a/sservice/bin/ss-stop.sh b/sservice/bin/ss-stop.sh index e91285b8..ddf4cf20 100755 --- a/sservice/bin/ss-stop.sh +++ b/sservice/bin/ss-stop.sh @@ -16,6 +16,7 @@ F_SERVICEHOME="$( cd -P "$( dirname ${BASH_SOURCE[0]} )/.." && pwd )" source ${F_SERVICEHOME}/bin/lib/common.sh +check_pdo_runtime_env source ${F_SERVICEHOME}/bin/lib/common_service.sh F_BASENAME='sservice'