From 62c2d9057c01906c09ac98087e037f84fb4eb4fe Mon Sep 17 00:00:00 2001 From: dkatzz <86739416+dkatzz@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:47:45 -0400 Subject: [PATCH] Add check about file existence and type --- cloud/shared/bin/python_env_setup | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cloud/shared/bin/python_env_setup b/cloud/shared/bin/python_env_setup index f463ca23..1508a00b 100755 --- a/cloud/shared/bin/python_env_setup +++ b/cloud/shared/bin/python_env_setup @@ -31,8 +31,20 @@ function initialize_python_env() { # source the activate script (. is more portable between shells than source) . .venv/bin/activate - # If a certificate file is specified, configure pip to use it + # If a certificate file is specified, perform checks then configure pip to use it if [[ -n "$cert_file_path" ]]; then + # Check if the file exists and is readable + if [[ ! -r "$cert_file_path" ]]; then + echo "Error: Certificate file '$cert_file_path' does not exist or is not readable." + return 1 + fi + + # Check the file format is PEM + if ! file "$cert_file_path" | grep -q "PEM certificate"; then + echo "Error: Certificate file '$cert_file_path' is not in the correct format (expected PEM)." + return 1 + fi + echo "Setting pip global.cert to $cert_file_path" pip config set global.cert "$cert_file_path" fi