Skip to content

Commit 339e3df

Browse files
committed
NRL-1595 Create script to pull truststore certs for all environments in a given account
1 parent 933f31c commit 339e3df

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SMOKE_TEST_ARGS ?=
1212
FEATURE_TEST_ARGS ?= ./tests/features --format progress2
1313
TF_WORKSPACE_NAME ?= $(shell terraform -chdir=terraform/infrastructure workspace show)
1414
ENV ?= dev
15+
ACCOUNT ?= dev
1516
APP_ALIAS ?= default
1617
HOST ?= $(TF_WORKSPACE_NAME).api.record-locator.$(ENV).national.nhs.uk
1718
ENV_TYPE ?= $(ENV)
@@ -201,6 +202,9 @@ truststore-build-ca: check-warn ## Build a CA (Certificate Authority)
201202
truststore-build-cert: check-warn ## Build a certificate
202203
@./scripts/truststore.sh build-cert "$(CA_NAME)" "$(CERT_NAME)" "$(CERT_SUBJECT)"
203204

205+
truststore-pull-all-for-account: check-warn ## Pull all certificates for each environment in a given account
206+
@./scripts/truststore.sh pull-all-for-account "$(ACCOUNT)"
207+
204208
truststore-pull-all: check-warn ## Pull all certificates
205209
@./scripts/truststore.sh pull-all "$(ENV)"
206210

scripts/get-envs-for-account.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Get the name of all environments in a provided NRLF account
3+
set -o errexit -o nounset -o pipefail
4+
5+
if [ $# -ne 1 ]; then
6+
echo "Usage: get-envs-for-account.sh <account>"
7+
exit 1
8+
fi
9+
10+
account="$1"
11+
12+
case "${account}" in
13+
dev)
14+
envs_array=("dev") # "dev-sandbox")
15+
echo ${envs_array[@]}
16+
;;
17+
test)
18+
envs_array=("qa" "perftest" "ref" "int") # "int-sandbox" "qa-sandbox") - I don't have perms for these!
19+
echo ${envs_array[@]}
20+
;;
21+
prod)
22+
envs_array=("prod")
23+
echo ${envs_array[@]}
24+
;;
25+
*)
26+
echo "Unknown account ${account}"
27+
exit 1
28+
esac

scripts/truststore.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ function _truststore_pull_server() {
303303

304304
function _truststore_pull_all() {
305305
env=$1
306+
306307
_truststore_pull_ca $env
307308
_truststore_pull_client $env
308309
_truststore_pull_server $env
@@ -311,6 +312,25 @@ function _truststore_pull_all() {
311312
return 0
312313
}
313314

315+
function _truststore_pull_all_for_account() {
316+
account=$1
317+
318+
# sets envs_array
319+
source ./scripts/get-envs-for-account.sh $account
320+
321+
echo "Pulling certs for environments ${envs_array[@]} in ${account} account"
322+
323+
for env in ${envs_array[@]}; do
324+
echo "⏳ Pulling ${env} truststore certs"
325+
_truststore_pull_ca $env
326+
_truststore_pull_client $env
327+
_truststore_pull_server $env
328+
done
329+
330+
echo -e "✅ Successfully pulled all ${account} truststore files from s3://${BUCKET}"
331+
return 0
332+
}
333+
314334
function _truststore_push_all() {
315335
env=$1
316336

@@ -364,6 +384,7 @@ function _truststore() {
364384
"build-ca") _truststore_build_ca $args ;;
365385
"build-cert") _truststore_build_cert $args ;;
366386
"pull-all") _truststore_pull_all $args ;;
387+
"pull-all-for-account") _truststore_pull_all_for_account $args ;;
367388
"pull-server") _truststore_pull_server $args ;;
368389
"pull-client") _truststore_pull_client $args ;;
369390
"pull-ca") _truststore_pull_ca $args ;;

0 commit comments

Comments
 (0)