Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SonarQube cloud analysis exceptions
# shell:S5332 - Clear text protocols are acceptable for AWS local development.
# secrets:S2068 - Well known local development secrets are aceptable.
name: CI

on: [push, pull_request]
Expand Down Expand Up @@ -38,3 +41,10 @@ jobs:
-Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/**
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
-Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/public/**
-Dsonar.issue.ignore.multicriteria=e1,e2,e3
-Dsonar.issue.ignore.multicriteria.e1.ruleKey=shell:S5332
-Dsonar.issue.ignore.multicriteria.e1.resourceKey=**/docker/scripts/register-lambda-functions.sh
-Dsonar.issue.ignore.multicriteria.e2.ruleKey=shell:S5332
-Dsonar.issue.ignore.multicriteria.e2.resourceKey=**/docker/scripts/load-dummy-data.sh
-Dsonar.issue.ignore.multicriteria.e3.ruleKey=secrets:S2068
-Dsonar.issue.ignore.multicriteria.e3.resourceKey=**/docker/.env
2 changes: 1 addition & 1 deletion docker/infrastructure.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
localstack:
container_name: "localstack-main"
image: localstack/localstack:latest
image: localstack/localstack:4.14.0
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
Expand Down
2 changes: 1 addition & 1 deletion docker/scripts/install-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
# Remove /etc/apt/sources.list.d/backports.list to resolve apt duplication warnings
rm -f /etc/apt/sources.list.d/backports.list
# Install Nodesource package signing key and the Node.js repository.
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --yes --dearmor -o /usr/share/keyrings/nodesource.gpg
curl --proto "=https" --tlsv1.2 -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --yes --dearmor -o /usr/share/keyrings/nodesource.gpg
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODEJS_VERSION}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list > /dev/null
# Install packages
apt update -y && \
Expand Down
49 changes: 35 additions & 14 deletions docker/scripts/register-api-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,24 @@ main() {
--stage-name local

echo "Created API Gateway deployment"
return 0
}

get_http_method() {
if [ $1 = "processMessage" ]; then
lambda_function_name=$1
if [ $lambda_function_name = "processMessage" ]; then
echo POST
else
echo GET
fi
return 0
}

register_api_gateway_support_for_get_message() {
get_message_resource_id=$(create_resource $cap_xml_rest_api_root_resource_id "message")
message_resource_id=$(create_resource $get_message_resource_id "{id}")
put_method_and_integration $message_resource_id
return 0
}

register_api_gateway_support_for_get_message_v2() {
Expand All @@ -71,6 +75,7 @@ register_api_gateway_support_for_get_message_v2() {
register_api_gateway_support_for_get_messages_atom() {
get_messages_atom_resource_id=$(create_resource $cap_xml_rest_api_root_resource_id "messages.atom")
put_method_and_integration $get_messages_atom_resource_id
return 0
}

register_api_gateway_support_for_get_messages_atom_v2() {
Expand All @@ -85,13 +90,17 @@ register_api_gateway_support_for_get_messages_atom_v2() {
register_api_gateway_support_for_process_message() {
process_message_resource_id=$(create_resource $cap_xml_rest_api_root_resource_id "message")
put_method_and_integration $process_message_resource_id
return 0
}

create_resource() {
cap_xml_rest_api_root_resource_id=$1
cap_xml_rest_api_path_part=$2
echo $(awslocal apigateway create-resource \
--rest-api-id $cap_xml_rest_api_id \
--parent-id $1 \
--path-part $2 | jq -r '.id')
--parent-id $cap_xml_rest_api_root_resource_id \
--path-part $cap_xml_rest_api_path_part | jq -r '.id')
return 0
}

put_method_and_integration() {
Expand All @@ -105,13 +114,14 @@ put_method_and_integration() {
$(get_request_parameters $lambda_function_name)

put_integration
return 0
}

get_request_parameters() {
if [ $lambda_function_name = "getMessage" ]; then
echo --request-parameters "method.request.path.id=true"
fi
return
return 0
}

put_integration() {
Expand Down Expand Up @@ -165,33 +175,39 @@ put_integration() {

put_responses_for_process_message
;;

*)
echo "Unable to configure integration for unexpected function $lambda_function_name"
;;
esac

return
return 0
}

put_method_response_for_http_200_status_code() {
# Due to unresolved shell expansion issues integration response models need to be hardcoded rather than being returned
# by a function. This results in some duplication.
case $lambda_function_name in
getMessage|getMessagesAtom)
awslocal apigateway put-method-response \
--rest-api-id $cap_xml_rest_api_id \
--resource-id $resource_id \
--http-method $http_method \
--status-code 200 \
--response-models '{"application/xml": "Empty"}'
;;
awslocal apigateway put-method-response \
--rest-api-id $cap_xml_rest_api_id \
--resource-id $resource_id \
--http-method $http_method \
--status-code 200 \
--response-models '{"application/xml": "Empty"}'
;;
processMessage)
awslocal apigateway put-method-response \
--rest-api-id $cap_xml_rest_api_id \
--resource-id $resource_id \
--http-method $http_method \
--status-code 200 \
--response-models '{"application/json": "Empty"}'
;;
;;
*)
echo "Unable to configure method response for unexpected function $lambda_function_name"
;;
esac
return 0
}

put_responses_for_get_message() {
Expand All @@ -211,11 +227,13 @@ put_responses_for_get_message() {
--response-templates '{"application/json": "{\"errorMessage\": $input.json(\"$.errorMessage\")}"}'

put_integration_response_for_http_500
return 0
}

put_responses_for_get_messages_atom() {
put_responses_for_http_200_get
put_integration_response_for_http_500
return 0
}

put_responses_for_process_message() {
Expand All @@ -227,6 +245,7 @@ put_responses_for_process_message() {

put_method_response_for_http_200_status_code
put_integration_response_for_http_500
return 0
}

put_responses_for_http_200_get() {
Expand All @@ -240,6 +259,7 @@ put_responses_for_http_200_get() {
--status-code 200 \
--response-parameters '{"method.response.header.content-type": "integration.response.body.headers.content-type"}' \
--response-templates '{"application/xml" : "#set($inputRoot = $input.path(\"$\"))\n$inputRoot.body"}'
return 0
}

put_integration_response_for_http_500() {
Expand All @@ -252,6 +272,7 @@ put_integration_response_for_http_500() {
--response-parameters '{"method.response.header.content-type": "integration.response.body.headers.content-type"}' \
--response-templates '{"application/json": "{\"errorMessage\": $input.json(\"$.errorMessage\")}"}' \
--selection-pattern '(\n|.)+'
return 0
}

main "$@"
Loading