Skip to content

Commit 1054bb3

Browse files
feat: Add support for multiple webhooks (#6)
* feat: Add support for multiple webhooks \n\n BREAKING CHANGE: Change data structure of repo_mapping attribute * ci: Update trigger branch * chore(release): v1.1.0-beta.1 * docs: Add support for multiple webhooks * chore(release): v1.1.0-beta.2 --------- Co-authored-by: semantic-release-bot <[email protected]>
1 parent f96cd07 commit 1054bb3

File tree

6 files changed

+43
-19
lines changed

6 files changed

+43
-19
lines changed

.github/workflows/semver.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches:
66
- main
7+
- beta
8+
- alpha
79

810
jobs:
911
release:

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# [1.1.0-beta.2](https://github.com/fabidick22/flux2-ecr-webhook/compare/v1.1.0-beta.1...v1.1.0-beta.2) (2023-07-03)
2+
3+
### Documentation
4+
5+
- Add support for multiple webhooks ([c922986](https://github.com/fabidick22/flux2-ecr-webhook/commit/c9229863292034106c43915a4592c2b1f534d8b2))
6+
7+
# [1.1.0-beta.1](https://github.com/fabidick22/flux2-ecr-webhook/compare/v1.0.2...v1.1.0-beta.1) (2023-06-07)
8+
9+
### Continuous Integration
10+
11+
- Fix string format (#5) ([f96cd07](https://github.com/fabidick22/flux2-ecr-webhook/commit/f96cd07cd6105b4bf53cfaaebed9854a28489a50)), closes [#5](https://github.com/fabidick22/flux2-ecr-webhook/issues/5)
12+
- Refactor semver workflow (#4) ([37134da](https://github.com/fabidick22/flux2-ecr-webhook/commit/37134daa58edc20c5db6749be79674aac4fa3018)), closes [#4](https://github.com/fabidick22/flux2-ecr-webhook/issues/4)
13+
- Update trigger branch ([6dc64a6](https://github.com/fabidick22/flux2-ecr-webhook/commit/6dc64a66f54b1de44c6e3068246df02324818664))
14+
15+
### Features
16+
17+
- Add support for multiple webhooks \n\n BREAKING CHANGE: Change data structure of repo_mapping attribute ([e28764a](https://github.com/fabidick22/flux2-ecr-webhook/commit/e28764af57c6514347688e44081900ad60aa9723))
18+
119
## [1.0.2](https://github.com/fabidick22/flux2-ecr-webhook/compare/v1.0.1...v1.0.2) (2023-05-10)
220

321
### Documentation

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module "flux2-ecr-webhook" {
5050
...
5151
repo_mapping = {
5252
my-ecr-repo = {
53-
webhook = "https://custom.domain.com/hook/11111111"
53+
webhook = ["https://custom.domain.com/hook/11111111", "https://custom.domain.com/hook/2222222"]
5454
}
5555
}
5656
...
@@ -102,7 +102,7 @@ module "flux2-ecr-webhook" {
102102
|------|-------------|------|---------|:--------:|
103103
| <a name="input_app_name"></a> [app\_name](#input\_app\_name) | Name used for resources to create. | `string` | `"flux2-ecr-webhook"` | no |
104104
| <a name="input_cw_logs_retention"></a> [cw\_logs\_retention](#input\_cw\_logs\_retention) | Specifies the number of days you want to retain log events in the specified log group. | `number` | `14` | no |
105-
| <a name="input_repo_mapping"></a> [repo\_mapping](#input\_repo\_mapping) | Object with repository mapping, if this variable is set `repo_mapping_file` will be ignored.<br>**Example:**<pre>{<br> ecr-repo-name = {<br> webhook = "https://gitops.domain.com/hook/111111 "<br> }<br> test/ecr-repo-name = {<br> webhook = "https://gitops.domain.com/hook/111111 "<br> token = "webhook-token "<br> }<br>}</pre> | `any` | `null` | no |
105+
| <a name="input_repo_mapping"></a> [repo\_mapping](#input\_repo\_mapping) | Object with repository mapping, if this variable is set `repo_mapping_file` will be ignored.<br>**Example:**<pre>{<br> ecr-repo-name = {<br> webhook = ["https://gitops.domain.com/hook/111111" ]<br> }<br> test/ecr-repo-name = {<br> webhook = ["https://gitops.domain.com/hook/111111", "https://gitops.domain.com/hook/222222" ]<br> token = "webhook-token "<br> }<br>}</pre> | `any` | `null` | no |
106106
| <a name="input_repo_mapping_file"></a> [repo\_mapping\_file](#input\_repo\_mapping\_file) | YAML file path with repository mapping. | `string` | `""` | no |
107107
| <a name="input_webhook_token"></a> [webhook\_token](#input\_webhook\_token) | Webhook default token used to call the Flux receiver. If it doesn't find a `token` attribute in the repository mapping use this token for the webhooks | `string` | `null` | no |
108108

docs/tf-docs/header.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ graph LR
1818
- Add unit tests
1919
- Add support for [generic-hmac](https://fluxcd.io/flux/components/notification/receiver/#generic-hmac)
2020
- Add support to lambda with VPC (for internal webhook)
21-
- Add support to multiple webhooks
2221

2322
## Usage
2423
To use this Terraform module, you must first have created webhooks for each [ImageRepository](https://fluxcd.io/flux/components/image/imagerepositories/) resource in your cluster.
@@ -50,7 +49,7 @@ module "flux2-ecr-webhook" {
5049
...
5150
repo_mapping = {
5251
my-ecr-repo = {
53-
webhook = "https://custom.domain.com/hook/11111111"
52+
webhook = ["https://custom.domain.com/hook/11111111", "https://custom.domain.com/hook/2222222"]
5453
}
5554
}
5655
...

src/call_receiver/app.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,9 @@ def process_ecr_push_event(detail):
4040
}))
4141

4242

43-
def call_flux_webhook(repository):
44-
# Retrieve the map of values from Secrets Manager
45-
webhook_map = get_webhook_map()
46-
47-
# Find the webhook endpoint corresponding to the event repository
48-
webhook_url = None
49-
token = None
50-
if repository in webhook_map:
51-
repo_data = webhook_map[repository]
52-
webhook_url = repo_data.get('webhook')
53-
token = repo_data.get('token', get_global_token())
54-
43+
def make_requests(webhook_url, repository, headers):
5544
# Call the Flux webhook with the token and corresponding endpoint
5645
if webhook_url:
57-
headers = {'Authorization': f'Bearer {token}'}
5846
response = session.post(webhook_url, headers=headers)
5947
print(json.dumps({
6048
'message': 'Webhook response',
@@ -66,6 +54,23 @@ def call_flux_webhook(repository):
6654
'repository': repository
6755
}))
6856

57+
def call_flux_webhook(repository):
58+
# Retrieve the map of values from Secrets Manager
59+
webhook_map = get_webhook_map()
60+
61+
# Find the webhook endpoint corresponding to the event repository
62+
webhook_url = None
63+
token = None
64+
if repository in webhook_map:
65+
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+
73+
6974

7075
def lambda_handler(event, context):
7176
# Extract event information

variables.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Object with repository mapping, if this variable is set `repo_mapping_file` will
2222
```
2323
{
2424
ecr-repo-name = {
25-
webhook = "https://gitops.domain.com/hook/111111 "
25+
webhook = ["https://gitops.domain.com/hook/111111" ]
2626
}
2727
test/ecr-repo-name = {
28-
webhook = "https://gitops.domain.com/hook/111111 "
28+
webhook = ["https://gitops.domain.com/hook/111111", "https://gitops.domain.com/hook/222222" ]
2929
token = "webhook-token "
3030
}
3131
}

0 commit comments

Comments
 (0)