Skip to content

Webhooks - #2336

Merged
SchrodingersGat merged 13 commits into
inventree:masterfrom
matmair:webhooks
Jan 11, 2022
Merged

SchrodingersGat merged 13 commits into
inventree:masterfrom
matmair:webhooks

Conversation

@matmair

@matmair matmair commented Nov 19, 2021 •

Copy link
Copy Markdown
Member

Fixes #2036
This is in preparation for discussion and merge after #2074 is done.

See #2049
This PR adds a Webhook receiver under the /api/webhook/<endpoint-id>/ URL. The view is designed to be inherited so each step is split into actionable functions. While there is the possibility for the (admin) user to create webhook-endpoints this is in preparation for integrating 3rd party software via plugins.

@matmair
matmair marked this pull request as draft November 19, 2021 21:42
@matmair matmair changed the title Pulls out the webhook dev for partial merge Webhooks Nov 19, 2021
@matmair
matmair marked this pull request as ready for review November 19, 2021 23:28
@SchrodingersGat

Copy link
Copy Markdown
Member

@matmair I guess now that the plugins architecture is merged, now we should look at this?

Looking through the code here, it appears that this is somewhat "separate" from the plugin architecture?

Unless I'm reading this wrong (and please correct me if so):

I would like to see the web-hook system be a sub-component of the plugin architecture - each "plugin" can accept custom web hooks to perform actions.

Can you run me through your thinking here? Does it line up with above?

@matmair

matmair commented Dec 21, 2021

Copy link
Copy Markdown
Member Author

@SchrodingersGat it is not depended on the plugin system but receiving webhooks without the plugin system dors not really make sense as the hook should trigger some custom code which should be in a plugin or something similar.
Plugins can be full apps so they can contain a model that inherits from the webhook base model. This mechanism ensures that the webhook will not be dead when the plugin is deactivated so that more strict senders do not kill your webhook-ability. Once the plugin is back up it can process through the missed messages at startup or through a task.
That is the whole reason to have it in common and not plugin.

@SchrodingersGat SchrodingersGat added this to the 0.6.0 milestone Dec 22, 2021
HMAC = 2


class WebhookEndpoint(models.Model):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the "WebhookEndpoint" have a foreignkey relation to "PluginConfig"? This way, when the plugin is uninstalled, so are the corresponding endpoints. Also, it would enable plugins to keep track of their own endpoints?

help_text=_('Is this webhook active')
)

user = models.ForeignKey(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the "user" the latest user to make use of the endpoint, or the only user who is allowed to use it

@SchrodingersGat

Copy link
Copy Markdown
Member

@matmair so if I understand correctly:

  • Webhook objects register a new webhook URL
  • Messages are received at that URL, and stored in the database
  • The background worker process extracts a message from the database, and passes it to the plugin to run?

@SchrodingersGat

Copy link
Copy Markdown
Member

@matmair I'm going to merge this now so we can have some time to play around with it before the 0.6.0 release

@SchrodingersGat
SchrodingersGat merged commit 19de9a0 into inventree:master Jan 11, 2022
@matmair
matmair deleted the webhooks branch January 11, 2022 07:57
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.

[3rd party integration] Webhook receiver

2 participants