From 687c690850d57446b5747c3f02cfbb1bf1d36144 Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Thu, 10 Aug 2023 16:00:36 +0100 Subject: [PATCH] code review changes --- .github/actions/docker-build-and-push/action.yml | 6 +++--- README.md | 1 + varnish-cleanup/Test/test_cleanup_handler.py | 4 ++-- varnish-cleanup/app/aws_factory.py | 16 ---------------- varnish-cleanup/app/settings.py | 1 - varnish-cleanup/cleanup_handler.py | 8 +++----- 6 files changed, 9 insertions(+), 27 deletions(-) diff --git a/.github/actions/docker-build-and-push/action.yml b/.github/actions/docker-build-and-push/action.yml index d80e72f..2e94251 100644 --- a/.github/actions/docker-build-and-push/action.yml +++ b/.github/actions/docker-build-and-push/action.yml @@ -26,7 +26,7 @@ runs: driver-opts: | image=moby/buildkit:v0.10.6 - id: docker-meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v4 with: images: ghcr.io/dlcs/${{ inputs.image-name }} tags: | @@ -37,13 +37,13 @@ runs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} - id: docker-login - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ inputs.github-token }} - id: docker-build-push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: ${{ inputs.context }} file: ${{ inputs.dockerfile }} diff --git a/README.md b/README.md index 812ae28..7dfcae4 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ The following environment settings are expected: * `VARNISH_CACHE_FOLDER` - Folder where disk backed cache is stored. * `VARNISH_CACHE_SIZE` - Size of cache. * `AWS_PROFILE` - Required to run locally +* `INCOMING_QUEUE` - the name of the queue that the cleanup handler listens to The following configuration is optional: diff --git a/varnish-cleanup/Test/test_cleanup_handler.py b/varnish-cleanup/Test/test_cleanup_handler.py index e221586..99db25c 100644 --- a/varnish-cleanup/Test/test_cleanup_handler.py +++ b/varnish-cleanup/Test/test_cleanup_handler.py @@ -48,7 +48,7 @@ def test_receive_message_bans(): sqs_mock_message.body = data with requests_mock.Mocker() as mo: - mo.request("BAN", url="http://localhost:65345/26/18/54378677") + mo.request("BAN", url="http://localhost/26/18/54378677") # Act response = cleanup_handler._handle_message(sqs_mock_message) @@ -66,7 +66,7 @@ def test_receive_message_bans_fail(): sqs_mock_message.body = data with requests_mock.Mocker() as mo: - mo.request("BAN", url="http://localhost:65345/26/18/54378677", status_code=400) + mo.request("BAN", url="http://localhost/26/18/54378677", status_code=400) # Act response = cleanup_handler._handle_message(sqs_mock_message) diff --git a/varnish-cleanup/app/aws_factory.py b/varnish-cleanup/app/aws_factory.py index 10ff5b4..f8564ed 100644 --- a/varnish-cleanup/app/aws_factory.py +++ b/varnish-cleanup/app/aws_factory.py @@ -4,22 +4,6 @@ from app.settings import LOCALSTACK, REGION, LOCALSTACK_ADDRESS from logzero import logger - -def get_aws_client(client_type: str): - """Get an aws client configured to use LocalStack if env var is set""" - if LOCALSTACK: - logger.warn(f"Using localstack for {client_type} client") - return boto3.client( - client_type, - region_name=REGION, - endpoint_url=LOCALSTACK_ADDRESS, - aws_access_key_id="foo", - aws_secret_access_key="bar", - ) - else: - return boto3.client(client_type, REGION) - - def get_aws_resource(resource_type: str): """Get an aws resource configured to use LocalStack if env var is set""" if LOCALSTACK: diff --git a/varnish-cleanup/app/settings.py b/varnish-cleanup/app/settings.py index 99dbcd4..034dba7 100644 --- a/varnish-cleanup/app/settings.py +++ b/varnish-cleanup/app/settings.py @@ -8,7 +8,6 @@ def _get_boolean(env_name: str, fallback: str) -> bool: # AWS REGION = os.environ.get("AWS_REGION", "eu-west-1") INCOMING_QUEUE = os.environ.get("INCOMING_QUEUE") -COMPLETED_TOPIC_ARN = os.environ.get("COMPLETED_TOPIC_ARN") # LocalStack LOCALSTACK = _get_boolean("LOCALSTACK", "False") diff --git a/varnish-cleanup/cleanup_handler.py b/varnish-cleanup/cleanup_handler.py index d95ce2a..2c3b617 100644 --- a/varnish-cleanup/cleanup_handler.py +++ b/varnish-cleanup/cleanup_handler.py @@ -5,7 +5,7 @@ from logzero import logger from app.aws_factory import get_aws_resource -from app.settings import INCOMING_QUEUE, MONITOR_SLEEP_SECS, COMPLETED_TOPIC_ARN, VARNISH_ADDRESS +from app.settings import INCOMING_QUEUE, MONITOR_SLEEP_SECS, VARNISH_ADDRESS from app.signal_handler import SignalHandler @@ -51,9 +51,7 @@ def _get_messages_from_queue(queue): def _handle_message(received_message): logger.debug(received_message) message = json.loads(received_message.body) - delivery_channels = message["asset"]["deliveryChannels"] - - id = _convert_asset_id(message["asset"]["id"], message["customerPathElement"]["name"]) + id = _convert_asset_id(message["asset"]["id"]) success = True varnishUrl = f"{VARNISH_ADDRESS}/{id}" @@ -72,7 +70,7 @@ def _handle_message(received_message): return success -def _convert_asset_id(id, name): +def _convert_asset_id(id): customer = id["customer"] space = id["space"] asset = id["asset"]