Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: [AEA-3616] - Create the Clinical Prescription Tracker API endpoint on Apigee #469

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
14c0817
Add the specification package
kris-szlapa Sep 9, 2024
e190234
Add the deploy_api and delete_proxygen_deployments scripts
kris-szlapa Sep 9, 2024
a2dc922
Add jest config files to the specification package
kris-szlapa Sep 10, 2024
8849c9d
Add package specification to workspaces
kris-szlapa Sep 11, 2024
3453cf3
Add the specification and update Makefile
kris-szlapa Sep 11, 2024
9b03c10
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Sep 11, 2024
1f85a5e
Update package-lock file
kris-szlapa Sep 11, 2024
d18e56d
Add run_package_code_and_api and run_release_code_and_api workflows
kris-szlapa Sep 13, 2024
fd8c24f
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Sep 13, 2024
6483c2a
Update packages
kris-szlapa Sep 13, 2024
5228c25
Update poetry libraries
kris-szlapa Sep 13, 2024
a2e3471
Update packages
kris-szlapa Sep 13, 2024
1230aab
Fix eps-spine-client and check-isenses issues
kris-szlapa Sep 13, 2024
c96214a
Add package specification to workspaces
kris-szlapa Sep 13, 2024
1f5b706
Update the Workflows paragraph in the README file
kris-szlapa Sep 13, 2024
40777c8
Add the esbuild dependency
kris-szlapa Sep 13, 2024
181c5ce
Use run_release_code_and_api workflow
kris-szlapa Sep 13, 2024
70943b5
Remove guard target_spine_server from Makefile
kris-szlapa Sep 13, 2024
8d010d8
Add the upload specification artifact step
kris-szlapa Sep 13, 2024
f1e8f75
Use run_package_code_and_api workflow
kris-szlapa Sep 13, 2024
6c49871
Rename the specification file to eps-clinical-prescription-tracker-api
kris-szlapa Sep 13, 2024
9bf945a
Break down the Package code step
kris-szlapa Sep 13, 2024
a05f875
Update statusLambda dependencies
kris-szlapa Sep 13, 2024
e81a207
Add a path to sam build step
kris-szlapa Sep 13, 2024
029bf88
Add make compile-specification command to the sam build step
kris-szlapa Sep 13, 2024
c5cf614
Fix clinical-prescription-tracker naming
kris-szlapa Sep 13, 2024
b2d42ec
Correct export specification path
kris-szlapa Sep 13, 2024
4a7dabe
Fix extracting the PR ID from STACK_NAME
kris-szlapa Sep 13, 2024
f2cd8b4
Add missing PROXYGEN_ROLE secrets
kris-szlapa Sep 13, 2024
96b4dc2
Update the README file
kris-szlapa Sep 13, 2024
a55b84d
Remove PROXYGEN_PATH env variable
kris-szlapa Sep 13, 2024
31f11de
Rename api to prescription-clinical-tracker in the deploy_api script
kris-szlapa Sep 13, 2024
d79210e
Remove unnecessary workflows
kris-szlapa Sep 13, 2024
725ba7c
Remove unnecessary variables
kris-szlapa Sep 13, 2024
13333ff
Add hardcoded values for testing
kris-szlapa Sep 13, 2024
827c760
Add proxygen testing values
kris-szlapa Sep 13, 2024
df99ed6
Fix test deployment script
kris-szlapa Sep 13, 2024
20bba4a
Remove code for testing
kris-szlapa Sep 13, 2024
6e70a8a
Restore teh export specification paths path
kris-szlapa Sep 13, 2024
6986a5d
Add prescription-clinical-tracker variables in the script
kris-szlapa Sep 13, 2024
8683cb3
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Sep 16, 2024
1783c53
Update poetry lock file
kris-szlapa Sep 16, 2024
1c299b5
Rename api
kris-szlapa Sep 16, 2024
5a85d23
Merge branch 'main' of https://github.com/NHSet api name to prescript…
kris-szlapa Sep 16, 2024
d6a0cb7
Rename api mane in delete_proxygen_deployments script to prescription…
kris-szlapa Sep 16, 2024
06bb903
Deploy mTLS key
kris-szlapa Sep 16, 2024
8a4550f
Set up proxygen credentials and settings
kris-szlapa Sep 16, 2024
25b468a
Print client_private_key_path
kris-szlapa Sep 16, 2024
4a09a3e
Amend the private_key_path
kris-szlapa Sep 16, 2024
f7bf59b
Remove username and password from credentials
kris-szlapa Sep 16, 2024
9358a06
Change paths to deploy mTLS key
kris-szlapa Sep 16, 2024
4523261
Reset paths to deploy mTLS key
kris-szlapa Sep 16, 2024
fb317d7
Add pem suffix to deploy mTLS key step
kris-szlapa Sep 16, 2024
85cb155
Add the proxygen_private_key value to tmp folder
kris-szlapa Sep 16, 2024
b95f1f1
Correct proxygen_private_key value
kris-szlapa Sep 16, 2024
ec8b7af
Add pem suffix
kris-szlapa Sep 16, 2024
fa1ae82
Change private_key_path
kris-szlapa Sep 16, 2024
62aea7e
Remove proxygen-cli deployment
kris-szlapa Sep 16, 2024
21fbd59
Deploy the API instance using Proxygen proxy lambda with clinical-tra…
kris-szlapa Sep 16, 2024
9ad077a
Store the secret used for mutual TLS to AWS using Proxygen proxy lambda
kris-szlapa Sep 16, 2024
28b2aa9
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Sep 24, 2024
8c45e2a
Update packages
kris-szlapa Sep 24, 2024
dfa5726
Correct eps-spine-client import to statusLambda
kris-szlapa Sep 24, 2024
e8dec18
Add packages to the sonar coverage excusions list
kris-szlapa Sep 24, 2024
2cc67f2
Comment out the SonarCloud Scan step
kris-szlapa Sep 24, 2024
d491303
Reset is_pull_request to false in deploy_api script
kris-szlapa Sep 24, 2024
e00024a
Turn on the SonarCloud Scan step
kris-szlapa Sep 24, 2024
8d3a812
Update specification
kris-szlapa Sep 24, 2024
3a5b114
Replace securitySchemes app-level0
kris-szlapa Sep 24, 2024
2acc4cb
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Sep 24, 2024
93ff537
Change the STACK_NAME in the deploy_api script to cpt
kris-szlapa Sep 25, 2024
a0b8083
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Sep 25, 2024
191539d
Update poetry lock file
kris-szlapa Sep 25, 2024
8c2a4ba
Change the STACK_NAME for the Sandbox to cpt-pr-<number>-sandbox
kris-szlapa Sep 25, 2024
e41d799
Rename target url to cpt
kris-szlapa Sep 26, 2024
6937777
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Sep 26, 2024
e244179
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Sep 26, 2024
0b99d71
Update packages
kris-szlapa Sep 26, 2024
7b432b3
Update nhsdigital package and imports
kris-szlapa Sep 26, 2024
829d975
Upgrade asdf_branch version
kris-szlapa Sep 26, 2024
53a71c7
Rename the api to clinical-prescription-tracker
kris-szlapa Sep 30, 2024
da4edcc
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Sep 30, 2024
0b6fd9e
Store the secret used for mutual TLS to AWS using Proxygen proxy lambda
kris-szlapa Sep 30, 2024
29d32be
Reset is_pull_request check to false
kris-szlapa Sep 30, 2024
da191b0
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Oct 1, 2024
a4f3416
Upgrade packages
kris-szlapa Oct 1, 2024
17e5fc1
Implement json-schema-to-ts approach
kris-szlapa Oct 2, 2024
42166d8
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Oct 2, 2024
09f90a5
Add compile-specification to the compile command to fix lint
kris-szlapa Oct 2, 2024
1dff199
Amend lint-node command
kris-szlapa Oct 2, 2024
f520857
Amend compile-specification comment
kris-szlapa Oct 3, 2024
3e23956
Add error handling to the extractSchemas script
kris-szlapa Oct 3, 2024
1efec5a
Add the compile-packages command
kris-szlapa Oct 3, 2024
edcbed0
Remove redundant sam templates
kris-szlapa Oct 3, 2024
7e00e4d
Remove redundant oas
kris-szlapa Oct 3, 2024
765ab7e
Add the lint-prescription-search step to the pre-commit-hooks list
kris-szlapa Oct 3, 2024
dbdc045
Add the specification package description to the documentation
kris-szlapa Oct 3, 2024
f84faeb
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Oct 3, 2024
ec5b658
Add the specification package to tsconfig build
kris-szlapa Oct 3, 2024
cf0850e
Update the workspace folders
kris-szlapa Oct 3, 2024
20d9a8c
Add the scripts folder to tsconfig file
kris-szlapa Oct 3, 2024
02425a2
Fix the extractSchemas script
kris-szlapa Oct 3, 2024
b9d0bd4
Rename the package to clinicalView to follow the naming convention
kris-szlapa Oct 3, 2024
fce4f7a
Update the clean command in the Makefile
kris-szlapa Oct 3, 2024
73c31af
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Oct 3, 2024
1268dee
Update poetry lock file
kris-szlapa Oct 3, 2024
ef7f6b8
Remove the unnecessary schema and update the code
kris-szlapa Oct 3, 2024
cef0a82
Override the eslint rule
kris-szlapa Oct 3, 2024
024d0c9
Merge branch 'main' into AEA-3616-create-clinical-prescription-tracke…
kris-szlapa Oct 4, 2024
9f8a010
Cleanup the code
kris-szlapa Oct 4, 2024
237a675
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Oct 7, 2024
de8f69d
Upgrade the eps-spine-client package
kris-szlapa Oct 7, 2024
18ca952
Merge branch 'main' of https://github.com/NHSDigital/electronic-presc…
kris-szlapa Oct 7, 2024
504beb6
Upgrade pre-commit package
kris-szlapa Oct 7, 2024
1ce8e30
Remove unnecessary package
kris-szlapa Oct 7, 2024
527df98
Fix eps-spine-client package
kris-szlapa Oct 7, 2024
7a1cc7c
Restore correct confluence page numbers
kris-szlapa Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/scripts/delete_proxygen_deployments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

# Generic script for removing proxygen deployed APIs where the pull request is closed

# Set the repo name to be the name of the repo this is running in
REPO_NAME=electronic-prescription-service-clinical-prescription-tracker

# Main function to delete relevant proxygen deployments
main() {
echo "Checking clinical tracker deployments"
PULL_REQUEST_PROXYGEN_REGEX=clinical-prescription-tracker-pr-
delete_apigee_deployments "internal-dev" "clinical-prescription-tracker" "ClinicalTrackerProxygenPrivateKey" "eps-clinical-tracker"
delete_apigee_deployments "internal-dev-sandbox" "clinical-prescription-tracker" "ClinicalTrackerProxygenPrivateKey" "eps-clinical-tracker"
}

# Function to delete Apigee deployments
delete_apigee_deployments() {
APIGEE_ENVIRONMENT=$1
APIGEE_API=$2
PROXYGEN_PRIVATE_KEY_NAME=$3
PROXYGEN_KID=$4
proxygen_private_key_arn=$(aws cloudformation list-exports --query "Exports[?Name=='account-resources:${PROXYGEN_PRIVATE_KEY_NAME}'].Value" --output text)

echo
echo "Checking Apigee deployments on ${APIGEE_ENVIRONMENT}"
echo

jq -n --arg apiName "${APIGEE_API}" \
--arg environment "${APIGEE_ENVIRONMENT}" \
--arg kid "${PROXYGEN_KID}" \
--arg proxygenSecretName "${proxygen_private_key_arn}" \
'{apiName: $apiName, environment: $environment, kid, $kid, proxygenSecretName: $proxygenSecretName}' > payload.json

aws lambda invoke --function-name "lambda-resources-ProxygenPTLInstanceGet" --cli-binary-format raw-in-base64-out --payload file://payload.json out.json > response.json

if eval "cat response.json | jq -e '.FunctionError' >/dev/null"; then
echo 'Error calling lambda'
cat out.json
exit 1
fi

jq -r '.[].name' "out.json" | while read -r i; do
echo "Checking if Apigee deployment $i has open pull request"
PULL_REQUEST=${i//${PULL_REQUEST_PROXYGEN_REGEX}/}
echo "Checking pull request ID ${PULL_REQUEST}"
URL="https://api.github.com/repos/NHSDigital/${REPO_NAME}/pulls/${PULL_REQUEST}"
RESPONSE=$(curl "${URL}" 2>/dev/null)
STATE=$(echo "${RESPONSE}" | jq -r .state)
if [ "$STATE" == "closed" ]; then
echo "** Going to delete Apigee deployment $i as state is ${STATE} **"
jq -n --arg apiName "${APIGEE_API}" \
--arg environment "${APIGEE_ENVIRONMENT}" \
--arg instance "${i}" \
--arg kid "${PROXYGEN_KID}" \
--arg proxygenSecretName "${proxygen_private_key_arn}" \
'{apiName: $apiName, environment: $environment, kid, $kid, proxygenSecretName: $proxygenSecretName, instance: $instance}' > payload.json

aws lambda invoke --function-name "lambda-resources-ProxygenPTLInstanceDelete" --cli-binary-format raw-in-base64-out --payload file://payload.json out.txt > response.json
if eval "cat response.json | jq -e '.FunctionError' >/dev/null"; then
echo 'Error calling lambda'
cat out.txt
exit 1
fi

else
echo "Not going to delete Apigee deployment $i as state is ${STATE}"
fi
done
}

main
13 changes: 5 additions & 8 deletions .github/scripts/delete_stacks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
REPO_NAME=electronic-prescription-service-clinical-prescription-tracker

# this should be a regex used in jq command that parses the output from aws cloudformation list-stacks and just captures stacks we are interested in
CAPTURE_REGEX="^cpt-(sandbox-)?pr-(\\d+)$"
CAPTURE_REGEX="^cpt-pr-(\\d+)(-sandbox)?$"

# this should be a regex that is used to get the pull request id from the cloud formation stack name
# this is used in a replace command to replace the stack name so what is left is just the pull request id
PULL_REQUEST_STACK_REGEX=cpt-pr-
SANDBOX_PULL_REQUEST_STACK_REGEX=cpt-sandbox-pr-

CNAME_QUERY=cpt-pr
CNAME_SANDBOX_QUERY=cpt-sandbox-pr
CNAME_QUERY=cpt-pr-

# this should be customised to delete cloudformation stacks and proxygen deployments if they are used
main() {
delete_cloudformation_stacks
delete_cname_records
Expand All @@ -33,10 +30,10 @@ delete_cloudformation_stacks() {
do
echo "Checking if stack $i has open pull request"
PULL_REQUEST=${i//${PULL_REQUEST_STACK_REGEX}/}
PULL_REQUEST=${PULL_REQUEST//${SANDBOX_PULL_REQUEST_STACK_REGEX}/}
PULL_REQUEST=${PULL_REQUEST//-sandbox/}
echo "Checking pull request id ${PULL_REQUEST}"
URL="https://api.github.com/repos/NHSDigital/${REPO_NAME}/pulls/${PULL_REQUEST}"
RESPONSE=$(curl --url "${URL}" --header "Authorization: Bearer ${GITHUB_TOKEN}" 2>/dev/null)
RESPONSE=$(curl "${URL}" 2>/dev/null)
STATE=$(echo "${RESPONSE}" | jq -r .state)
if [ "$STATE" == "closed" ]; then
echo "** going to delete stack $i as state is ${STATE} **"
Expand All @@ -52,7 +49,7 @@ delete_cloudformation_stacks() {
delete_cname_records() {
HOSTED_ZONE_ID=$(aws route53 list-hosted-zones-by-name --dns-name dev.eps.national.nhs.uk. | jq -r ".HostedZones[0] | .Id")
CNAME_RECORDS=$(aws route53 list-resource-record-sets --hosted-zone-id "${HOSTED_ZONE_ID}" \
--query "ResourceRecordSets[?Type == 'CNAME' && (contains(Name, '${CNAME_QUERY}') || contains(Name, '${CNAME_SANDBOX_QUERY}'))]" \
--query "ResourceRecordSets[?Type == 'CNAME' && contains(Name, '${CNAME_QUERY}')]" \
| jq -r " .[] | .Name")

mapfile -t CNAME_RECORDS_ARRAY <<< "$CNAME_RECORDS"
Expand Down
197 changes: 197 additions & 0 deletions .github/scripts/deploy_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#!/usr/bin/env bash
set -eu pipefail

echo "Specification path: ${SPEC_PATH}"
echo "Specification version: ${VERSION_NUMBER}"
echo "Stack name: ${STACK_NAME}"
echo "AWS environment: ${TARGET_ENVIRONMENT}"
echo "Apigee environment: ${APIGEE_ENVIRONMENT}"
echo "Proxygen private key name: ${PROXYGEN_PRIVATE_KEY_NAME}"
echo "Proxygen KID: ${PROXYGEN_KID}"
echo "Dry run: ${DRY_RUN}"

client_private_key=$(cat ~/.proxygen/tmp/client_private_key)
client_cert=$(cat ~/.proxygen/tmp/client_cert)

if [ -z "${client_private_key}" ]; then
echo "client_private_key is unset or set to the empty string"
exit 1
fi
if [ -z "${client_cert}" ]; then
echo "client_cert is unset or set to the empty string"
exit 1
fi

put_secret_lambda=lambda-resources-ProxygenPTLMTLSSecretPut
instance_put_lambda=lambda-resources-ProxygenPTLInstancePut
spec_publish_lambda=lambda-resources-ProxygenPTLSpecPublish

if [[ "$APIGEE_ENVIRONMENT" =~ ^(int|sandbox|prod)$ ]]; then
put_secret_lambda=lambda-resources-ProxygenProdMTLSSecretPut
instance_put_lambda=lambda-resources-ProxygenProdInstancePut
spec_publish_lambda=lambda-resources-ProxygenProdSpecPublish
fi

is_pull_request=false
instance_suffix=""
if [[ ${STACK_NAME} == cpt-pr-* ]]; then
is_pull_request=true
# Extracting the PR ID from $STACK_NAME
pr_id=$(echo "${STACK_NAME}" | cut -d'-' -f3)
instance_suffix=-"pr-${pr_id}"
fi

# Determine the proxy instance based on the provided $STACK_NAME
apigee_api=clinical-prescription-tracker
instance="clinical-prescription-tracker${instance_suffix}"

echo "Is pull request: ${is_pull_request}"
echo "Proxy instance: ${instance}"
echo "Apigee api: ${apigee_api}"

echo

echo "Fixing the spec"
# Find and replace the title
title=$(jq -r '.info.title' "${SPEC_PATH}")
if [[ "${is_pull_request}" == "true" ]]; then
jq --arg title "[PR-${pr_id}] $title" '.info.title = $title' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
fi

# Find and replace the specification version number
jq --arg version "${VERSION_NUMBER}" '.info.version = $version' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"

# Find and replace the x-nhsd-apim.target.url value
jq --arg stack_name "${STACK_NAME}" --arg aws_env "${TARGET_ENVIRONMENT}" '.["x-nhsd-apim"].target.url = "https://\($stack_name).\($aws_env).eps.national.nhs.uk"' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"

# Find and replace the servers object
if [[ "${APIGEE_ENVIRONMENT}" == "prod" ]]; then
jq --arg inst "${instance}" '.servers = [ { "url": "https://api.service.nhs.uk/\($inst)" } ]' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
else
jq --arg env "${APIGEE_ENVIRONMENT}" --arg inst "${instance}" '.servers = [ { "url": "https://\($env).api.service.nhs.uk/\($inst)" } ]' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
fi

# Find and replace securitySchemes
if [[ "${APIGEE_ENVIRONMENT}" == "prod" ]]; then
jq '.components.securitySchemes."app-level0" = {"$ref": "https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/app-level0"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
else
jq '.components.securitySchemes."app-level0" = {"$ref": "https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/app-level0"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
fi

if [[ "${APIGEE_ENVIRONMENT}" == "prod" ]]; then
jq '.components.securitySchemes."app-level3" = {"$ref": "https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/app-level3"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
else
jq '.components.securitySchemes."app-level3" = {"$ref": "https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/app-level3"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
fi

# Remove target attributes if the environment is sandbox
if [[ "${APIGEE_ENVIRONMENT}" == *"sandbox"* ]]; then
echo "Removing target attributes for sandbox environment"
jq 'del(."x-nhsd-apim"."target-attributes")' "$SPEC_PATH" > temp.json && mv temp.json "${SPEC_PATH}"
fi

echo

echo "Retrieving proxygen credentials"

# Retrieve the proxygen private key and client private key and cert from AWS Secrets Manager
proxygen_private_key_arn=$(aws cloudformation list-exports --query "Exports[?Name=='account-resources:${PROXYGEN_PRIVATE_KEY_NAME}'].Value" --output text)

if [[ "${is_pull_request}" == "false" ]]; then
echo
echo "Store the secret used for mutual TLS to AWS using Proxygen proxy lambda"
if [[ "${DRY_RUN}" == "false" ]]; then
jq -n --arg apiName "${apigee_api}" \
--arg environment "${APIGEE_ENVIRONMENT}" \
--arg secretName "clinical-tracker-mtls-1" \
--arg secretKey "${client_private_key}" \
--arg secretCert "${client_cert}" \
--arg kid "${PROXYGEN_KID}" \
--arg proxygenSecretName "${proxygen_private_key_arn}" \
'{apiName: $apiName, environment: $environment, secretName: $secretName, secretKey: $secretKey, secretCert: $secretCert, kid, $kid, proxygenSecretName: $proxygenSecretName}' > payload.json

aws lambda invoke --function-name "${put_secret_lambda}" --cli-binary-format raw-in-base64-out --payload file://payload.json out.txt > response.json
if eval "cat response.json | jq -e '.FunctionError' >/dev/null"; then
echo 'Error calling lambda'
cat out.txt
exit 1
fi
echo "Secret stored successfully"
else
echo "Would call ${put_secret_lambda}"
fi
fi

echo
echo "Deploy the API instance using Proxygen proxy lambda"
if [[ "${DRY_RUN}" == "false" ]]; then

jq -n --argfile spec "${SPEC_PATH}" \
--arg apiName "${apigee_api}" \
--arg environment "${APIGEE_ENVIRONMENT}" \
--arg instance "${instance}" \
--arg kid "${PROXYGEN_KID}" \
--arg proxygenSecretName "${proxygen_private_key_arn}" \
'{apiName: $apiName, environment: $environment, specDefinition: $spec, instance: $instance, kid: $kid, proxygenSecretName: $proxygenSecretName}' > payload.json

aws lambda invoke --function-name "${instance_put_lambda}" --cli-binary-format raw-in-base64-out --payload file://payload.json out.txt > response.json

if eval "cat response.json | jq -e '.FunctionError' >/dev/null"; then
echo 'Error calling lambda'
cat out.txt
exit 1
fi
echo "Instance deployed"
else
echo "Would call ${instance_put_lambda}"
fi

if [[ "${APIGEE_ENVIRONMENT}" == "int" ]]; then
echo
echo "Deploy the API spec to prod catalogue as it is int environment"
if [[ "${DRY_RUN}" == "false" ]]; then
jq -n --argfile spec "${SPEC_PATH}" \
--arg apiName "${apigee_api}" \
--arg environment "prod" \
--arg instance "${instance}" \
--arg kid "${PROXYGEN_KID}" \
--arg proxygenSecretName "${proxygen_private_key_arn}" \
'{apiName: $apiName, environment: $environment, specDefinition: $spec, instance: $instance, kid: $kid, proxygenSecretName: $proxygenSecretName}' > payload.json

aws lambda invoke --function-name "${spec_publish_lambda}" --cli-binary-format raw-in-base64-out --payload file://payload.json out.txt > response.json

if eval "cat response.json | jq -e '.FunctionError' >/dev/null"; then
echo 'Error calling lambda'
cat out.txt
exit 1
fi
echo "Spec deployed"
else
echo "Would call ${spec_publish_lambda}"
fi
fi

if [[ "${APIGEE_ENVIRONMENT}" == "internal-dev" && "${is_pull_request}" == "false" ]]; then
echo
echo "Deploy the API spec to uat catalogue as it is internal-dev environment"
if [[ "${DRY_RUN}" == "false" ]]; then
jq -n --argfile spec "${SPEC_PATH}" \
--arg apiName "${apigee_api}" \
--arg environment "uat" \
--arg instance "${instance}" \
--arg kid "${PROXYGEN_KID}" \
--arg proxygenSecretName "${proxygen_private_key_arn}" \
'{apiName: $apiName, environment: $environment, specDefinition: $spec, instance: $instance, kid: $kid, proxygenSecretName: $proxygenSecretName}' > payload.json

aws lambda invoke --function-name "${spec_publish_lambda}" --cli-binary-format raw-in-base64-out --payload file://payload.json out.txt > response.json

if eval "cat response.json | jq -e '.FunctionError' >/dev/null"; then
echo 'Error calling lambda'
cat out.txt
exit 1
fi
echo "Spec deployed"
else
echo "Would call ${spec_publish_lambda}"
fi
fi
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,17 @@ jobs:

package_code:
needs: tag_release
uses: ./.github/workflows/sam_package_code.yml
uses: ./.github/workflows/run_package_code_and_api.yml

release_dev:
needs: [tag_release, package_code, get_commit_id]
uses: ./.github/workflows/sam_release_code.yml
uses: ./.github/workflows/run_release_code_and_api.yml
with:
ARTIFACT_BUCKET_PREFIX: ${{needs.tag_release.outputs.version_tag}}
STACK_NAME: cpt
TARGET_ENVIRONMENT: dev
APIGEE_ENVIRONMENT: internal-dev
ENABLE_MUTUAL_TLS: true
DEPLOY_SANDBOX: false
BUILD_ARTIFACT: packaged_code
TRUSTSTORE_FILE: clinical-tracker-truststore.pem
VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
Expand All @@ -118,22 +117,22 @@ jobs:
CREATE_PROD_RELEASE_NOTES: true
secrets:
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_DEPLOY_ROLE }}
TARGET_SPINE_SERVER: ${{ secrets.DEV_TARGET_SPINE_SERVER }}
# TARGET_SPINE_SERVER: ${{ secrets.DEV_TARGET_SPINE_SERVER }}
DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE }}
INT_CLOUD_FORMATION_CHECK_VERSION_ROLE: ${{ secrets.INT_CLOUD_FORMATION_CHECK_VERSION_ROLE }}
PROD_CLOUD_FORMATION_CHECK_VERSION_ROLE: ${{ secrets.PROD_CLOUD_FORMATION_CHECK_VERSION_ROLE }}
DEV_CLOUD_FORMATION_EXECUTE_LAMBDA_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_EXECUTE_LAMBDA_ROLE }}
PROXYGEN_ROLE: ${{ secrets.PROXYGEN_PTL_ROLE }}

release_dev_sandbox:
needs: [tag_release, package_code, get_commit_id]
uses: ./.github/workflows/sam_release_code.yml
uses: ./.github/workflows/run_release_code_and_api.yml
with:
ARTIFACT_BUCKET_PREFIX: ${{needs.tag_release.outputs.version_tag}}
STACK_NAME: cpt-sandbox
TARGET_ENVIRONMENT: dev
APIGEE_ENVIRONMENT: internal-dev-sandbox
ENABLE_MUTUAL_TLS: true
DEPLOY_SANDBOX: true
BUILD_ARTIFACT: packaged_sandbox_code
TRUSTSTORE_FILE: clinical-tracker-sandbox-truststore.pem
VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
Expand All @@ -142,18 +141,18 @@ jobs:
LOG_RETENTION_DAYS: 30
secrets:
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_DEPLOY_ROLE }}
TARGET_SPINE_SERVER: sandbox
PROXYGEN_ROLE: ${{ secrets.PROXYGEN_PTL_ROLE }}
# TARGET_SPINE_SERVER: sandbox

release_qa:
needs: [tag_release, release_dev, release_dev_sandbox, package_code, get_commit_id]
uses: ./.github/workflows/sam_release_code.yml
uses: ./.github/workflows/run_release_code_and_api.yml
with:
ARTIFACT_BUCKET_PREFIX: ${{needs.tag_release.outputs.version_tag}}
STACK_NAME: cpt
TARGET_ENVIRONMENT: qa
APIGEE_ENVIRONMENT: internal-qa
ENABLE_MUTUAL_TLS: true
DEPLOY_SANDBOX: false
BUILD_ARTIFACT: packaged_code
TRUSTSTORE_FILE: clinical-tracker-truststore.pem
VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
Expand All @@ -162,4 +161,5 @@ jobs:
LOG_RETENTION_DAYS: 30
secrets:
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.QA_CLOUD_FORMATION_DEPLOY_ROLE }}
TARGET_SPINE_SERVER: ${{ secrets.QA_TARGET_SPINE_SERVER }}
PROXYGEN_ROLE: ${{ secrets.PROXYGEN_PTL_ROLE }}
# TARGET_SPINE_SERVER: ${{ secrets.QA_TARGET_SPINE_SERVER }}
Loading