Skip to content

Commit 4f165d0

Browse files
committed
feat: Add support for a regex parameter \n\n BREAKING CHANGE: Update repo_mapping variable to support the regex attribute
1 parent b101b29 commit 4f165d0

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/call_receiver/app.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import boto3
33
import requests
44
import os
5+
import re
56

67
secretsmanager = boto3.client('secretsmanager')
78
TOKEN_SECRET_NAME = os.environ['FLUX2_WEBHOOK_TOKEN_SECRET_NAME']
@@ -54,7 +55,8 @@ def make_requests(webhook_url, repository, headers):
5455
'repository': repository
5556
}))
5657

57-
def call_flux_webhook(repository):
58+
59+
def call_flux_webhook(repository, image_tag):
5860
# Retrieve the map of values from Secrets Manager
5961
webhook_map = get_webhook_map()
6062

@@ -63,13 +65,14 @@ def call_flux_webhook(repository):
6365
token = None
6466
if repository in webhook_map:
6567
repo_data = webhook_map[repository]
66-
webhook_urls = repo_data.get('webhook')
67-
token = repo_data.get('token', get_global_token())
68-
for webhook in webhook_urls:
69-
headers = {'Authorization': f'Bearer {token}'}
70-
make_requests(webhook, repository, headers)
71-
72-
68+
for key, data in repo_data.items():
69+
webhook_urls = data.get('webhook')
70+
token = data.get('token', get_global_token())
71+
regex = data.get('regex', '.*')
72+
for webhook in webhook_urls:
73+
headers = {'Authorization': f'Bearer {token}'}
74+
if regex and re.match(regex, image_tag):
75+
make_requests(webhook, repository, headers)
7376

7477

7578
def lambda_handler(event, context):
@@ -82,7 +85,7 @@ def lambda_handler(event, context):
8285
process_ecr_push_event(detail)
8386

8487
# Call the Flux webhook with the event repository
85-
call_flux_webhook(detail['repository-name'])
88+
call_flux_webhook(detail['repository-name'], detail['image-tag'])
8689

8790
return {
8891
'statusCode': 200,

0 commit comments

Comments
 (0)