Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: activations with webhooks #595

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Jan 10, 2024

https://issues.redhat.com/browse/AAP-20844
Allow WebHooks to be added in the eda server that can be shared with different activations.

Support for HMAC and token authentication.

https://docs.google.com/document/d/1YJ5yQPKXNO7_Nqa_QEJ_NwXS-u6ZE-rLBx6tnM10Wxo/edit

@mkanoor mkanoor requested a review from a team as a code owner January 10, 2024 18:14
@@ -0,0 +1,29 @@
# Copyright 2023 Red Hat, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024, instead? Other new files, also.

Comment on lines 98 to 100
extra_var_obj = models.ExtraVar.objects.get(
pk=response.extra_var_id
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This get() of the extra var looks to be redundant based on lines 87-91 which has already retrieved it when response.extra_var_id is set.

@mkanoor mkanoor force-pushed the webhook_server branch 2 times, most recently from 4994620 to 5d5771e Compare January 11, 2024 03:02
@hsong-rh
Copy link
Contributor

@mkanoor what's the rbac settings for webhooks? do you need to pre-seed them into DB? I missed it when adding the source model.

Copy link
Contributor

@Alex-Izquierdo Alex-Izquierdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrations are not sync.

@mkanoor
Copy link
Contributor Author

mkanoor commented Jan 11, 2024

Migrations are not sync.

Updated

@mkanoor mkanoor force-pushed the webhook_server branch 2 times, most recently from 1b90b9d to 4c255fb Compare February 18, 2024 16:33
pyproject.toml Outdated
@@ -49,6 +49,8 @@ django-ansible-base = { git = "https://github.com/ansible/django-ansible-base.gi
jinja2 = ">=3.1.3,<3.2"
django-split-settings = "^1.2.0"
pexpect = "^4.9.0"
psycopg = "*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be replaced the old psycopg? Have you check if there are overlaps or conflicts?
https://github.com/ansible/eda-server/blob/main/pyproject.toml#L35

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous version is called psycopg2? pyscopg is the psycopg3, there was a memory leak that was fixed in pyscopg related to PG Notify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkanoor What I'm saying is that we should remove psycopg2 and only use psycopg.

if activation.webhooks:
extra_var = {}
if activation.extra_var_id:
extra_var_obj = models.ExtraVar.objects.get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal since right now the extra_vars are not deleted explicitly but this would raise an exception if the id if doesn't exist, don't? It might be less prone error to use filter or a try/except block.

Comment on lines 126 to 127
logger.error(f"Headers {request.headers}")
logger.error(f"Body {request.body}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a mistake? Why print it always as error? should it be debug?

secret = EncryptedTextField(
null=False, help_text="The secret for the webhook"
)
auth_type = models.TextField(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not an enum?

@action(detail=True, methods=["POST"], rbac_action=None)
def post(self, request, *args, **kwargs):
try:
self.webhook = Webhook.objects.get(uuid=kwargs["pk"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a parameter? I think it is more usual take the UUID from the uri. Also it would make easier for admins to apply custom logic for specific endpoints in load-balancers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alex-Izquierdo I am not sure if the admins would be routing based on each individual webhook, the routing would happen at a higher level from the NGINX configuration which will come from the UI NGINX in this PR https://github.com/ansible/ansible-ui/pull/1738/files

command:
- /bin/bash
- -c
- aap-eda-manage runserver 0.0.0.0:8000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stage should use gunicorn.

@@ -165,5 +171,26 @@ services:
retries: 3
start_period: 5s

eda-webhook-api:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without modify the nginx conf (aside of the url_prefix options) , this new service would be just a resource consumer. Anyway, if you want to add it, docker-compose-dev should have it too.

Comment on lines +514 to +640
SERVER_UUID = settings.get("SERVER_UUID", "abc-def-123-34567")
WEBHOOK_URL_PREFIX = settings.get(
"WEBHOOK_URL_PREFIX",
f"https://ui.eda.local:8443/{SERVER_UUID}/api/eda/v1/external_webhook",
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be these UUID empty by default, specially after the discussion when we agreed on implement it later

Comment on lines 27 to 33
- EDA_WEBHOOK_URL_PREFIX=${EDA_WEBHOOK_URL_PREFIX:-https://my_nginix_server/edgecafe-beef-feed-fade-decadeedgecafe/api/eda/v1/external_webhook}
- EDA_WEBHOOK_HOST=${EDA_WEBHOOK_HOST:-eda-webhook-api:8000}
- EDA_WEBHOOK_SERVER=http://${EDA_WEBHOOK_HOST:-eda-webhook-api:8000}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the docker-compose should work out the box. (Docker-compose-dev not even is updated) Without override the nginx conf this wouldn't work. Probably is better to not enable the url prefix by default (related with my previous comment)

pyproject.toml Outdated
@@ -49,6 +49,8 @@ django-ansible-base = { git = "https://github.com/ansible/django-ansible-base.gi
jinja2 = ">=3.1.3,<3.2"
django-split-settings = "^1.2.0"
pexpect = "^4.9.0"
psycopg = "*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkanoor What I'm saying is that we should remove psycopg2 and only use psycopg.

pyproject.toml Outdated
@@ -49,6 +49,8 @@ django-ansible-base = { git = "https://github.com/ansible/django-ansible-base.gi
jinja2 = ">=3.1.3,<3.2"
django-split-settings = "^1.2.0"
pexpect = "^4.9.0"
psycopg = "*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you set it as psycopg = "^3.1.17" ? that aligns with downstream constraints.

@mkanoor mkanoor force-pushed the webhook_server branch 8 times, most recently from 6c66371 to 1695c02 Compare April 26, 2024 21:51
@mkanoor mkanoor force-pushed the webhook_server branch 2 times, most recently from e09f82c to 2d89172 Compare May 2, 2024 21:16
@mkanoor mkanoor force-pushed the webhook_server branch 6 times, most recently from 9e69bf1 to e199afd Compare May 6, 2024 20:56
@mkanoor mkanoor force-pushed the webhook_server branch 3 times, most recently from 4102c9f to 57906fe Compare May 15, 2024 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants