Skip to content

Commit

Permalink
Add checks for environment completness (and fix a couple places where…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
cmickeyb authored and g2flyer committed Jan 24, 2024
1 parent b03dfb3 commit 1204450
Show file tree
Hide file tree
Showing 33 changed files with 81 additions and 17 deletions.
47 changes: 38 additions & 9 deletions bin/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function yell () {
}

function die() {
recho "$(basename $0): $*" >&2
recho "$(basename $0): ERROR: $*" >&2
exit 111
}

Expand Down Expand Up @@ -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)}"
}
1 change: 1 addition & 0 deletions build/__tools__/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions build/__tools__/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

# -----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions build/__tools__/run-benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

# -----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions build/__tools__/run-perf-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

# -----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions build/__tools__/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions build/__tools__/verify-pre-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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: $*"
Expand Down
1 change: 1 addition & 0 deletions build/__tools__/verify-pre-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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: $*"
Expand Down
1 change: 1 addition & 0 deletions build/tests/multi-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# -----------------------------------------------------------------
# -----------------------------------------------------------------
source ${PDO_SOURCE_ROOT}/bin/lib/common.sh
check_pdo_runtime_env
check_python_version

# -----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions build/tests/service-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# -----------------------------------------------------------------
# -----------------------------------------------------------------
source ${PDO_SOURCE_ROOT}/bin/lib/common.sh
check_pdo_runtime_env
check_python_version

# -----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions build/tests/unit-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions common/crypto/verify_ias_report/fetch_ias_certificates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# -----------------------------------------------------------------
# -----------------------------------------------------------------
source ${PDO_SOURCE_ROOT}/bin/lib/common.sh
check_pdo_build_env

IAS_CERTIFICATE_URL=$1

Expand Down
6 changes: 3 additions & 3 deletions docker/tools/build_client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docker/tools/build_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docker/tools/run_ccf_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docker/tools/run_client_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
# 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

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

Expand Down
3 changes: 2 additions & 1 deletion docker/tools/run_services_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docker/tools/start_ccf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docker/tools/start_client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docker/tools/start_development.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docker/tools/start_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions eservice/bin/es-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions eservice/bin/es-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions eservice/bin/es-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions eservice/bin/register-with-ledger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions ledgers/ccf/scripts/start_ccf_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# -----------------------------------------------------------------
# -----------------------------------------------------------------
source ${PDO_HOME}/bin/lib/common.sh
check_pdo_runtime_env
check_python_version

# -----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions ledgers/ccf/scripts/stop_cchost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pservice/bin/ps-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pservice/bin/ps-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions pservice/bin/ps-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions sservice/bin/ss-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions sservice/bin/ss-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions sservice/bin/ss-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 1204450

Please sign in to comment.