Skip to content

Commit 72d97cb

Browse files
Merge pull request #1087 from NHSDigital/bugfix/made14-NRL-1700-truststore-sh-fixes
[NRL-1700] Fixup error handling in truststore rotate functions
2 parents ac4f828 + 152ab8e commit 72d97cb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

scripts/truststore.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ function _truststore_rotate_ca() {
142142
env="$1"
143143
fqdn="$2"
144144

145+
if [[ ! -f "truststore/ca/$env.crt" ]] ||
146+
[[ ! -f "truststore/ca/$env.key" ]] ||
147+
[[ ! -f "truststore/server/$env.pem" ]]; then
148+
echo "Error: One or more ca cert truststore files not found for environment $env - cannot rotate CA" 1>&2
149+
echo "Try running this first:" 1>&2
150+
echo " $0 pull-all $env && $0 pull-ca-key dev" 1>&2
151+
return 1
152+
fi
153+
145154
# Archive the existing ca certs
146155
archive_date="$(date +%Y-%m-%d)"
147156
if [[ -f "truststore/ca/$env.archived_$archive_date.crt" ]] ||
@@ -176,6 +185,14 @@ function _truststore_rotate_cert() {
176185
ca_name="$2"
177186
fqdn="$3"
178187

188+
if [[ ! -f "truststore/client/$cert_name.crt" ]] ||
189+
[[ ! -f "truststore/client/$cert_name.key" ]]; then
190+
echo "Error: One or more client cert truststore files not found for $cert_name - cannot rotate client cert" 1>&2
191+
echo "Try running this first:" 1>&2
192+
echo " $0 pull-all $cert_name" 1>&2
193+
return 1
194+
fi
195+
179196
# Archive the existing client certs
180197
archive_date=$(date +%Y-%m-%d)
181198
if [[ -f "truststore/client/$cert_name.archived_$archive_date.crt" ]] ||

0 commit comments

Comments
 (0)