Skip to content

Commit

Permalink
code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JackLewis-digirati committed Aug 10, 2023
1 parent 95d847e commit 687c690
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/actions/docker-build-and-push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions varnish-cleanup/Test/test_cleanup_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 0 additions & 16 deletions varnish-cleanup/app/aws_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion varnish-cleanup/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 3 additions & 5 deletions varnish-cleanup/cleanup_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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}"
Expand All @@ -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"]
Expand Down

0 comments on commit 687c690

Please sign in to comment.