diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78b4929..43d34f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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] @@ -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 diff --git a/docker/infrastructure.yml b/docker/infrastructure.yml index 81a9b03..ff88ba3 100644 --- a/docker/infrastructure.yml +++ b/docker/infrastructure.yml @@ -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 diff --git a/docker/scripts/install-packages.sh b/docker/scripts/install-packages.sh index b2aeab3..3cd50f6 100755 --- a/docker/scripts/install-packages.sh +++ b/docker/scripts/install-packages.sh @@ -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 && \ diff --git a/docker/scripts/register-api-gateway.sh b/docker/scripts/register-api-gateway.sh index 4f2414a..d8d6c33 100755 --- a/docker/scripts/register-api-gateway.sh +++ b/docker/scripts/register-api-gateway.sh @@ -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() { @@ -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() { @@ -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() { @@ -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() { @@ -165,10 +175,12 @@ 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() { @@ -176,13 +188,13 @@ put_method_response_for_http_200_status_code() { # 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 \ @@ -190,8 +202,12 @@ put_method_response_for_http_200_status_code() { --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() { @@ -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() { @@ -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() { @@ -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() { @@ -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 "$@" \ No newline at end of file