Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1aa1a42
[ADD] webservice_core: split core out of webservice
simahawk Aug 27, 2026
75628a8
webservice: bump 19.0.2.0.0
simahawk Sep 22, 2026
4f4f001
[UPD] Update webservice_core.pot
Sep 23, 2026
795dc18
[BOT] post-merge updates
OCA-git-bot Sep 23, 2026
bad9901
[FIX] webservice: always return the full response, drop content_only
simahawk Sep 22, 2026
3031edf
[BOT] post-merge updates
OCA-git-bot Sep 23, 2026
864aa94
[IMP] webservice: configurable OAuth2 token request
ivantodorovich Jul 2, 2026
791ed72
[IMP] webservice_server_env: expose new OAuth2 options to server env
ivantodorovich Jul 2, 2026
70b3c40
Added translation using Weblate (Italian)
mymage Sep 25, 2026
5c5277b
[BOT] post-merge updates
OCA-git-bot Sep 28, 2026
463d7e3
Translated using Weblate (Italian)
mymage Oct 7, 2026
788b19f
[IMP] webservice_core: add configurable endpoints
simahawk Sep 24, 2026
530bcd3
[IMP] webservice_core: add configurable timeout
simahawk Oct 6, 2026
4ae9abe
[UPD] Update webservice_core.pot
Oct 20, 2026
8748336
[BOT] post-merge updates
OCA-git-bot Oct 20, 2026
36651b0
Update translation files
weblate Oct 20, 2026
b0cebee
[IMP] webservice_core: add copiable full url
simahawk Sep 22, 2026
9a29c3f
Translated using Weblate (Italian)
mymage Oct 27, 2026
94c6245
[UPD] Update webservice_core.pot
Oct 29, 2026
434b2ab
[BOT] post-merge updates
OCA-git-bot Oct 29, 2026
1482f9d
Update translation files
weblate Oct 29, 2026
1bbd2d0
Translated using Weblate (Italian)
mymage Oct 30, 2026
6994079
[IMP] webservice_core: add endpoints tab on backend form
simahawk Oct 29, 2026
184191e
[IMP] webservice_core: add archived ribbon on endpoint form
simahawk Nov 2, 2026
1b31fa5
[UPD] Update webservice_core.pot
Nov 2, 2026
fe360b7
[BOT] post-merge updates
OCA-git-bot Nov 2, 2026
32968b6
Update translation files
weblate Nov 2, 2026
d071516
Translated using Weblate (Italian)
mymage Nov 4, 2026
8c0617d
[IMP] webservice_core: add neutralize script
simahawk Oct 21, 2026
e50bec9
[FIX] webservice_core: test neutralize script on raw columns
simahawk Nov 3, 2026
b8f4f7c
[IMP] webservice_core: secret querystring params
simahawk Nov 5, 2026
9409da4
[IMP] webservice_core: secret headers
simahawk Nov 5, 2026
f8d5a2d
[IMP] webservice_core: do not log secret values
simahawk Nov 5, 2026
2efafd5
[UPD] Update webservice_core.pot
Nov 6, 2026
c8d17c8
[BOT] post-merge updates
OCA-git-bot Nov 6, 2026
0a35c5d
Update translation files
weblate Nov 6, 2026
d23954c
Translated using Weblate (Italian)
mymage Nov 6, 2026
558cdbd
Translated using Weblate (Italian)
mymage Nov 8, 2026
8e1e1a6
[IMP] webservice_core: pre-commit auto fixes
MiquelRForgeFlow Sep 30, 2026
e94a710
[MIG] webservice_core: Migration to 19.0
MiquelRForgeFlow Sep 30, 2026
d55d4a1
[IMP] webservice_core: neutralize base credentials
MiquelRForgeFlow Sep 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
PyYAML
jsonschema
oauthlib
openupgradelib
requests
requests-oauthlib
responses
29 changes: 25 additions & 4 deletions webservice/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ WebService
This module creates WebService frameworks to be used globally.

The module introduces support for HTTP Request protocol. The webservice
HTTP call returns by default the content of the response. A context
'content_only' can be passed to get the full response object.
HTTP call returns the full ``requests.Response`` object.

It builds on top of ``webservice_core`` (which provides the
``webservice.backend`` model with public/username-password/API key
authentication) to add OAuth2 authentication and ``server_environment``
support.

**Table of contents**

Expand All @@ -46,6 +50,20 @@ HTTP call returns by default the content of the response. A context
Configuration
=============

Upgrade from versions prior to 19.0.2.0.1
-----------------------------------------

On upgrade from a version prior to ``19.0.2.0.1``, a
``webservice.request_content_only`` system parameter is created
automatically (see that version's migration script) to preserve the
previous default behavior of HTTP calls, which returned only the
response content instead of the full ``requests.Response`` object.

If your code relies on that implicit default, keep the parameter for
now. Once it's adapted to use the full response object (see *Usage*),
delete the parameter under *Settings > Technical > System Parameters* -
new installs never get it set.

OAuth2 (Client Credentials)
---------------------------

Expand Down Expand Up @@ -129,10 +147,13 @@ promote its widespread use.
.. |maintainer-etobella| image:: https://github.com/etobella.png?size=40px
:target: https://github.com/etobella
:alt: etobella
.. |maintainer-simahawk| image:: https://github.com/simahawk.png?size=40px
:target: https://github.com/simahawk
:alt: simahawk

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-etobella|
|maintainer-etobella| |maintainer-simahawk|

This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/19.0/webservice>`_ project on GitHub.

Expand Down
8 changes: 3 additions & 5 deletions webservice/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
{
"name": "WebService",
"summary": """Defines webservice abstract definition to be used generally""",
"version": "19.0.1.4.0",
"version": "19.0.2.0.1",
"license": "AGPL-3",
"development_status": "Production/Stable",
"maintainers": ["etobella"],
"maintainers": ["etobella", "simahawk"],
"author": "Creu Blanca, Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web-api",
"depends": ["component"],
"depends": ["webservice_core", "component"],
"external_dependencies": {"python": ["requests-oauthlib", "oauthlib", "responses"]},
"data": [
"security/ir.model.access.csv",
"security/ir_rule.xml",
"views/webservice_backend.xml",
],
"demo": [],
Expand Down
11 changes: 5 additions & 6 deletions webservice/components/request_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from requests_oauthlib import OAuth2Session

from odoo.addons.component.core import Component

from ..utils import StaticHeaderAuth, sanitize_url_for_log
from odoo.addons.webservice_core.utils import StaticHeaderAuth, sanitize_url_for_log

_logger = logging.getLogger(__name__)

Expand All @@ -26,7 +25,7 @@ class BaseRestRequestsAdapter(Component):
# TODO: url and url_params could come from work_ctx
def _request(self, method, url=None, url_params=None, **kwargs):
url = self._get_url(url=url, url_params=url_params)
content_only = kwargs.pop("content_only", True)
self.collection._pop_deprecated_content_only_kwarg(kwargs)
# TODO: turn on/off debug from webservice setting?
url_to_log = self._sanitize_url_for_log(url)
_logger.info("%s call to %s", method, url_to_log)
Expand All @@ -41,7 +40,7 @@ def _request(self, method, url=None, url_params=None, **kwargs):
# pylint: disable=E8106
request = requests.request(method, url, **new_kwargs)
request.raise_for_status()
if content_only:
if self.collection._get_request_content_only():
return request.content
return request

Expand Down Expand Up @@ -206,7 +205,7 @@ def _token_fetch_kwargs(self, oauth_params):

def _request(self, method, url=None, url_params=None, **kwargs):
url = self._get_url(url=url, url_params=url_params)
content_only = kwargs.pop("content_only", True)
self.collection._pop_deprecated_content_only_kwarg(kwargs)
new_kwargs = kwargs.copy()
new_kwargs.update(
{
Expand All @@ -219,7 +218,7 @@ def _request(self, method, url=None, url_params=None, **kwargs):
# pylint: disable=E8106
request = session.request(method, url, **new_kwargs)
request.raise_for_status()
if content_only:
if self.collection._get_request_content_only():
return request.content
return request

Expand Down
8 changes: 3 additions & 5 deletions webservice/data/neutralize.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
-- remove webservice backend credentials
-- remove webservice backend OAuth2 credentials
-- (base credentials are cleared by webservice_core/data/neutralize.sql)
UPDATE webservice_backend
SET username = NULL,
password = NULL,
api_key = NULL,
oauth2_clientid = NULL,
SET oauth2_clientid = NULL,
oauth2_client_secret = NULL,
oauth2_client_auth_value = NULL,
oauth2_token = NULL;
157 changes: 84 additions & 73 deletions webservice/models/webservice_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,26 @@

_logger = logging.getLogger(__name__)

# Backward-compat switch for the `content_only` default removal on `_request`.
# Existing databases get it set (see `webservice`'s `19.0.2.0.1` upgrade
# script) to keep returning only the response content; new installs get the
# full `requests.Response` object with no param set. Safe to delete once
# calling code has been adapted; the code checking it can then be dropped
# too.
CONTENT_ONLY_COMPAT_PARAM = "webservice.request_content_only"


class WebserviceBackend(models.Model):
_name = "webservice.backend"
_inherit = ["collection.base"]
_description = "WebService Backend"
_inherit = [
"webservice.backend",
"collection.base",
]

name = fields.Char(required=True)
tech_name = fields.Char(required=True)
protocol = fields.Selection([("http", "HTTP Request")], required=True)
url = fields.Char(required=True)
auth_type = fields.Selection(
selection=[
("none", "Public"),
("user_pwd", "Username & password"),
("api_key", "API Key"),
("oauth2", "OAuth2"),
],
required=True,
selection_add=[("oauth2", "OAuth2")],
ondelete={"oauth2": "cascade"},
)
username = fields.Char(auth_type="user_pwd")
password = fields.Char(auth_type="user_pwd")
api_key = fields.Char(string="API Key", auth_type="api_key")
api_key_header = fields.Char(string="API Key header", auth_type="api_key")
oauth2_flow = fields.Selection(
[
("backend_application", "Backend Application (Client Credentials Grant)"),
Expand Down Expand Up @@ -86,30 +83,22 @@ class WebserviceBackend(models.Model):
help="random key generated when authorization flow starts "
"to ensure that no CSRF attack happen"
)
content_type = fields.Selection(
[
("application/json", "JSON"),
("application/xml", "XML"),
("application/x-www-form-urlencoded", "Form"),
],
)
company_id = fields.Many2one("res.company", string="Company")

@api.constrains("auth_type")
def _check_auth_type(self):
valid_fields = {
k: v for k, v in self._fields.items() if hasattr(v, "auth_type")
}
for rec in self:
if rec.auth_type == "none":
continue
_fields = [v for v in valid_fields.values() if v.auth_type == rec.auth_type]
missing = []
for _field in _fields:
if not rec[_field.name]:
missing.append(_field)
if missing:
raise exceptions.UserError(rec._msg_missing_auth_param(missing))
@api.onchange("auth_type")
def _onchange_auth_type(self):
# Keep `oauth2_flow` in sync in the UI as the user edits `auth_type`,
# regardless of whether `server_environment` is installed (see
# `create`/`write` below for the same guarantee on any other write).
if self.auth_type != "oauth2":
self.oauth2_flow = False

@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
records.filtered(
lambda r: r.auth_type != "oauth2" and r.oauth2_flow
).oauth2_flow = False
return records

@api.constrains(
"auth_type",
Expand Down Expand Up @@ -151,38 +140,6 @@ def _check_oauth2_custom_header(self):
if missing:
raise exceptions.UserError(rec._msg_missing_auth_param(missing))

def _msg_missing_auth_param(self, missing_fields):
def get_selection_value(fname):
return self._fields.get(fname).convert_to_export(self[fname], self)

return self.env._(
"Webservice '%(name)s' requires '%(auth_type)s' authentication. "
"However, the following field(s) are not valued: %(fields)s",
name=self.name,
auth_type=get_selection_value("auth_type"),
fields=", ".join([f.string for f in missing_fields]),
)

def _valid_field_parameter(self, field, name):
extra_params = ("auth_type",)
return name in extra_params or super()._valid_field_parameter(field, name)

@api.onchange("auth_type")
def _onchange_auth_type(self):
# Keep `oauth2_flow` in sync in the UI as the user edits `auth_type`,
# regardless of whether `server_environment` is installed (see
# `create`/`write` below for the same guarantee on any other write).
if self.auth_type != "oauth2":
self.oauth2_flow = False

@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
records.filtered(
lambda r: r.auth_type != "oauth2" and r.oauth2_flow
).oauth2_flow = False
return records

def write(self, vals):
res = super().write(vals)
if "auth_type" in vals:
Expand All @@ -192,7 +149,17 @@ def write(self, vals):
return res

def call(self, method, *args, **kwargs):
_logger.debug("backend %s: call %s %s %s", self.name, method, args, kwargs)
if not self.auth_type.startswith("oauth2"):
return super().call(method, *args, **kwargs)
# NOTE: oauth2 still relies on `component` for now, until it gets
# extracted to its own module and reworked to drop that dependency too.
_logger.debug(
"backend %s: call %s %s %s",
self.name,
method,
args,
self._sanitize_kwargs_for_log(kwargs),
)
response = getattr(self._get_adapter(), method)(*args, **kwargs)
_logger.debug("backend %s: response: \n%s", self.name, response)
return response
Expand All @@ -204,6 +171,50 @@ def _get_adapter(self):
webservice_protocol=self._get_adapter_protocol(),
)

def _request(self, method, url=None, url_params=None, **kwargs):
self._pop_deprecated_content_only_kwarg(kwargs)
response = super()._request(method, url=url, url_params=url_params, **kwargs)
if self._get_request_content_only():
return response.content
return response

def _pop_deprecated_content_only_kwarg(self, kwargs):
"""Drop the removed ``content_only`` call argument, warning if used.

It used to switch between returning the raw response content or the
full ``requests.Response`` object per call. It's gone: the full
response is always returned now, controlled only (and temporarily)
by the ``CONTENT_ONLY_COMPAT_PARAM`` system parameter for the whole
database - not something to keep sprinkling through call sites.
"""
if "content_only" in kwargs:
kwargs.pop("content_only")
_logger.warning(
"%s: the 'content_only' argument is no longer supported "
"and was ignored; the full response object is always "
"returned now. Remove it from the calling code.",
self.display_name,
)

def _get_request_content_only(self):
"""Whether to return only the response content (legacy behavior).

See ``CONTENT_ONLY_COMPAT_PARAM``.
"""
content_only = bool(
self.env["ir.config_parameter"].sudo().get_param(CONTENT_ONLY_COMPAT_PARAM)
)
if content_only:
_logger.warning(
"%s: returning only the response content because the "
"'%s' system parameter is set (kept for backward "
"compatibility after upgrade). Delete it once the calling "
"code is adapted to use the full response object.",
self.display_name,
CONTENT_ONLY_COMPAT_PARAM,
)
return content_only

def _get_adapter_protocol(self):
protocol = self.protocol
if self.auth_type.startswith("oauth2"):
Expand Down
13 changes: 13 additions & 0 deletions webservice/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## Upgrade from versions prior to 19.0.2.0.1

On upgrade from a version prior to `19.0.2.0.1`, a
`webservice.request_content_only` system parameter is created automatically
(see that version's migration script) to preserve the previous default
behavior of HTTP calls, which returned only the response content instead of
the full `requests.Response` object.

If your code relies on that implicit default, keep the parameter for now.
Once it's adapted to use the full response object (see *Usage*), delete the
parameter under *Settings > Technical > System Parameters* - new installs
never get it set.

## OAuth2 (Client Credentials)

For the *Backend Application (Client Credentials Grant)* flow, two extra options
Expand Down
6 changes: 5 additions & 1 deletion webservice/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
This module creates WebService frameworks to be used globally.

The module introduces support for HTTP Request protocol. The webservice HTTP call returns by default the content of the response. A context 'content_only' can be passed to get the full response object.
The module introduces support for HTTP Request protocol. The webservice HTTP call returns the full `requests.Response` object.

It builds on top of ``webservice_core`` (which provides the ``webservice.backend``
model with public/username-password/API key authentication) to add OAuth2
authentication and ``server_environment`` support.
2 changes: 0 additions & 2 deletions webservice/security/ir.model.access.csv

This file was deleted.

10 changes: 0 additions & 10 deletions webservice/security/ir_rule.xml

This file was deleted.

Loading
Loading