Skip to content

Commit e1d4b2a

Browse files
committed
Simplified script handling
1 parent ecc24d8 commit e1d4b2a

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

evergreen/convert-client-cert-to-pkcs12.sh

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,23 @@ set -o errexit # Exit the script with an error if any of the commands fail
55
# Input environment variables
66
: "${CLIENT_PEM_VAR_NAME:="CLIENT_PEM"}" # Name of the input variable for the client.pem file
77
: "${OUTPUT_VAR_PREFIX:="MONGO_X509_CLIENT"}" # Prefix for output environment variables
8-
: "${CERTIFICATE_NAME:="Drivers Client Certificate"}" # Name for the exported certificate
9-
10-
#todo, need to take the input name for client file and password, and not use the convoluted system we have
11-
#I think I need to add those to the input environment variables and then use those in the export down here (where the default values for output variables are)
8+
: "${FRIENDLY_NAME:="Drivers Client Certificate"}" # Friendly name for the exported certificate
9+
: "${P12_FILENAME:="client.p12"}"
10+
: "${P12_PASSWORD:="Picard-Alpha-Alpha-3-0-5"}"
11+
: "${OUT_CLIENT_PASSWORD_VAR:="MONGO_X509_CLIENT_CERTIFICATE_PASSWORD"}"
12+
: "${OUT_CLIENT_PATH_VAR:="MONGO_X509_CLIENT_CERTIFICATE_PATH"}"
1213

1314
CLIENT_PEM=${!CLIENT_PEM_VAR_NAME:-nil}
14-
OUT_CLIENT_P12_VAR="${OUTPUT_VAR_PREFIX}_CLIENT_P12"
15-
OUT_CLIENT_PASSWORD_VAR="${OUTPUT_VAR_PREFIX}_CERTIFICATE_PASSWORD"
16-
OUT_CLIENT_PATH_VAR="${OUTPUT_VAR_PREFIX}_CERTIFICATE_PATH"
17-
18-
# Default values for output variables (can be overridden via the environment)
19-
export "${OUT_CLIENT_P12_VAR}"="${!OUT_CLIENT_P12_VAR:-client.p12}"
20-
export "${OUT_CLIENT_PASSWORD_VAR}"="${!OUT_CLIENT_PASSWORD_VAR:-Picard-Alpha-Alpha-3-0-5}"
2115

2216
if [[ "$CLIENT_PEM" == "nil" ]]; then
2317
echo "Error: ${CLIENT_PEM_VAR_NAME} must be set."
2418
exit 1
2519
fi
2620

27-
P12_FILENAME=${!OUT_CLIENT_P12_VAR}
28-
CERT_PASSWORD=${!OUT_CLIENT_PASSWORD_VAR}
29-
3021
openssl pkcs12 -export -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -macalg sha1 -in "${CLIENT_PEM}" \
3122
-out "${P12_FILENAME}" \
32-
-name "${CERTIFICATE_NAME}" \
33-
-password "pass:${CERT_PASSWORD}"
23+
-name "${FRIENDLY_NAME}" \
24+
-password "pass:${P12_PASSWORD}"
3425

3526
# Determine path using realpath (compatible across macOS, Linux, and Windows)
3627
if [[ "$OS" =~ MAC|Mac|mac ]]; then
@@ -55,9 +46,9 @@ if [[ "$OS" =~ Windows|windows ]]; then
5546
CERT_PATH=$(cygpath -w "${CERT_PATH}")
5647
fi
5748

49+
export "${OUT_CLIENT_PASSWORD_VAR}"="${P12_PASSWORD}"
5850
export "${OUT_CLIENT_PATH_VAR}"="${CERT_PATH}"
5951

6052
echo "Exported variables:"
61-
echo "${OUT_CLIENT_P12_VAR}=${!OUT_CLIENT_P12_VAR}"
6253
echo "${OUT_CLIENT_PASSWORD_VAR}=${!OUT_CLIENT_PASSWORD_VAR}"
6354
echo "${OUT_CLIENT_PATH_VAR}=${!OUT_CLIENT_PATH_VAR}"

evergreen/run-tests.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ if [[ "$CLIENT_PEM" != "nil" ]]; then
134134
CLIENT_PEM=${CLIENT_PEM} source evergreen/convert-client-cert-to-pkcs12.sh
135135
fi
136136

137+
#TODO need to remove this from here
137138
if [[ "$CLIENT_NO_USER_PEM" != "nil" ]]; then
138139
export CLIENT_PEM_VAR_NAME="CLIENT_NO_USER_PEM"
139-
export OUTPUT_VAR_PREFIX="MONGO_X509_CLIENT_NO_USER"
140-
export CERTIFICATE_NAME="Drivers No-User Client Certificate"
141-
export MONGO_X509_CLIENT_NO_USER_CLIENT_P12="client_no_user.p12"
140+
export FRIENDLY_NAME="Drivers No-User Client Certificate"
141+
export P12_FILENAME="client_no_user.p12"
142+
export OUT_CLIENT_PASSWORD_VAR="MONGO_X509_CLIENT_NO_USER_CERTIFICATE_PASSWORD"
143+
export OUT_CLIENT_PATH_VAR="MONGO_X509_CLIENT_NO_USER_CERTIFICATE_PATH"
142144
CLIENT_NO_USER_PEM=${CLIENT_NO_USER_PEM} source evergreen/convert-client-cert-to-pkcs12.sh
143145
fi
144146

0 commit comments

Comments
 (0)