-
-
Notifications
You must be signed in to change notification settings - Fork 25
[ADD] base_web_hook: Create abstract web hooks #4
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
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
192adb4
[ADD] base_json_request: Module to allow standard JSON requests
lasley 2839174
[ADD] base_web_hook: Create abstract web hooks
lasley 071843b
Add token adapter/interface mechanism
lasley adcb447
Add headers to token verification
lasley c93ca2a
Add inherits on adapters
lasley 8fe5b08
Usability
lasley c2e781c
Send headers to hook receive
lasley 24004e3
Views and usability
lasley 87d90a3
Add full URI
lasley 616ade0
Add auth note in receive
lasley 854e366
Allow circumvention of automatic adapter creation on hook creation
lasley 9057d8f
Usability updates & add a request bin
lasley 162e618
Remove unused model and add user to request bin
lasley e310be4
Add an HTTP endpoint and an always true token
lasley 8255239
Bug fixes - it works!
lasley f203779
Add security and remove csrf from http route
lasley b23a071
Save request bin as raw strings
lasley 3ca31ab
Add an authentication-required HTTP endpoint
lasley 675e5c7
Oops
lasley 0ee415f
Add some sensible security
lasley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| .. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg | ||
| :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
| :alt: License: LGPL-3 | ||
|
|
||
| ================= | ||
| Base JSON Request | ||
| ================= | ||
|
|
||
| This module allows you to receive JSON requests in Odoo that are not | ||
| RPC. | ||
|
|
||
| .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
| :alt: Try me on Runbot | ||
| :target: https://runbot.odoo-community.org/runbot/210/10.0 | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues | ||
| <https://github.com/OCA/server-tools/issues>`_. In case of trouble, please | ||
| check there if your issue has already been reported. If you spotted it first, | ||
| help us smashing it by providing a detailed and welcomed feedback. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Images | ||
| ------ | ||
|
|
||
| * Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| * Dave Lasley <dave@laslabs.com> | ||
|
|
||
| Maintainer | ||
| ---------- | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use. | ||
|
|
||
| To contribute to this module, please visit https://odoo-community.org. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| from .hooks import post_load |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2017 LasLabs Inc. | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| { | ||
| 'name': 'Base JSON Request', | ||
| 'summary': 'Allows you to receive JSON requests that are not RPC.', | ||
| 'version': '10.0.1.0.0', | ||
| 'category': 'Authentication', | ||
| 'website': 'https://laslabs.com/', | ||
| 'author': 'LasLabs, Odoo Community Association (OCA)', | ||
| 'license': 'LGPL-3', | ||
| 'installable': True, | ||
| 'depends': [ | ||
| 'web', | ||
| ], | ||
| 'post_load': 'post_load', | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2017 LasLabs Inc. | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| from odoo import http | ||
|
|
||
| from .http import _handle_exception, __init__ | ||
|
|
||
|
|
||
| def post_load(): | ||
| """Monkey patch HTTP methods.""" | ||
| http.JsonRequest._handle_exception = _handle_exception | ||
| http.JsonRequest.__init__ = __init__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2017 LasLabs Inc. | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| import json | ||
|
|
||
| from werkzeug.exceptions import BadRequest | ||
|
|
||
| from odoo import http | ||
|
|
||
|
|
||
| old_handle_exception = http.JsonRequest._handle_exception | ||
| old_init = http.JsonRequest.__init__ | ||
|
|
||
|
|
||
| def __init__(self, *args): | ||
| try: | ||
| old_init(self, *args) | ||
| except BadRequest as e: | ||
| try: | ||
| args = self.httprequest.args | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AttributeError: 'JsonRequest' object has no attribute 'httprequest' |
||
| self.jsonrequest = args | ||
| self.params = json.loads(self.jsonrequest.get('params', "{}")) | ||
| self.context = self.params.pop('context', | ||
| dict(self.session.context)) | ||
| except ValueError: | ||
| raise e | ||
|
|
||
|
|
||
| def _handle_exception(self, exception): | ||
| """ Override the original method to handle Werkzeug exceptions. | ||
|
|
||
| Args: | ||
| exception (Exception): Exception object that is being thrown. | ||
|
|
||
| Returns: | ||
| BaseResponse: JSON Response. | ||
| """ | ||
|
|
||
| # For some reason a try/except here still raised... | ||
| code = getattr(exception, 'code', None) | ||
| if code is None: | ||
| return old_handle_exception( | ||
| self, exception, | ||
| ) | ||
|
|
||
| error = { | ||
| 'data': http.serialize_exception(exception), | ||
| 'code': code, | ||
| } | ||
|
|
||
| try: | ||
| error['message'] = exception.description | ||
| except AttributeError: | ||
| try: | ||
| error['message'] = exception.message | ||
| except AttributeError: | ||
| error['message'] = 'Internal Server Error' | ||
|
|
||
| return self._json_response(error=error) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| .. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg | ||
| :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
| :alt: License: LGPL-3 | ||
|
|
||
| ============= | ||
| Base Web Hook | ||
| ============= | ||
|
|
||
| This module provides an abstract core for receiving and processing web hooks. | ||
|
|
||
| .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
| :alt: Try me on Runbot | ||
| :target: https://runbot.odoo-community.org/runbot/210/10.0 | ||
|
|
||
| Known Issues | ||
| ============ | ||
|
|
||
| * Security is too lax; public can read too much. Maybe should also add a group for hooks.. | ||
| * Buffer length should be checked before ``httprequest.get_data`` calls | ||
|
|
||
| Bug Tracker | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a usage section on how to use this module |
||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues | ||
| <https://github.com/OCA/server-tools/issues>`_. In case of trouble, please | ||
| check there if your issue has already been reported. If you spotted it first, | ||
| help us smashing it by providing a detailed and welcomed feedback. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Images | ||
| ------ | ||
|
|
||
| * Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| * Dave Lasley <dave@laslabs.com> | ||
|
|
||
| Maintainer | ||
| ---------- | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use. | ||
|
|
||
| To contribute to this module, please visit https://odoo-community.org. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| from . import controllers | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2017 LasLabs Inc. | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| { | ||
| 'name': 'Base Web Hook', | ||
| 'summary': 'Provides an abstract system for defining and receiving web ' | ||
| 'hooks.', | ||
| 'version': '10.0.1.0.0', | ||
| 'category': 'Tools', | ||
| 'website': 'https://laslabs.com/', | ||
| 'author': 'LasLabs, Odoo Community Association (OCA)', | ||
| 'license': 'LGPL-3', | ||
| 'installable': True, | ||
| 'external_dependencies': { | ||
| 'python': ['slugify'], | ||
| }, | ||
| 'depends': [ | ||
| 'base_json_request', | ||
| ], | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/web_hook_view.xml', | ||
| ], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| from . import main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2017 LasLabs Inc. | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| import json | ||
|
|
||
| from odoo import http | ||
|
|
||
|
|
||
| class WebHookController(http.Controller): | ||
|
|
||
| @http.route( | ||
| ['/base_web_hook/json/<string:slug>.json'], | ||
| type='json', | ||
| auth='public', | ||
| ) | ||
| def json_receive(self, *args, **kwargs): | ||
| return self._receive(*args, **kwargs) | ||
|
|
||
| @http.route( | ||
| ['/base_web_hook/<string:slug>'], | ||
| type='http', | ||
| auth='public', | ||
| csrf=False, | ||
| ) | ||
| def http_receive(self, *args, **kwargs): | ||
| return json.dumps( | ||
| self._receive(*args, **kwargs), | ||
| ) | ||
|
|
||
| @http.route( | ||
| ['/base_web_hook/authenticated/<string:slug>'], | ||
| type='http', | ||
| auth='user', | ||
| csrf=False, | ||
| ) | ||
| def http_receive_authenticated(self, *args, **kwargs): | ||
| return self.http_receive(*args, **kwargs) | ||
|
|
||
| def _receive(self, slug, **kwargs): | ||
| hook = http.request.env['web.hook'].search_by_slug(slug) | ||
| return hook.receive( | ||
| data=kwargs, | ||
| data_string=http.request.httprequest.get_data(), | ||
| headers=http.request.httprequest.headers, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| # Concrete models | ||
| from . import web_hook | ||
| from . import web_hook_token | ||
|
|
||
| # Adapters | ||
| from . import web_hook_adapter | ||
| from . import web_hook_token_adapter | ||
|
|
||
| # Token Interfaces | ||
| from . import web_hook_token_none | ||
| from . import web_hook_token_plain | ||
| from . import web_hook_token_user | ||
|
|
||
| # Request Bin Hook | ||
| from . import web_hook_request_bin | ||
| from . import web_hook_request_bin_request |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a usage section on how to use this module