Skip to content

Commit cf5003f

Browse files
committed
WIP: Added AWS account check and updated make commands
1 parent 7f3031b commit cf5003f

2 files changed

Lines changed: 83 additions & 27 deletions

File tree

Makefile

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,58 +53,67 @@ config:: # Configure development environment (main) @Configuration
5353
#### Proxygen ####
5454
##################
5555

56-
retrieve-proxygen-key: # Obtain the 'machine user' credentials from AWS SSM (Development environment)
57-
mkdir -p ~/.proxygen && \
58-
aws ssm get-parameter --name /proxygen/private_key_temp --with-decryption | jq ".Parameter.Value" --raw-output \
59-
> ~/.proxygen/eligibility-signposting-api.pem
56+
# retrieve-proxygen-key: # Obtain the 'machine user' credentials from AWS SSM (Development environment)
57+
# mkdir -p ~/.proxygen && \
58+
# aws ssm get-parameter --name /proxygen/private_key_temp --with-decryption | jq ".Parameter.Value" --raw-output \
59+
# > ~/.proxygen/eligibility-signposting-api.pem
6060

6161
# retrieve-proxygen-key: # Obtain the 'machine user' credentials from AWS SSM (Development environment)
6262
# mkdir -p ~/.proxygen && \
6363
# aws ssm get-parameter --name /proxygen/private_key_temp_$(ENV) --with-decryption | jq ".Parameter.Value" --raw-output \
6464
# > ~/.proxygen/eligibility-signposting-api-$(ENV).pem
65-
66-
retrieve-proxygen-key-ptl:
67-
$(MAKE) retrieve-proxygen-key ENV=ptl
68-
69-
retrieve-proxygen-key-prod:
70-
$(MAKE) retrieve-proxygen-key ENV=prod
71-
72-
setup-proxygen-credentials:
73-
cd specification && \
65+
#
66+
# retrieve-proxygen-key-ptl:
67+
# $(MAKE) retrieve-proxygen-key ENV=ptl
68+
#
69+
# retrieve-proxygen-key-prod:
70+
# $(MAKE) retrieve-proxygen-key ENV=prod
71+
72+
# Verify current AWS account login and retrieve the proxygen key
73+
# from AWS SSM for the specified environment
74+
retrieve-proxygen-key: guard-ENV
75+
@ ./scripts/check-aws-account.sh $(ENV)
76+
mkdir -p ~/.proxygen
77+
aws ssm get-parameter --name /proxygen/private_key_temp --with-decryption \
78+
| jq -r ".Parameter.Value" \
79+
> ~/.proxygen/eligibility-signposting-api-$(ENV).pem && \
80+
echo "Retrieved proxygen key for '$(ENV)' environment"
81+
82+
# Copy proxygen credentials for the specified environment to `~/.proxygen/`
83+
# This location required location for local proxygen usage
84+
setup-proxygen-credentials: guard-ENV
85+
@ cd specification && \
7486
cp .proxygen/credentials-$(ENV).yaml ~/.proxygen/credentials.yaml && \
75-
cp .proxygen/settings-$(ENV).yaml ~/.proxygen/settings.yaml
76-
77-
setup-proxygen-credentials-ptl:
78-
$(MAKE) setup-proxygen-credentials ENV=ptl
79-
80-
setup-proxygen-credentials-prod:
81-
$(MAKE) setup-proxygen-credentials ENV=prod
87+
cp .proxygen/settings-$(ENV).yaml ~/.proxygen/settings.yaml && \
88+
echo "Set up proxygen credentials for the '$(ENV)' environment"
8289

8390
get-spec: # Get the most recent specification live in proxygen
84-
$(MAKE) setup-proxygen-credentials-prod
91+
$(MAKE) setup-proxygen-credentials ENV=prod
8592
proxygen spec get
8693

8794
get-spec-uat: # Get the most recent specification live in proxygen
88-
$(MAKE) setup-proxygen-credentials-ptl
95+
$(MAKE) setup-proxygen-credentials ENV=ptl
8996
proxygen spec get --uat
9097

9198
publish-spec: # Publish the specification to proxygen
92-
$(MAKE) setup-proxygen-credentials-prod
99+
$(MAKE) setup-proxygen-credentials ENV=prod
93100
proxygen spec publish build/specification/prod/eligibility-signposting-api.yaml
94101

95102
publish-spec-uat: # Publish the specification to proxygen
96-
$(MAKE) setup-proxygen-credentials-ptl
103+
$(MAKE) setup-proxygen-credentials ENV=ptl
97104
proxygen spec publish build/specification/preprod/eligibility-signposting-api.yaml --uat
98105

99106
delete-spec: # Delete the specification from proxygen
100-
$(MAKE) setup-proxygen-credentials-prod
107+
$(MAKE) setup-proxygen-credentials ENV=prod
101108
proxygen spec delete
102109

103110
delete-spec-uat: # Delete the specification from proxygen
104-
$(MAKE) setup-proxygen-credentials-ptl
111+
$(MAKE) setup-proxygen-credentials ENV=ptl
105112
proxygen spec delete --uat
106113

107-
# Specification
114+
#####################
115+
### Specification ###
116+
#####################
108117

109118
guard-%:
110119
@ if [ "${${*}}" = "" ]; then \

scripts/check-aws-account.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
#!/usr/bin/env bash
3+
set -e
4+
5+
APIM_ENV_NAME="$1"
6+
7+
# Map APIM environment names to AWS account ID and environment name
8+
case "$APIM_ENV_NAME" in
9+
dev)
10+
AWS_ENV_NAME="dev"
11+
EXPECTED_ACCOUNT="448049830832"
12+
;;
13+
ptl)
14+
AWS_ENV_NAME="preprod" # Called 'preprod' in AWS and `ptl` in APIM
15+
EXPECTED_ACCOUNT="203918864209"
16+
;;
17+
prod)
18+
AWS_ENV_NAME="prod"
19+
EXPECTED_ACCOUNT="333333333333"
20+
;;
21+
*)
22+
echo "Unknown APIM environment: $APIM_ENV_NAME"
23+
exit 1
24+
;;
25+
esac
26+
27+
# Read the currently authenticated AWS account
28+
CURRENT_ACCOUNT=$(aws sts get-caller-identity --query "Account" --output text)
29+
30+
# Compare the current account with the expected account
31+
if [ "$CURRENT_ACCOUNT" != "$EXPECTED_ACCOUNT" ]; then
32+
echo "AWS account mismatch!"
33+
# MSG="The 'ENV' arg '$APIM_ENV_NAME' for APIM maps to the AWS env '$AWS_ENV_NAME' and account $EXPECTED_ACCOUNT, but the current AWS account is $CURRENT_ACCOUNT."
34+
# echo "$MSG"
35+
# echo "The 'ENV' arg $APIM_ENV_NAME for APIM maps to the AWS env $AWS_ENV_NAME and account $EXPECTED_ACCOUNT, but the current AWS account is $CURRENT_ACCOUNT."
36+
# echo "APIM environment : $APIM_ENV_NAME"
37+
# echo "Expected AWS environment: $AWS_ENV_NAME"
38+
# echo "Expected account: $EXPECTED_ACCOUNT"
39+
# echo "Actual account : $CURRENT_ACCOUNT"
40+
# echo "The APIM '$APIM_ENV_NAME' environment is mapped to the AWS '$AWS_ENV_NAME' environment and account $EXPECTED_ACCOUNT, but the current AWS account is $CURRENT_ACCOUNT."
41+
echo "The expected mapping for the argument 'ENV=$APIM_ENV_NAME' is AWS '$AWS_ENV_NAME' account $EXPECTED_ACCOUNT, but the current AWS account is $CURRENT_ACCOUNT."
42+
echo "Please switch to the correct AWS account and try again."
43+
echo "Exiting script..."
44+
exit 1
45+
fi
46+
47+
echo "Active login to AWS '$AWS_ENV_NAME' account $CURRENT_ACCOUNT verified."

0 commit comments

Comments
 (0)