diff --git a/requirements.txt b/requirements.txt
index 70c765a0..cc8d360a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,5 +2,7 @@
PyYAML
jsonschema
oauthlib
+openupgradelib
+requests
requests-oauthlib
responses
diff --git a/webservice/README.rst b/webservice/README.rst
index 654941aa..bea71be8 100644
--- a/webservice/README.rst
+++ b/webservice/README.rst
@@ -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**
@@ -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)
---------------------------
@@ -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 `__:
+Current `maintainers `__:
-|maintainer-etobella|
+|maintainer-etobella| |maintainer-simahawk|
This module is part of the `OCA/web-api `_ project on GitHub.
diff --git a/webservice/__manifest__.py b/webservice/__manifest__.py
index b482d8df..4bff2667 100644
--- a/webservice/__manifest__.py
+++ b/webservice/__manifest__.py
@@ -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": [],
diff --git a/webservice/components/request_adapter.py b/webservice/components/request_adapter.py
index 99645343..b733beb2 100644
--- a/webservice/components/request_adapter.py
+++ b/webservice/components/request_adapter.py
@@ -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__)
@@ -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)
@@ -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
@@ -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(
{
@@ -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
diff --git a/webservice/data/neutralize.sql b/webservice/data/neutralize.sql
index 264b1b17..d58b7269 100644
--- a/webservice/data/neutralize.sql
+++ b/webservice/data/neutralize.sql
@@ -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;
diff --git a/webservice/models/webservice_backend.py b/webservice/models/webservice_backend.py
index 3b7f6916..e4d7b472 100644
--- a/webservice/models/webservice_backend.py
+++ b/webservice/models/webservice_backend.py
@@ -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)"),
@@ -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",
@@ -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:
@@ -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
@@ -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"):
diff --git a/webservice/readme/CONFIGURE.md b/webservice/readme/CONFIGURE.md
index 4cd9ccc6..5cc89fe7 100644
--- a/webservice/readme/CONFIGURE.md
+++ b/webservice/readme/CONFIGURE.md
@@ -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
diff --git a/webservice/readme/DESCRIPTION.md b/webservice/readme/DESCRIPTION.md
index cdd44bd7..74b608df 100644
--- a/webservice/readme/DESCRIPTION.md
+++ b/webservice/readme/DESCRIPTION.md
@@ -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.
diff --git a/webservice/security/ir.model.access.csv b/webservice/security/ir.model.access.csv
deleted file mode 100644
index f8bb5166..00000000
--- a/webservice/security/ir.model.access.csv
+++ /dev/null
@@ -1,2 +0,0 @@
-id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
-access_webservice_backend_edit,webservice_backend edit,model_webservice_backend,base.group_system,1,1,1,1
diff --git a/webservice/security/ir_rule.xml b/webservice/security/ir_rule.xml
deleted file mode 100644
index 367dfb6c..00000000
--- a/webservice/security/ir_rule.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
- webservice_backend multi-company
-
-
- ['|', ('company_id','=',False), ('company_id', 'in', company_ids)]
-
-
-
diff --git a/webservice/static/description/index.html b/webservice/static/description/index.html
index 32e0b279..84bf2614 100644
--- a/webservice/static/description/index.html
+++ b/webservice/static/description/index.html
@@ -377,31 +377,47 @@ 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
+
+
+
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.
+
-
+
For the Backend Application (Client Credentials Grant) flow, two extra
options control how the token is requested, so that endpoints which
deviate from the OAuth2 spec can still be used:
@@ -422,7 +438,7 @@
-
+
Bugs are tracked on GitHub Issues .
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
@@ -450,23 +466,23 @@
Do not contact contributors directly about support or help with technical issues.
-
+
diff --git a/webservice/tests/__init__.py b/webservice/tests/__init__.py
index 88a07b8f..57f297d2 100644
--- a/webservice/tests/__init__.py
+++ b/webservice/tests/__init__.py
@@ -1,4 +1,3 @@
+from . import test_content_only_compat
from . import test_oauth2
-from . import test_webservice
-from . import test_utils
from . import test_neutralize
diff --git a/webservice/tests/test_content_only_compat.py b/webservice/tests/test_content_only_compat.py
new file mode 100644
index 00000000..3552ebed
--- /dev/null
+++ b/webservice/tests/test_content_only_compat.py
@@ -0,0 +1,64 @@
+# Copyright 2026 Camptocamp SA
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+import responses
+
+from .common import CommonWebService
+
+
+class TestContentOnlyCompat(CommonWebService):
+ """`content_only` removal, and its backward-compat system parameter.
+
+ This lives in `webservice`, not `webservice_core`: the compat switch
+ only matters for databases that already ran with the old
+ `content_only=True` default, and that's `webservice`'s history, not
+ `webservice_core`'s (a new, not-yet-released module nobody depends on
+ with that old default).
+ """
+
+ @classmethod
+ def _setup_records(cls):
+ res = super()._setup_records()
+ cls.url = "https://localhost.demo.odoo/"
+ cls.webservice = cls.env["webservice.backend"].create(
+ {
+ "name": "WebService",
+ "protocol": "http",
+ "url": cls.url,
+ "tech_name": "demo_ws_content_only",
+ "auth_type": "none",
+ }
+ )
+ return res
+
+ @responses.activate
+ def test_returns_full_response_by_default(self):
+ responses.add(responses.GET, self.url, body="{}")
+ result = self.webservice.call("get")
+ self.assertEqual(result.content, b"{}")
+ self.assertEqual(result.status_code, 200)
+
+ @responses.activate
+ def test_compat_param_restores_content_only(self):
+ self.env["ir.config_parameter"].sudo().set_param(
+ "webservice.request_content_only", "1"
+ )
+ responses.add(responses.GET, self.url, body="{}")
+ with self.assertLogs(
+ "odoo.addons.webservice.models.webservice_backend", level="WARNING"
+ ) as log_catcher:
+ result = self.webservice.call("get")
+ self.assertEqual(result, b"{}")
+ self.assertTrue(
+ any("webservice.request_content_only" in m for m in log_catcher.output)
+ )
+
+ @responses.activate
+ def test_content_only_kwarg_is_ignored(self):
+ """The removed `content_only` kwarg no longer has any effect."""
+ responses.add(responses.GET, self.url, body="{}")
+ with self.assertLogs(
+ "odoo.addons.webservice.models.webservice_backend", level="WARNING"
+ ) as log_catcher:
+ result = self.webservice.call("get", content_only=True)
+ self.assertEqual(result.content, b"{}")
+ self.assertTrue(any("content_only" in m for m in log_catcher.output))
diff --git a/webservice/tests/test_oauth2.py b/webservice/tests/test_oauth2.py
index 1288cda8..41ef4c8a 100644
--- a/webservice/tests/test_oauth2.py
+++ b/webservice/tests/test_oauth2.py
@@ -70,7 +70,7 @@ def test_fetch_token(self):
delta=1, # Accept a diff of 1s
)
self.assertEqual(responses.calls[1].response.content.decode(), "OK")
- self.assertEqual(result.decode(), "OK")
+ self.assertEqual(result.content.decode(), "OK")
@responses.activate
def test_update_token(self):
@@ -112,7 +112,7 @@ def test_update_token(self):
delta=1, # Accept a diff of 1s
)
self.assertEqual(responses.calls[1].response.content.decode(), "OK")
- self.assertEqual(result.decode(), "OK")
+ self.assertEqual(result.content.decode(), "OK")
@responses.activate
def test_update_token_with_error(self):
@@ -152,7 +152,7 @@ def test_update_token_with_error(self):
)
@responses.activate
- def test_call_with_content_only_false_returns_response(self):
+ def test_call_returns_response(self):
now = time.time()
duration = 3600
responses.add(
@@ -172,7 +172,6 @@ def test_call_with_content_only_false_returns_response(self):
"post",
url=f"{self.url}endpoint",
data="payload",
- content_only=False,
)
self.assertEqual(response.status_code, 200)
diff --git a/webservice/tests/test_utils.py b/webservice/tests/test_utils.py
deleted file mode 100644
index a17f8232..00000000
--- a/webservice/tests/test_utils.py
+++ /dev/null
@@ -1,14 +0,0 @@
-# Copyright 2023 Camptocamp SA
-# @author Simone Orsi
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-
-
-from odoo.tests.common import BaseCase
-
-from odoo.addons.webservice.utils import sanitize_url_for_log
-
-
-class TestUtils(BaseCase):
- def test_url_cleanup(self):
- url = "https://custom.url/?a=1&apikey=secret&password=moresecret"
- self.assertEqual(sanitize_url_for_log(url), "https://custom.url/?a=1")
diff --git a/webservice/upgrades/19.0.2.0.1/post-update.py b/webservice/upgrades/19.0.2.0.1/post-update.py
new file mode 100644
index 00000000..084cdb26
--- /dev/null
+++ b/webservice/upgrades/19.0.2.0.1/post-update.py
@@ -0,0 +1,32 @@
+# Copyright 2026 Camptocamp SA
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from openupgradelib import openupgrade
+
+from odoo.tools import parse_version
+
+CONTENT_ONLY_COMPAT_PARAM = "webservice.request_content_only"
+
+
+@openupgrade.migrate()
+def migrate(env, version):
+ """Preserve the pre-upgrade behavior of HTTP webservice calls.
+
+ Before this version, ``webservice.backend.call()`` (and friends)
+ returned only the response content (raw bytes) by default. That default
+ is gone: calls now always return the full ``requests.Response`` object.
+
+ Existing databases get ``CONTENT_ONLY_COMPAT_PARAM`` set so their
+ calling code keeps working unchanged until it's adapted; new installs
+ never get it, so they see the new behavior right away. Leave the
+ parameter unset (or delete it) once the calling code is updated.
+ """
+ # Databases coming from 18.0 >= 18.0.2.0.1 already went through the same
+ # upgrade step there: don't set the parameter back if it was removed.
+ if version.startswith("18.0.") and parse_version(version) >= parse_version(
+ "18.0.2.0.1"
+ ):
+ return
+ icp = env["ir.config_parameter"].sudo()
+ if not icp.search_count([("key", "=", CONTENT_ONLY_COMPAT_PARAM)]):
+ icp.set_param(CONTENT_ONLY_COMPAT_PARAM, "1")
diff --git a/webservice/views/webservice_backend.xml b/webservice/views/webservice_backend.xml
index 6b398d92..44e52cde 100644
--- a/webservice/views/webservice_backend.xml
+++ b/webservice/views/webservice_backend.xml
@@ -3,167 +3,78 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
- webservice.backend.form (in webservice)
+ webservice.backend.form (oauth2, in webservice)
webservice.backend
+
-
-
-
-
-
- webservice.backend.search (in webservice)
- webservice.backend
-
-
-
-
-
-
-
-
-
-
-
- webservice.backend.tree (in webservice)
- webservice.backend
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
-
- WebService Backend
- webservice.backend
- list,form
- []
- {}
-
-
-
diff --git a/webservice_core/README.rst b/webservice_core/README.rst
new file mode 100644
index 00000000..d865f9f9
--- /dev/null
+++ b/webservice_core/README.rst
@@ -0,0 +1,233 @@
+.. image:: https://odoo-community.org/readme-banner-image
+ :target: https://odoo-community.org/get-involved?utm_source=readme
+ :alt: Odoo Community Association
+
+===============
+WebService Core
+===============
+
+..
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ !! This file is generated by oca-gen-addon-readme !!
+ !! changes will be overwritten. !!
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ !! source digest: sha256:db6e0855773c3a8d7c7d1421e7b0e53ef3f91d376b6ce26249ef94e63e8e5a7a
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
+ :target: https://odoo-community.org/page/development-status
+ :alt: Production/Stable
+.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
+ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
+ :alt: License: AGPL-3
+.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github
+ :target: https://github.com/OCA/web-api/tree/19.0/webservice_core
+ :alt: OCA/web-api
+.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
+ :target: https://translation.odoo-community.org/projects/web-api-19-0/web-api-19-0-webservice_core
+ :alt: Translate me on Weblate
+.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/web-api&target_branch=19.0
+ :alt: Try me on Runboat
+
+|badge1| |badge2| |badge3| |badge4| |badge5|
+
+This module provides the ``webservice.backend`` model with its
+authentication (public, username/password, API key) and HTTP call
+features (``get``/``post``/``put``/``delete``).
+
+It has no dependency on ``component`` or ``server_environment``, so it
+can be used as a lightweight building block by any module needing to
+configure and call an outbound webservice, without pulling in extra
+frameworks.
+
+On top of a backend, you can configure specific, named
+``webservice.endpoint`` records via the UI, instead of only building
+calls in Python via ``webservice.backend.call(method, url_args, ...)``.
+Each endpoint bundles a required description, a fixed HTTP method and
+relative path (appended to the backend URL), static headers, and an
+optional authentication override, fully independent from the backend's.
+Endpoints are called with ``endpoint.call(...)``; calling the backend
+directly with ``backend.call(method, ...)`` remains fully supported.
+
+**Table of contents**
+
+.. contents::
+ :local:
+
+Configuration
+=============
+
+Go to *Settings > Technical > WebService Backend* (requires the
+*Administration / Settings* group) and create a new backend:
+
+- **Name** / **Technical Name**: a label and a unique technical key
+ you'll use to look the backend up from code (e.g. ``env.ref`` is not
+ used here; search by ``tech_name`` instead).
+- **Protocol**: only ``HTTP Request`` is available in this module.
+- **URL**: the base URL every call is relative to, e.g.
+ ``https://api.example.com``. It may contain ``{placeholder}`` tokens
+ (see *Usage*), e.g. ``https://api.example.com/{endpoint}``.
+- **Content-Type**: optional default ``Content-Type`` header for every
+ call.
+- **Timeout**: optional timeout in seconds for the whole request
+ (connect + read). Left empty, a call waits indefinitely.
+
+Under the **Headers** and **Querystring Params** tabs you can configure
+static defaults, merged into every call (see *Usage*). Flag a header or
+a querystring param as **Secret** when its value is a token, a key, ...:
+the value is hidden in the UI and dropped when the database is
+neutralized.
+
+Then configure authentication via **Auth Type**:
+
+- **Public**: no credentials needed.
+- **Username & password**: sent as HTTP Basic Auth. Requires
+ **Username** and **Password**.
+- **API Key**: sent as a custom header. Requires **API Key** and **API
+ Key header** (the header name to send it under, e.g. ``X-Api-Key``).
+
+Required fields depend on the selected auth type; the form only shows
+and requires the ones that apply, and saving enforces it.
+
+Each ``webservice.endpoint`` (see *Description*) has its own
+Content-Type, Timeout, Headers and Querystring Params, overriding the
+backend's own for that specific endpoint - set only what needs to
+differ.
+
+When a database is neutralized, the URL of the backends is replaced by a
+placeholder, and the stored credentials (username, password, API key) of
+backends and endpoints are cleared.
+
+Usage
+=====
+
+Look up the backend (e.g. by its technical name) and call it:
+
+.. code:: python
+
+ backend = env["webservice.backend"].search([("tech_name", "=", "my_api")])
+ result = backend.call("get") # -> the full requests.Response object
+
+``call(method, *args, **kwargs)`` accepts any of the standard HTTP verbs
+(``get``, ``post``, ``put``, ``delete``) and forwards everything else to
+`requests `__, so any of its keyword
+arguments work too (``data``, ``json``, ``params``, ``files``, ...):
+
+.. code:: python
+
+ backend.call("post", data=b"... ")
+ backend.call("post", json={"foo": "bar"})
+
+**URL**: by default the backend's own ``url`` is used. Pass ``url`` to
+hit a different path - relative paths are appended to the backend's URL,
+a full ``http(s)://`` URL is used as-is:
+
+.. code:: python
+
+ backend.call("get", url="orders") # -> /orders
+ backend.call("get", url="https://other.example.com/orders")
+
+If the backend's URL (or the ``url`` passed above) contains
+``{placeholder}`` tokens, fill them with ``url_params``:
+
+.. code:: python
+
+ # backend.url == "https://api.example.com/{endpoint}"
+ backend.call("get", url_params={"endpoint": "orders"})
+
+**Headers**: pass ``headers`` to add/override headers for that call;
+they are merged on top of the backend's own static headers (configured
+in the "Headers" tab), ``Content-Type`` and auth-derived headers (e.g.
+the API key header) - the ``headers`` kwarg wins on matching keys:
+
+.. code:: python
+
+ backend.call("get", headers={"X-Request-Id": "42"})
+
+**Querystring params**: sent via ``requests``' ``params=``, not to be
+confused with ``url_params`` above, which fills ``{placeholder}`` tokens
+in the URL path itself. Configure static defaults in the "Querystring
+Params" tab - a value there may itself contain a ``{placeholder}``,
+resolved against the same ``url_params`` used for the URL. An explicit
+``params`` kwarg passed to ``call()`` wins over the static configuration
+on matching keys:
+
+.. code:: python
+
+ backend.call("get", params={"verbose": "1"})
+
+**Auth override**: pass ``auth`` to bypass the backend's configured auth
+type for a single call (same format ``requests`` itself accepts, e.g. a
+``(user, password)`` tuple):
+
+.. code:: python
+
+ backend.call("get", auth=("other_user", "other_password"))
+
+**Timeout**: pass ``timeout`` to override the backend's own configured
+timeout (in seconds) for a single call:
+
+.. code:: python
+
+ backend.call("get", timeout=5)
+
+**Response**: ``call()`` always returns the full ``requests.Response``
+object (status code, headers, content, ...):
+
+.. code:: python
+
+ response = backend.call("get")
+ response.status_code
+ response.content
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues `_.
+In case of trouble, please check there if your issue has already been reported.
+If you spotted it first, help us to smash it by providing a detailed and welcomed
+`feedback `_.
+
+Do not contact contributors directly about support or help with technical issues.
+
+Credits
+=======
+
+Authors
+-------
+
+* Creu Blanca
+* Camptocamp
+
+Contributors
+------------
+
+- Simone Orsi
+- Enric Tobella
+- Alexandre Fayolle
+
+Maintainers
+-----------
+
+This module is maintained by the OCA.
+
+.. image:: https://odoo-community.org/logo.png
+ :alt: Odoo Community Association
+ :target: https://odoo-community.org
+
+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.
+
+.. |maintainer-simahawk| image:: https://github.com/simahawk.png?size=40px
+ :target: https://github.com/simahawk
+ :alt: simahawk
+
+Current `maintainer `__:
+
+|maintainer-simahawk|
+
+This module is part of the `OCA/web-api `_ project on GitHub.
+
+You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/webservice_core/__init__.py b/webservice_core/__init__.py
new file mode 100644
index 00000000..6d58305f
--- /dev/null
+++ b/webservice_core/__init__.py
@@ -0,0 +1,2 @@
+from . import models
+from .hooks import pre_init_hook
diff --git a/webservice_core/__manifest__.py b/webservice_core/__manifest__.py
new file mode 100644
index 00000000..7a8f74e6
--- /dev/null
+++ b/webservice_core/__manifest__.py
@@ -0,0 +1,24 @@
+# Copyright 2020 Creu Blanca
+# Copyright 2022 Camptocamp SA
+# @author Simone Orsi
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+{
+ "name": "WebService Core",
+ "summary": """Webservice backend & endpoints: auth and call features""",
+ "version": "19.0.1.0.0",
+ "license": "AGPL-3",
+ "development_status": "Production/Stable",
+ "maintainers": ["simahawk"],
+ "author": "Creu Blanca, Camptocamp, Odoo Community Association (OCA)",
+ "website": "https://github.com/OCA/web-api",
+ "depends": ["base"],
+ "external_dependencies": {"python": ["requests", "openupgradelib"]},
+ "data": [
+ "security/ir.model.access.csv",
+ "security/ir_rule.xml",
+ "views/webservice_backend.xml",
+ "views/webservice_endpoint.xml",
+ ],
+ "pre_init_hook": "pre_init_hook",
+}
diff --git a/webservice_core/data/neutralize.sql b/webservice_core/data/neutralize.sql
new file mode 100644
index 00000000..52b4cf78
--- /dev/null
+++ b/webservice_core/data/neutralize.sql
@@ -0,0 +1,25 @@
+-- Drop the endpoints and credentials of the webservice backends, so that
+-- a database copied from another environment does not call external services.
+-- `url` is required, so it gets a placeholder instead of NULL.
+UPDATE webservice_backend
+ SET url = 'https://neutralized.invalid',
+ username = NULL,
+ password = NULL,
+ api_key = NULL;
+
+-- Endpoints can override the authentication of their backend.
+UPDATE webservice_endpoint
+ SET username = NULL,
+ password = NULL,
+ api_key = NULL;
+
+-- Secret querystring params carry tokens, keys, ...
+-- `value` is required, so it gets a placeholder instead of NULL.
+UPDATE webservice_querystring_param
+ SET value = 'neutralized'
+ WHERE secret;
+
+-- Same for secret headers.
+UPDATE webservice_header
+ SET value = 'neutralized'
+ WHERE secret;
diff --git a/webservice_core/hooks.py b/webservice_core/hooks.py
new file mode 100644
index 00000000..52a5f8ab
--- /dev/null
+++ b/webservice_core/hooks.py
@@ -0,0 +1,26 @@
+# Copyright 2026 Camptocamp SA
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from openupgradelib import openupgrade
+
+# `webservice.backend`'s base access rule, multi-company rule, and
+# non-form views (search/list/action/menu) used to be defined by
+# `webservice`, before this module split the base backend out of it. The
+# form view keeps its own `webservice.webservice_backend_form_view` XMLID
+# (its content changed, but `webservice` still owns and extends it), so it
+# is deliberately not in this list.
+MOVED_XMLIDS = [
+ "access_webservice_backend_edit",
+ "rule_webservice_backend_multi_company",
+ "webservice_backend_search_view",
+ "webservice_backend_tree_view",
+ "webservice_backend_act_window",
+ "webservice_backend_menu",
+]
+
+
+def pre_init_hook(env):
+ """Reuse `webservice`'s pre-split records instead of duplicating them."""
+ openupgrade.rename_xmlids(
+ env.cr,
+ [(f"webservice.{xmlid}", f"webservice_core.{xmlid}") for xmlid in MOVED_XMLIDS],
+ )
diff --git a/webservice_core/i18n/it.po b/webservice_core/i18n/it.po
new file mode 100644
index 00000000..25602cee
--- /dev/null
+++ b/webservice_core/i18n/it.po
@@ -0,0 +1,478 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * webservice_core
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Odoo Server 18.0\n"
+"Report-Msgid-Bugs-To: \n"
+"PO-Revision-Date: 2026-11-08 17:46+0000\n"
+"Last-Translator: mymage \n"
+"Language-Team: none\n"
+"Language: it\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: nplurals=2; plural=n != 1;\n"
+"X-Generator: Weblate 5.15.2\n"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__api_key
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__api_key
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__api_key
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__auth_type__api_key
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__auth_type__api_key
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__auth_type__api_key
+msgid "API Key"
+msgstr "Chiave API"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__api_key_header
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__api_key_header
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__api_key_header
+msgid "API Key header"
+msgstr "Intestazione chiave API"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__active
+msgid "Active"
+msgstr "Attivo"
+
+#. module: webservice_core
+#: model:ir.model.constraint,message:webservice_core.constraint_webservice_endpoint_tech_name_backend_uniq
+msgid "An endpoint with this technical name already exists for this backend."
+msgstr "Esiste già un endpoint con questo nome tecnico per questo backend."
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_search_view
+msgid "Archived"
+msgstr "In archivio"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__auth_type
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__auth_type
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__auth_type
+msgid "Auth Type"
+msgstr "Tipo autorizzazione"
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+msgid "Authentication"
+msgstr "Autenticazione"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__backend_id
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_search_view
+msgid "Backend"
+msgstr "Backend"
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__full_url_display
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__full_url_display
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__full_url_display
+msgid ""
+"Best-effort absolute URL, ready to copy/paste. Any '{placeholder}' token is "
+"left unresolved: fill it in before use."
+msgstr ""
+"Migliore URL assoluto, pronto da copiare e incollare. Eventuali segnaposto "
+"nel formato '{placeholder}' rimangono invariati: è necessario completarli "
+"prima dell'uso."
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__company_id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__company_id
+msgid "Company"
+msgstr "Azienda"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__content_type
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__content_type
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__content_type
+msgid "Content Type"
+msgstr "Tipo di contenuto"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__create_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__create_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__create_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__create_uid
+msgid "Created by"
+msgstr "Creato da"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__create_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__create_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__create_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__create_date
+msgid "Created on"
+msgstr "Creato il"
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__http_method__delete
+msgid "DELETE"
+msgstr "DELETE"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__description
+msgid "Description"
+msgstr "Descrizione"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__display_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__display_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__display_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__display_name
+msgid "Display Name"
+msgstr "Nome visualizzato"
+
+#. module: webservice_core
+#. odoo-python
+#: code:addons/webservice_core/models/webservice_endpoint.py:0
+msgid ""
+"Endpoint '%(name)s' overrides authentication: an authentication type is "
+"required."
+msgstr ""
+"L'endpoint '%(name)s' sostituisce l'autenticazione: è necessario specificare "
+"un tipo di autenticazione."
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__endpoint_count
+msgid "Endpoint Count"
+msgstr "Conteggio endpoint"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__endpoint_ids
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_backend_form_view
+msgid "Endpoints"
+msgstr "Endpoint"
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__content_type__application/x-www-form-urlencoded
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__content_type__application/x-www-form-urlencoded
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__content_type__application/x-www-form-urlencoded
+msgid "Form"
+msgstr "Maschera"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__full_url_display
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__full_url_display
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__full_url_display
+msgid "Full Url Display"
+msgstr "Visualizza URL completo"
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__http_method__get
+msgid "GET"
+msgstr "GET"
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_search_view
+msgid "Group By"
+msgstr "Raggruppa per"
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__protocol__http
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__protocol__http
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__protocol__http
+msgid "HTTP Request"
+msgstr "Richiesta HTTP"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__header_ids
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__header_ids
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__header_ids
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_backend_form_view
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+msgid "Headers"
+msgstr "Intestazioni"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__http_method
+msgid "Http Method"
+msgstr "Metodo HTTP"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__id
+msgid "ID"
+msgstr "ID"
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__content_type__application/json
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__content_type__application/json
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__content_type__application/json
+msgid "JSON"
+msgstr "JSON"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__write_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__write_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__write_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__write_uid
+msgid "Last Updated by"
+msgstr "Ultimo aggiornamento di"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__write_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__write_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__write_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__write_date
+msgid "Last Updated on"
+msgstr "Ultimo aggiornamento il"
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_backend_form_view
+msgid "Manage endpoints"
+msgstr "Gestione endpoint"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__name
+msgid "Name"
+msgstr "Nome"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__override_auth
+msgid "Override Authentication"
+msgstr "Sostituisci autenticazione"
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__http_method__post
+msgid "POST"
+msgstr "POST"
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__http_method__put
+msgid "PUT"
+msgstr "PUT"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__password
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__password
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__password
+msgid "Password"
+msgstr "Password"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__path
+msgid "Path"
+msgstr "Percorso"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__protocol
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__protocol
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__protocol
+msgid "Protocol"
+msgstr "Protcollo"
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__auth_type__none
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__auth_type__none
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__auth_type__none
+msgid "Public"
+msgstr "Pubblico"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__querystring_param_ids
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__querystring_param_ids
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__querystring_param_ids
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_backend_form_view
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+msgid "Querystring Params"
+msgstr "Parametri della query string"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__res_id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__res_id
+msgid "Record"
+msgstr "Record"
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__path
+msgid ""
+"Relative path appended to the backend URL. Supports the same '{placeholder}' "
+"syntax as the backend URL."
+msgstr ""
+"Percorso relativo aggiunto all'URL del backend. Supporta la stessa sintassi "
+"'{placeholder}' dell'URL del backend."
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__res_model
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__res_model
+msgid "Res Model"
+msgstr "Modello res"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__secret
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__secret
+msgid "Secret"
+msgstr "Segreto"
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__header_ids
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__header_ids
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__header_ids
+msgid ""
+"Static default headers, merged into every call. An explicit `headers` kwarg "
+"passed to `call()` wins over these."
+msgstr ""
+"Intestazioni predefinite statiche, unite a ogni chiamata. Le intestazioni "
+"specificate esplicitamente con l’argomento `headers` in `call()` hanno la "
+"precedenza su queste."
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__querystring_param_ids
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__querystring_param_ids
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__querystring_param_ids
+msgid ""
+"Static default querystring params, merged into every call. An explicit "
+"`params` kwarg passed to `call()` wins over these. A value may contain a "
+"'{placeholder}' resolved against the same values used to fill the URL path "
+"(the `url_params` kwarg)."
+msgstr ""
+"Parametri statici predefiniti della query string, uniti a ogni chiamata. I "
+"parametri specificati esplicitamente con l’argomento `params` in `call()` "
+"hanno la precedenza su questi. Un valore può contenere un '{placeholder}', "
+"risolto usando gli stessi valori impiegati per compilare il percorso URL "
+"(l’argomento `url_params`)."
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__tech_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__tech_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__tech_name
+msgid "Tech Name"
+msgstr "Nome tecnico"
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_header__secret
+#: model:ir.model.fields,help:webservice_core.field_webservice_querystring_param__secret
+msgid ""
+"The value is a secret (e.g. a token or a key): it is hidden in the UI and "
+"dropped when the database is neutralized."
+msgstr ""
+"Il valore è un segreto (es. un token o una chiave): è nascosto "
+"nell'interfaccia utente e viene eliminato quando il database viene "
+"neutralizzato."
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__timeout
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__timeout
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__timeout
+msgid "Timeout"
+msgstr "Timeout"
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__timeout
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__timeout
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__timeout
+msgid ""
+"Timeout in seconds for the whole request (connect + read). An explicit "
+"`timeout` kwarg passed to `call()` wins over this. Left empty, the call "
+"waits indefinitely."
+msgstr ""
+"Timeout in secondi per l’intera richiesta (connessione + lettura). Il valore "
+"specificato esplicitamente con l’argomento `timeout` in `call()` ha la "
+"precedenza. Se lasciato vuoto, la chiamata attende indefinitamente."
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__tech_name
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__tech_name
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__tech_name
+msgid ""
+"Unique name for technical purposes. Automatically generated from the name if "
+"left empty."
+msgstr ""
+"Nome univoco per scopi tecnici. Generato automaticamente a partire dal nome "
+"se lasciato vuoto."
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__url
+msgid "Url"
+msgstr "URL"
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__override_auth
+msgid "Use this endpoint's own authentication instead of the backend's."
+msgstr ""
+"Usa l'autenticazione specifica di questo endpoint anziché quella del backend."
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__username
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__username
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__username
+msgid "Username"
+msgstr "Nome utente"
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__auth_type__user_pwd
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__auth_type__user_pwd
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__auth_type__user_pwd
+msgid "Username & password"
+msgstr "Nome utente e password"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__value
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__value
+msgid "Value"
+msgstr "Valore"
+
+#. module: webservice_core
+#: model:ir.actions.act_window,name:webservice_core.webservice_backend_act_window
+#: model:ir.model,name:webservice_core.model_webservice_backend
+#: model:ir.ui.menu,name:webservice_core.webservice_backend_menu
+msgid "WebService Backend"
+msgstr "Backend servizio web"
+
+#. module: webservice_core
+#: model:ir.actions.act_window,name:webservice_core.webservice_endpoint_act_window
+#: model:ir.model,name:webservice_core.model_webservice_endpoint
+#: model:ir.ui.menu,name:webservice_core.webservice_endpoint_menu
+msgid "WebService Endpoint"
+msgstr "Endpoint del servizio web"
+
+#. module: webservice_core
+#: model:ir.model,name:webservice_core.model_webservice_header
+msgid "WebService Header"
+msgstr "Intestazione del servizio web"
+
+#. module: webservice_core
+#: model:ir.model,name:webservice_core.model_webservice_querystring_param
+msgid "WebService Querystring Param"
+msgstr "Parametro della query string del servizio web"
+
+#. module: webservice_core
+#. odoo-python
+#: code:addons/webservice_core/models/webservice_request_mixin.py:0
+msgid ""
+"Webservice '%(name)s' requires '%(auth_type)s' authentication. However, the "
+"following field(s) are not valued: %(fields)s"
+msgstr ""
+"Il webservice '%(name)s' richiede autentIcazione '%(auth_type)s'. Comunque, "
+"i seguenti campi non sono calorizzati: %(fields)s"
+
+#. module: webservice_core
+#: model:ir.model,name:webservice_core.model_webservice_request_mixin
+msgid "Webservice Request Mixin"
+msgstr "Mixin richiesta servizio web"
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+msgid "What this endpoint is for..."
+msgstr "A cosa serve questo endpoint..."
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__content_type__application/xml
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__content_type__application/xml
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__content_type__application/xml
+msgid "XML"
+msgstr "XML"
+
+#. module: webservice_core
+#: model:ir.model.constraint,message:webservice_core.constraint_webservice_backend_tech_name_uniq
+msgid "`tech_name` must be unique!"
+msgstr "`tech_name` deve essere univoco!"
diff --git a/webservice_core/i18n/webservice_core.pot b/webservice_core/i18n/webservice_core.pot
new file mode 100644
index 00000000..df091191
--- /dev/null
+++ b/webservice_core/i18n/webservice_core.pot
@@ -0,0 +1,449 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * webservice_core
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Odoo Server 18.0\n"
+"Report-Msgid-Bugs-To: \n"
+"Last-Translator: \n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__api_key
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__api_key
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__api_key
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__auth_type__api_key
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__auth_type__api_key
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__auth_type__api_key
+msgid "API Key"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__api_key_header
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__api_key_header
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__api_key_header
+msgid "API Key header"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__active
+msgid "Active"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.constraint,message:webservice_core.constraint_webservice_endpoint_tech_name_backend_uniq
+msgid "An endpoint with this technical name already exists for this backend."
+msgstr ""
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_search_view
+msgid "Archived"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__auth_type
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__auth_type
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__auth_type
+msgid "Auth Type"
+msgstr ""
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+msgid "Authentication"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__backend_id
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_search_view
+msgid "Backend"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__full_url_display
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__full_url_display
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__full_url_display
+msgid ""
+"Best-effort absolute URL, ready to copy/paste. Any '{placeholder}' token is "
+"left unresolved: fill it in before use."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__company_id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__company_id
+msgid "Company"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__content_type
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__content_type
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__content_type
+msgid "Content Type"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__create_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__create_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__create_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__create_uid
+msgid "Created by"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__create_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__create_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__create_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__create_date
+msgid "Created on"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__http_method__delete
+msgid "DELETE"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__description
+msgid "Description"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__display_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__display_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__display_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__display_name
+msgid "Display Name"
+msgstr ""
+
+#. module: webservice_core
+#. odoo-python
+#: code:addons/webservice_core/models/webservice_endpoint.py:0
+msgid ""
+"Endpoint '%(name)s' overrides authentication: an authentication type is "
+"required."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__endpoint_count
+msgid "Endpoint Count"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__endpoint_ids
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_backend_form_view
+msgid "Endpoints"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__content_type__application/x-www-form-urlencoded
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__content_type__application/x-www-form-urlencoded
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__content_type__application/x-www-form-urlencoded
+msgid "Form"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__full_url_display
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__full_url_display
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__full_url_display
+msgid "Full Url Display"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__http_method__get
+msgid "GET"
+msgstr ""
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_search_view
+msgid "Group By"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__protocol__http
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__protocol__http
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__protocol__http
+msgid "HTTP Request"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__header_ids
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__header_ids
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__header_ids
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_backend_form_view
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+msgid "Headers"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__http_method
+msgid "Http Method"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__id
+msgid "ID"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__content_type__application/json
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__content_type__application/json
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__content_type__application/json
+msgid "JSON"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__write_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__write_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__write_uid
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__write_uid
+msgid "Last Updated by"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__write_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__write_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__write_date
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__write_date
+msgid "Last Updated on"
+msgstr ""
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_backend_form_view
+msgid "Manage endpoints"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__name
+msgid "Name"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__override_auth
+msgid "Override Authentication"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__http_method__post
+msgid "POST"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__http_method__put
+msgid "PUT"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__password
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__password
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__password
+msgid "Password"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__path
+msgid "Path"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__protocol
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__protocol
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__protocol
+msgid "Protocol"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__auth_type__none
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__auth_type__none
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__auth_type__none
+msgid "Public"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__querystring_param_ids
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__querystring_param_ids
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__querystring_param_ids
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_backend_form_view
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+msgid "Querystring Params"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__res_id
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__res_id
+msgid "Record"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__path
+msgid ""
+"Relative path appended to the backend URL. Supports the same '{placeholder}'"
+" syntax as the backend URL."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__res_model
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__res_model
+msgid "Res Model"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__secret
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__secret
+msgid "Secret"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__header_ids
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__header_ids
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__header_ids
+msgid ""
+"Static default headers, merged into every call. An explicit `headers` kwarg "
+"passed to `call()` wins over these."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__querystring_param_ids
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__querystring_param_ids
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__querystring_param_ids
+msgid ""
+"Static default querystring params, merged into every call. An explicit "
+"`params` kwarg passed to `call()` wins over these. A value may contain a "
+"'{placeholder}' resolved against the same values used to fill the URL path "
+"(the `url_params` kwarg)."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__tech_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__tech_name
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__tech_name
+msgid "Tech Name"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_header__secret
+#: model:ir.model.fields,help:webservice_core.field_webservice_querystring_param__secret
+msgid ""
+"The value is a secret (e.g. a token or a key): it is hidden in the UI and "
+"dropped when the database is neutralized."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__timeout
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__timeout
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__timeout
+msgid "Timeout"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__timeout
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__timeout
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__timeout
+msgid ""
+"Timeout in seconds for the whole request (connect + read). An explicit "
+"`timeout` kwarg passed to `call()` wins over this. Left empty, the call "
+"waits indefinitely."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_backend__tech_name
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__tech_name
+#: model:ir.model.fields,help:webservice_core.field_webservice_request_mixin__tech_name
+msgid ""
+"Unique name for technical purposes. Automatically generated from the name if"
+" left empty."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__url
+msgid "Url"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,help:webservice_core.field_webservice_endpoint__override_auth
+msgid "Use this endpoint's own authentication instead of the backend's."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_backend__username
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_endpoint__username
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_request_mixin__username
+msgid "Username"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__auth_type__user_pwd
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__auth_type__user_pwd
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__auth_type__user_pwd
+msgid "Username & password"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_header__value
+#: model:ir.model.fields,field_description:webservice_core.field_webservice_querystring_param__value
+msgid "Value"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.actions.act_window,name:webservice_core.webservice_backend_act_window
+#: model:ir.model,name:webservice_core.model_webservice_backend
+#: model:ir.ui.menu,name:webservice_core.webservice_backend_menu
+msgid "WebService Backend"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.actions.act_window,name:webservice_core.webservice_endpoint_act_window
+#: model:ir.model,name:webservice_core.model_webservice_endpoint
+#: model:ir.ui.menu,name:webservice_core.webservice_endpoint_menu
+msgid "WebService Endpoint"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model,name:webservice_core.model_webservice_header
+msgid "WebService Header"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model,name:webservice_core.model_webservice_querystring_param
+msgid "WebService Querystring Param"
+msgstr ""
+
+#. module: webservice_core
+#. odoo-python
+#: code:addons/webservice_core/models/webservice_request_mixin.py:0
+msgid ""
+"Webservice '%(name)s' requires '%(auth_type)s' authentication. However, the "
+"following field(s) are not valued: %(fields)s"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model,name:webservice_core.model_webservice_request_mixin
+msgid "Webservice Request Mixin"
+msgstr ""
+
+#. module: webservice_core
+#: model_terms:ir.ui.view,arch_db:webservice_core.webservice_endpoint_form_view
+msgid "What this endpoint is for..."
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_backend__content_type__application/xml
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_endpoint__content_type__application/xml
+#: model:ir.model.fields.selection,name:webservice_core.selection__webservice_request_mixin__content_type__application/xml
+msgid "XML"
+msgstr ""
+
+#. module: webservice_core
+#: model:ir.model.constraint,message:webservice_core.constraint_webservice_backend_tech_name_uniq
+msgid "`tech_name` must be unique!"
+msgstr ""
diff --git a/webservice_core/models/__init__.py b/webservice_core/models/__init__.py
new file mode 100644
index 00000000..c8b35fbb
--- /dev/null
+++ b/webservice_core/models/__init__.py
@@ -0,0 +1,5 @@
+from . import webservice_header
+from . import webservice_querystring_param
+from . import webservice_request_mixin
+from . import webservice_backend
+from . import webservice_endpoint
diff --git a/webservice_core/models/webservice_backend.py b/webservice_core/models/webservice_backend.py
new file mode 100644
index 00000000..15f8c0ef
--- /dev/null
+++ b/webservice_core/models/webservice_backend.py
@@ -0,0 +1,59 @@
+# Copyright 2020 Creu Blanca
+# Copyright 2022 Camptocamp SA
+# @author Simone Orsi
+# @author Alexandre Fayolle
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from odoo import api, fields, models
+
+
+class WebserviceBackend(models.Model):
+ _name = "webservice.backend"
+ _inherit = ["webservice.request.mixin"]
+ _description = "WebService Backend"
+
+ _tech_name_uniq = models.Constraint(
+ "unique(tech_name)",
+ "`tech_name` must be unique!",
+ )
+
+ name = fields.Char(required=True)
+ url = fields.Char(required=True)
+ company_id = fields.Many2one("res.company", string="Company")
+ endpoint_ids = fields.One2many(
+ "webservice.endpoint", "backend_id", string="Endpoints"
+ )
+ endpoint_count = fields.Integer(compute="_compute_endpoint_count")
+
+ def _get_base_url(self):
+ return self.url
+
+ @api.depends("url")
+ def _compute_full_url_display(self):
+ return super()._compute_full_url_display()
+
+ def _get_secret_names(self):
+ # Endpoint calls are logged by the backend, with the endpoint's
+ # headers and params merged in.
+ header_names, param_names = super()._get_secret_names()
+ for endpoint in self.endpoint_ids:
+ endpoint_headers, endpoint_params = endpoint._get_own_secret_names()
+ header_names |= endpoint_headers
+ param_names |= endpoint_params
+ return header_names, param_names
+
+ def _compute_endpoint_count(self):
+ data = self.env["webservice.endpoint"]._read_group(
+ [("backend_id", "in", self.ids)], ["backend_id"], ["__count"]
+ )
+ mapped_data = {backend.id: count for backend, count in data}
+ for rec in self:
+ rec.endpoint_count = mapped_data.get(rec.id, 0)
+
+ def action_view_endpoints(self):
+ self.ensure_one()
+ action = self.env["ir.actions.actions"]._for_xml_id(
+ "webservice_core.webservice_endpoint_act_window"
+ )
+ action["domain"] = [("backend_id", "=", self.id)]
+ action["context"] = {"default_backend_id": self.id}
+ return action
diff --git a/webservice_core/models/webservice_endpoint.py b/webservice_core/models/webservice_endpoint.py
new file mode 100644
index 00000000..db041bad
--- /dev/null
+++ b/webservice_core/models/webservice_endpoint.py
@@ -0,0 +1,118 @@
+# Copyright 2026 Camptocamp SA
+# @author Simone Orsi
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from odoo import api, exceptions, fields, models
+
+
+class WebserviceEndpoint(models.Model):
+ """A specific, UI-configurable call on a webservice backend.
+
+ Unlike a plain ``backend.call(method, url=..., ...)``, an endpoint bundles
+ the HTTP method, relative path, static headers and (optionally) its own
+ authentication into one named, reusable record: ``endpoint.call(...)``.
+
+ Authentication is inherited from the backend unless ``override_auth`` is
+ set, in which case the endpoint uses its own auth fields (from
+ ``webservice.request.mixin``) instead - fully independent from the
+ backend's credentials.
+
+ """
+
+ _name = "webservice.endpoint"
+ _inherit = ["webservice.request.mixin"]
+ _description = "WebService Endpoint"
+
+ name = fields.Char(required=True)
+ tech_name = fields.Char(required=True)
+ description = fields.Text(required=True)
+ backend_id = fields.Many2one(
+ "webservice.backend", required=True, ondelete="cascade", index=True
+ )
+ company_id = fields.Many2one(
+ related="backend_id.company_id", store=True, readonly=True
+ )
+ active = fields.Boolean(default=True)
+ http_method = fields.Selection(
+ [
+ ("get", "GET"),
+ ("post", "POST"),
+ ("put", "PUT"),
+ ("delete", "DELETE"),
+ ],
+ required=True,
+ default="get",
+ )
+ path = fields.Char(
+ help="Relative path appended to the backend URL. "
+ "Supports the same '{placeholder}' syntax as the backend URL."
+ )
+ override_auth = fields.Boolean(
+ string="Override Authentication",
+ help="Use this endpoint's own authentication instead of the backend's.",
+ )
+ protocol = fields.Selection(default="http")
+ auth_type = fields.Selection(required=False)
+
+ _tech_name_backend_uniq = models.Constraint(
+ "unique(backend_id, tech_name)",
+ "An endpoint with this technical name already exists for this backend.",
+ )
+
+ @api.constrains("override_auth", "auth_type")
+ def _check_override_auth(self):
+ for rec in self:
+ if rec.override_auth and not rec.auth_type:
+ raise exceptions.UserError(
+ self.env._(
+ "Endpoint '%(name)s' overrides authentication: "
+ "an authentication type is required.",
+ name=rec.name,
+ )
+ )
+
+ @api.depends("path")
+ @api.depends_context("webservice_endpoint_display_path")
+ def _compute_display_name(self):
+ if not self.env.context.get("webservice_endpoint_display_path"):
+ return super()._compute_display_name()
+ for rec in self:
+ rec.display_name = f"{rec.name} ({rec.path})" if rec.path else rec.name
+
+ def _get_base_url(self):
+ return self.backend_id.url
+
+ def _get_display_url(self):
+ return self._compose_url(self.path)
+
+ @api.depends("path", "backend_id.url")
+ def _compute_full_url_display(self):
+ return super()._compute_full_url_display()
+
+ def _call_prepare(self, **kwargs):
+ # Precedence: call-time kwarg > endpoint config > backend config.
+ # Each `_call_prepare` lets existing `kwargs` win over its own
+ # config, so call the endpoint's first - it only yields to the
+ # original call-time kwargs - then the backend's, which just
+ # fills in what's still missing.
+ kwargs = super()._call_prepare(**kwargs)
+ return self.backend_id._call_prepare(**kwargs)
+
+ def _get_own_secret_names(self):
+ """Return the secret names configured on the endpoint itself."""
+ return super()._get_secret_names()
+
+ def _get_secret_names(self):
+ # The backend's headers and params are merged into the endpoint call.
+ header_names, param_names = self._get_own_secret_names()
+ backend_headers, backend_params = self.backend_id._get_secret_names()
+ return header_names | backend_headers, param_names | backend_params
+
+ def call(self, url_params=None, **kwargs):
+ self.ensure_one()
+ kwargs.setdefault("url", self.path)
+ if url_params:
+ kwargs["url_params"] = url_params
+ kwargs = self._call_prepare(**kwargs)
+ if self.override_auth:
+ return super().call(self.http_method, **kwargs)
+ return self.backend_id.call(self.http_method, **kwargs)
diff --git a/webservice_core/models/webservice_header.py b/webservice_core/models/webservice_header.py
new file mode 100644
index 00000000..91a30880
--- /dev/null
+++ b/webservice_core/models/webservice_header.py
@@ -0,0 +1,28 @@
+# Copyright 2026 Camptocamp SA
+# @author Simone Orsi
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from odoo import fields, models
+
+
+class WebserviceHeader(models.Model):
+ """A static default HTTP header for a webservice backend or endpoint.
+
+ Generic (``res_model``/``res_id``) so it can be attached to any model
+ inheriting ``webservice.request.mixin``, not just one of them - see
+ ``header_ids`` on the mixin.
+
+ """
+
+ _name = "webservice.header"
+ _description = "WebService Header"
+
+ res_model = fields.Char(required=True, index=True)
+ res_id = fields.Many2oneReference(
+ string="Record", model_field="res_model", required=True, index=True
+ )
+ name = fields.Char(required=True)
+ value = fields.Char(required=True)
+ secret = fields.Boolean(
+ help="The value is a secret (e.g. a token or a key): "
+ "it is hidden in the UI and dropped when the database is neutralized.",
+ )
diff --git a/webservice_core/models/webservice_querystring_param.py b/webservice_core/models/webservice_querystring_param.py
new file mode 100644
index 00000000..39386ee6
--- /dev/null
+++ b/webservice_core/models/webservice_querystring_param.py
@@ -0,0 +1,34 @@
+# Copyright 2026 Camptocamp SA
+# @author Simone Orsi
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from odoo import fields, models
+
+
+class WebserviceQueryStringParam(models.Model):
+ """A static default querystring param for a webservice backend or endpoint.
+
+ Sent as an actual HTTP querystring param (``requests``' ``params=``), not
+ to be confused with the ``url_params`` kwarg accepted by ``call()``,
+ which fills ``{placeholder}`` tokens in the URL path itself. A param's
+ ``value`` here may still contain such a ``{placeholder}``: it is resolved
+ against the same substitution values before the request is sent.
+
+ Generic (``res_model``/``res_id``) so it can be attached to any model
+ inheriting ``webservice.request.mixin`` - see ``querystring_param_ids``
+ on the mixin.
+
+ """
+
+ _name = "webservice.querystring.param"
+ _description = "WebService Querystring Param"
+
+ res_model = fields.Char(required=True, index=True)
+ res_id = fields.Many2oneReference(
+ string="Record", model_field="res_model", required=True, index=True
+ )
+ name = fields.Char(required=True)
+ value = fields.Char(required=True)
+ secret = fields.Boolean(
+ help="The value is a secret (e.g. a token or a key): "
+ "it is hidden in the UI and dropped when the database is neutralized.",
+ )
diff --git a/webservice_core/models/webservice_request_mixin.py b/webservice_core/models/webservice_request_mixin.py
new file mode 100644
index 00000000..a51c7559
--- /dev/null
+++ b/webservice_core/models/webservice_request_mixin.py
@@ -0,0 +1,350 @@
+# Copyright 2020 Creu Blanca
+# Copyright 2022 Camptocamp SA
+# @author Simone Orsi
+# @author Alexandre Fayolle
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+import logging
+
+import requests
+
+from odoo import Command, api, exceptions, fields, models
+
+from ..utils import sanitize_url_for_log, sanitize_values_for_log
+
+_logger = logging.getLogger(__name__)
+
+
+class WebserviceRequestMixin(models.AbstractModel):
+ """Auth configuration + HTTP call features for any webservice-like record.
+
+ Any model inheriting this mixin becomes able to issue authenticated HTTP
+ requests based on its own ``auth_type``/credential fields, resolved via
+ ``self._get_base_url()`` which must be implemented by the model.
+
+ ``call()`` dispatches by ``self._get_protocol()`` (``self.protocol`` by
+ default) to a ``_handle_call_for_`` method that actually
+ performs the request - ``_handle_call_for_http`` today. A new protocol is
+ added by implementing a new ``_handle_call_for_``.
+
+ Extra auth types are added by other modules via plain model inheritance:
+ add the new value to the ``auth_type`` selection, add fields tagged with
+ the matching ``auth_type=`` parameter, and implement
+ ``_get_auth_for_``/``_get_headers_for_`` and/or override
+ ``_request`` when the whole HTTP request flow needs to change (e.g.
+ oauth2).
+
+ """
+
+ _name = "webservice.request.mixin"
+ _description = "Webservice Request Mixin"
+
+ tech_name = fields.Char(
+ required=True,
+ copy=False,
+ help="Unique name for technical purposes. "
+ "Automatically generated from the name if left empty.",
+ )
+ protocol = fields.Selection([("http", "HTTP Request")], required=True)
+ auth_type = fields.Selection(
+ selection=[
+ ("none", "Public"),
+ ("user_pwd", "Username & password"),
+ ("api_key", "API Key"),
+ ],
+ required=True,
+ )
+ 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")
+ content_type = fields.Selection(
+ [
+ ("application/json", "JSON"),
+ ("application/xml", "XML"),
+ ("application/x-www-form-urlencoded", "Form"),
+ ],
+ )
+ timeout = fields.Float(
+ help="Timeout in seconds for the whole request (connect + read). "
+ "An explicit `timeout` kwarg passed to `call()` wins over this. "
+ "Left empty, the call waits indefinitely.",
+ )
+ full_url_display = fields.Char(
+ compute="_compute_full_url_display",
+ help="Best-effort absolute URL, ready to copy/paste. "
+ "Any '{placeholder}' token is left unresolved: fill it in before use.",
+ )
+ header_ids = fields.One2many(
+ "webservice.header",
+ "res_id",
+ string="Headers",
+ domain=lambda self: [("res_model", "=", self._name)],
+ help="Static default headers, merged into every call. "
+ "An explicit `headers` kwarg passed to `call()` wins over these.",
+ )
+ querystring_param_ids = fields.One2many(
+ "webservice.querystring.param",
+ "res_id",
+ string="Querystring Params",
+ domain=lambda self: [("res_model", "=", self._name)],
+ help="Static default querystring params, merged into every call. "
+ "An explicit `params` kwarg passed to `call()` wins over these. "
+ "A value may contain a '{placeholder}' resolved against the same "
+ "values used to fill the URL path (the `url_params` kwarg).",
+ )
+
+ @api.model_create_multi
+ def create(self, vals_list):
+ for vals in vals_list:
+ self._set_reference_line_defaults(vals)
+ self._handle_tech_name(vals)
+ return super().create(vals_list)
+
+ def write(self, vals):
+ self._set_reference_line_defaults(vals)
+ self._handle_tech_name(vals)
+ return super().write(vals)
+
+ def _set_reference_line_defaults(self, vals):
+ # `header_ids`/`querystring_param_ids` point to generic
+ # (`res_model`/`res_id`) line models: the ORM only auto-fills
+ # `res_id` (the declared inverse of the One2many), so `res_model`
+ # must be set explicitly here.
+ for fname in ("header_ids", "querystring_param_ids"):
+ for command in vals.get(fname) or []:
+ if command[0] == Command.CREATE:
+ command[2].setdefault("res_model", self._name)
+
+ @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))
+
+ 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("name")
+ def _onchange_name_for_tech_name(self):
+ # Keep this specific name for the method to avoid possible overrides
+ # of existing `_onchange_name` methods
+ if self.name and not self.tech_name:
+ self.tech_name = self.name
+
+ @api.onchange("tech_name")
+ def _onchange_tech_name(self):
+ if self.tech_name:
+ # make sure it's normalized
+ self.tech_name = self._normalize_tech_name(self.tech_name)
+
+ def _handle_tech_name(self, vals):
+ # make sure technical names are always there
+ if not vals.get("tech_name") and vals.get("name"):
+ vals["tech_name"] = self._normalize_tech_name(vals["name"])
+
+ def _normalize_tech_name(self, name):
+ return self.env["ir.http"]._slugify(name).replace("-", "_")
+
+ def call(self, method, *args, **kwargs):
+ kwargs = self._call_prepare(**kwargs)
+ _logger.debug(
+ "%s: call %s %s %s",
+ self.display_name,
+ method,
+ args,
+ self._sanitize_kwargs_for_log(kwargs),
+ )
+ handler = getattr(self, "_handle_call_for_" + self._get_protocol())
+ response = handler(method, *args, **kwargs)
+ _logger.debug("%s: response: \n%s", self.display_name, response)
+ return response
+
+ def _call_prepare(self, **kwargs):
+ """Merge this record's own configured headers/querystring params into kwargs.
+
+ Call-time values (already present in ``kwargs``) win over this
+ record's own configuration for matching keys.
+
+ """
+ headers = {h.name: h.value for h in self.header_ids}
+ headers.update(kwargs.pop("headers", None) or {})
+ if headers:
+ kwargs["headers"] = headers
+
+ params = {p.name: p.value for p in self.querystring_param_ids}
+ params.update(kwargs.pop("params", None) or {})
+ if params:
+ kwargs["params"] = params
+
+ if self.content_type and "content_type" not in kwargs:
+ kwargs["content_type"] = self.content_type
+
+ if self.timeout and "timeout" not in kwargs:
+ kwargs["timeout"] = self.timeout
+
+ return kwargs
+
+ def _get_protocol(self):
+ return self.protocol
+
+ def _handle_call_for_http(self, method, **kwargs):
+ return self._request(method, **kwargs)
+
+ # shortcuts
+ def call_get(self, **kwargs):
+ return self.call("get", **kwargs)
+
+ def call_post(self, **kwargs):
+ return self.call("post", **kwargs)
+
+ def call_put(self, **kwargs):
+ return self.call("put", **kwargs)
+
+ def call_delete(self, **kwargs):
+ return self.call("delete", **kwargs)
+
+ def _request(self, method, url=None, url_params=None, **kwargs):
+ url = self._get_url(url=url, url_params=url_params)
+ # ``content_type`` is only consumed by ``_get_headers``: it is not a valid
+ # ``requests.request`` kwarg and must not leak into ``new_kwargs`` below.
+ content_type = kwargs.pop("content_type", False)
+ # Not resolved via `self.timeout` here: by the time `_request` runs,
+ # `self` may be the backend even for an endpoint-configured timeout
+ # (see `_call_prepare`), so the value must already be in `kwargs`.
+ timeout = kwargs.pop("timeout", None)
+ url_to_log = self._sanitize_url_for_log(url)
+ _logger.info("%s call to %s", method, url_to_log)
+ new_kwargs = kwargs.copy()
+ new_kwargs.update(
+ {
+ "auth": self._get_auth(**kwargs),
+ "headers": self._get_headers(content_type=content_type, **kwargs),
+ "timeout": timeout or None,
+ }
+ )
+ if new_kwargs.get("params"):
+ new_kwargs["params"] = self._resolve_query_params(
+ new_kwargs["params"], url_params
+ )
+ # pylint: disable=E8106
+ request = requests.request(method, url, **new_kwargs)
+ request.raise_for_status()
+ return request
+
+ def _sanitize_url_for_log(self, url):
+ return sanitize_url_for_log(url)
+
+ def _get_secret_names(self):
+ """Return the names of the secret headers and querystring params."""
+ return (
+ {h.name for h in self.header_ids if h.secret},
+ {p.name for p in self.querystring_param_ids if p.secret},
+ )
+
+ def _sanitize_kwargs_for_log(self, kwargs):
+ """Return a copy of the call kwargs with the secret values masked."""
+ header_names, param_names = self._get_secret_names()
+ kwargs = dict(kwargs)
+ for key, names in (("headers", header_names), ("params", param_names)):
+ if kwargs.get(key):
+ kwargs[key] = sanitize_values_for_log(kwargs[key], secret_keys=names)
+ return kwargs
+
+ def _get_auth(self, auth=False, **kwargs):
+ if auth:
+ return auth
+ handler = getattr(self, "_get_auth_for_" + self.auth_type, None)
+ return handler(**kwargs) if handler else None
+
+ def _get_auth_for_user_pwd(self, **kw):
+ if self.username and self.password:
+ return self.username, self.password
+ return None
+
+ def _get_headers(self, content_type=False, headers=False, **kwargs):
+ headers = headers or {}
+ if content_type or self.content_type:
+ result = {
+ "Content-Type": content_type or self.content_type,
+ }
+ else:
+ result = {}
+ handler = getattr(self, "_get_headers_for_" + self.auth_type, None)
+ if handler:
+ headers.update(handler(**kwargs))
+ result.update(headers)
+ return result
+
+ def _get_headers_for_api_key(self, **kw):
+ return {self.api_key_header: self.api_key}
+
+ def _get_url(self, url=None, url_params=None, **kwargs):
+ url = self._compose_url(url)
+ url_params = url_params or kwargs
+ return url.format(**url_params)
+
+ def _compose_url(self, url=None):
+ base = self._get_base_url()
+ if not url:
+ return base
+ if not url.startswith(base):
+ if not url.startswith("http"):
+ return f"{base.rstrip('/')}/{url.lstrip('/')}"
+ # TODO: if url is given, we should validate the domain
+ # to avoid abusing a webservice backend for different calls.
+ return url
+
+ @api.depends()
+ def _compute_full_url_display(self):
+ for rec in self:
+ rec.full_url_display = rec._get_display_url()
+
+ def _get_display_url(self):
+ """Best-effort absolute URL for display/copy in the UI.
+
+ Unlike ``_get_url()``, ``{placeholder}`` tokens are never resolved
+ here: there is no call-time value to fill them with, so they are
+ left as-is for the user to replace.
+
+ Models with a relative part of their own (e.g. an endpoint's
+ ``path``) should override this to compose it with ``_compose_url()``.
+ """
+ return self._get_base_url()
+
+ def _resolve_query_params(self, params, url_params):
+ url_params = url_params or {}
+ return {
+ name: value.format(**url_params) if isinstance(value, str) else value
+ for name, value in params.items()
+ }
+
+ def _get_base_url(self):
+ """Return the base url requests are relative to.
+
+ To be implemented by models inheriting this mixin.
+
+ """
+ raise NotImplementedError
diff --git a/webservice_core/pyproject.toml b/webservice_core/pyproject.toml
new file mode 100644
index 00000000..4231d0cc
--- /dev/null
+++ b/webservice_core/pyproject.toml
@@ -0,0 +1,3 @@
+[build-system]
+requires = ["whool"]
+build-backend = "whool.buildapi"
diff --git a/webservice_core/readme/CONFIGURE.md b/webservice_core/readme/CONFIGURE.md
new file mode 100644
index 00000000..505264c4
--- /dev/null
+++ b/webservice_core/readme/CONFIGURE.md
@@ -0,0 +1,38 @@
+Go to *Settings > Technical > WebService Backend* (requires the
+*Administration / Settings* group) and create a new backend:
+
+- **Name** / **Technical Name**: a label and a unique technical key you'll
+ use to look the backend up from code (e.g. `env.ref` is not used here;
+ search by `tech_name` instead).
+- **Protocol**: only `HTTP Request` is available in this module.
+- **URL**: the base URL every call is relative to, e.g.
+ `https://api.example.com`. It may contain `{placeholder}` tokens (see
+ *Usage*), e.g. `https://api.example.com/{endpoint}`.
+- **Content-Type**: optional default `Content-Type` header for every call.
+- **Timeout**: optional timeout in seconds for the whole request (connect +
+ read). Left empty, a call waits indefinitely.
+
+Under the **Headers** and **Querystring Params** tabs you can configure
+static defaults, merged into every call (see *Usage*).
+Flag a header or a querystring param as **Secret** when its value is a
+token, a key, ...: the value is hidden in the UI and dropped when the
+database is neutralized.
+
+Then configure authentication via **Auth Type**:
+
+- **Public**: no credentials needed.
+- **Username & password**: sent as HTTP Basic Auth. Requires **Username**
+ and **Password**.
+- **API Key**: sent as a custom header. Requires **API Key** and
+ **API Key header** (the header name to send it under, e.g. `X-Api-Key`).
+
+Required fields depend on the selected auth type; the form only shows and
+requires the ones that apply, and saving enforces it.
+
+Each `webservice.endpoint` (see *Description*) has its own Content-Type,
+Timeout, Headers and Querystring Params, overriding the backend's own for
+that specific endpoint - set only what needs to differ.
+
+When a database is neutralized, the URL of the backends is replaced by a
+placeholder, and the stored credentials (username, password, API key) of
+backends and endpoints are cleared.
diff --git a/webservice_core/readme/CONTRIBUTORS.md b/webservice_core/readme/CONTRIBUTORS.md
new file mode 100644
index 00000000..d0412679
--- /dev/null
+++ b/webservice_core/readme/CONTRIBUTORS.md
@@ -0,0 +1,3 @@
+- Simone Orsi \<\>
+- Enric Tobella \<\>
+- Alexandre Fayolle \<\>
diff --git a/webservice_core/readme/DESCRIPTION.md b/webservice_core/readme/DESCRIPTION.md
new file mode 100644
index 00000000..68ada934
--- /dev/null
+++ b/webservice_core/readme/DESCRIPTION.md
@@ -0,0 +1,15 @@
+This module provides the ``webservice.backend`` model with its authentication
+(public, username/password, API key) and HTTP call features (``get``/``post``/``put``/``delete``).
+
+It has no dependency on ``component`` or ``server_environment``, so it can be used
+as a lightweight building block by any module needing to configure and call
+an outbound webservice, without pulling in extra frameworks.
+
+On top of a backend, you can configure specific, named ``webservice.endpoint``
+records via the UI, instead of only building calls in Python via
+``webservice.backend.call(method, url_args, ...)``. Each endpoint bundles a
+required description, a fixed HTTP method and relative path (appended to the
+backend URL), static headers, and an optional authentication override, fully
+independent from the backend's. Endpoints are called with ``endpoint.call(...)``;
+calling the backend directly with ``backend.call(method, ...)`` remains fully
+supported.
diff --git a/webservice_core/readme/USAGE.md b/webservice_core/readme/USAGE.md
new file mode 100644
index 00000000..4d982a6a
--- /dev/null
+++ b/webservice_core/readme/USAGE.md
@@ -0,0 +1,77 @@
+Look up the backend (e.g. by its technical name) and call it:
+
+```python
+backend = env["webservice.backend"].search([("tech_name", "=", "my_api")])
+result = backend.call("get") # -> the full requests.Response object
+```
+
+`call(method, *args, **kwargs)` accepts any of the standard HTTP verbs
+(`get`, `post`, `put`, `delete`) and forwards everything else to
+[requests](https://requests.readthedocs.io/), so any of its keyword
+arguments work too (`data`, `json`, `params`, `files`, ...):
+
+```python
+backend.call("post", data=b"... ")
+backend.call("post", json={"foo": "bar"})
+```
+
+**URL**: by default the backend's own `url` is used. Pass `url` to hit a
+different path - relative paths are appended to the backend's URL, a full
+`http(s)://` URL is used as-is:
+
+```python
+backend.call("get", url="orders") # -> /orders
+backend.call("get", url="https://other.example.com/orders")
+```
+
+If the backend's URL (or the `url` passed above) contains `{placeholder}`
+tokens, fill them with `url_params`:
+
+```python
+# backend.url == "https://api.example.com/{endpoint}"
+backend.call("get", url_params={"endpoint": "orders"})
+```
+
+**Headers**: pass `headers` to add/override headers for that call; they are
+merged on top of the backend's own static headers (configured in the
+"Headers" tab), `Content-Type` and auth-derived headers (e.g. the API key
+header) - the `headers` kwarg wins on matching keys:
+
+```python
+backend.call("get", headers={"X-Request-Id": "42"})
+```
+
+**Querystring params**: sent via `requests`' `params=`, not to be confused
+with `url_params` above, which fills `{placeholder}` tokens in the URL path
+itself. Configure static defaults in the "Querystring Params" tab - a
+value there may itself contain a `{placeholder}`, resolved against the
+same `url_params` used for the URL. An explicit `params` kwarg passed to
+`call()` wins over the static configuration on matching keys:
+
+```python
+backend.call("get", params={"verbose": "1"})
+```
+
+**Auth override**: pass `auth` to bypass the backend's configured auth type
+for a single call (same format `requests` itself accepts, e.g. a
+`(user, password)` tuple):
+
+```python
+backend.call("get", auth=("other_user", "other_password"))
+```
+
+**Timeout**: pass `timeout` to override the backend's own configured
+timeout (in seconds) for a single call:
+
+```python
+backend.call("get", timeout=5)
+```
+
+**Response**: `call()` always returns the full `requests.Response` object
+(status code, headers, content, ...):
+
+```python
+response = backend.call("get")
+response.status_code
+response.content
+```
diff --git a/webservice_core/security/ir.model.access.csv b/webservice_core/security/ir.model.access.csv
new file mode 100644
index 00000000..ad7d1667
--- /dev/null
+++ b/webservice_core/security/ir.model.access.csv
@@ -0,0 +1,5 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_webservice_backend_edit,webservice_backend edit,model_webservice_backend,base.group_system,1,1,1,1
+access_webservice_endpoint_edit,webservice_endpoint edit,model_webservice_endpoint,base.group_system,1,1,1,1
+access_webservice_header_edit,webservice_header edit,model_webservice_header,base.group_system,1,1,1,1
+access_webservice_querystring_param_edit,webservice_querystring_param edit,model_webservice_querystring_param,base.group_system,1,1,1,1
diff --git a/webservice_core/security/ir_rule.xml b/webservice_core/security/ir_rule.xml
new file mode 100644
index 00000000..417ef65a
--- /dev/null
+++ b/webservice_core/security/ir_rule.xml
@@ -0,0 +1,21 @@
+
+
+
+
+ webservice_backend multi-company
+
+
+ ['|', ('company_id','=',False), ('company_id', 'in', company_ids)]
+
+
+
+
+ webservice_endpoint multi-company
+
+
+ ['|', ('company_id','=',False), ('company_id', 'in', company_ids)]
+
+
+
diff --git a/webservice_core/static/description/icon.png b/webservice_core/static/description/icon.png
new file mode 100644
index 00000000..3a0328b5
Binary files /dev/null and b/webservice_core/static/description/icon.png differ
diff --git a/webservice_core/static/description/index.html b/webservice_core/static/description/index.html
new file mode 100644
index 00000000..3e30e2e9
--- /dev/null
+++ b/webservice_core/static/description/index.html
@@ -0,0 +1,554 @@
+
+
+
+
+
+README.rst
+
+
+
+
+
+
+
+
+
+
+
WebService Core
+
+
+
This module provides the webservice.backend model with its
+authentication (public, username/password, API key) and HTTP call
+features (get /post /put /delete ).
+
It has no dependency on component or server_environment , so it
+can be used as a lightweight building block by any module needing to
+configure and call an outbound webservice, without pulling in extra
+frameworks.
+
On top of a backend, you can configure specific, named
+webservice.endpoint records via the UI, instead of only building
+calls in Python via webservice.backend.call(method, url_args, ...) .
+Each endpoint bundles a required description, a fixed HTTP method and
+relative path (appended to the backend URL), static headers, and an
+optional authentication override, fully independent from the backend’s.
+Endpoints are called with endpoint.call(...) ; calling the backend
+directly with backend.call(method, ...) remains fully supported.
+
Table of contents
+
+
+
+
Go to Settings > Technical > WebService Backend (requires the
+Administration / Settings group) and create a new backend:
+
+Name / Technical Name : a label and a unique technical key
+you’ll use to look the backend up from code (e.g. env.ref is not
+used here; search by tech_name instead).
+Protocol : only HTTP Request is available in this module.
+URL : the base URL every call is relative to, e.g.
+https://api.example.com . It may contain {placeholder} tokens
+(see Usage ), e.g. https://api.example.com/{endpoint} .
+Content-Type : optional default Content-Type header for every
+call.
+Timeout : optional timeout in seconds for the whole request
+(connect + read). Left empty, a call waits indefinitely.
+
+
Under the Headers and Querystring Params tabs you can configure
+static defaults, merged into every call (see Usage ). Flag a header or
+a querystring param as Secret when its value is a token, a key, …:
+the value is hidden in the UI and dropped when the database is
+neutralized.
+
Then configure authentication via Auth Type :
+
+Public : no credentials needed.
+Username & password : sent as HTTP Basic Auth. Requires
+Username and Password .
+API Key : sent as a custom header. Requires API Key and API
+Key header (the header name to send it under, e.g. X-Api-Key ).
+
+
Required fields depend on the selected auth type; the form only shows
+and requires the ones that apply, and saving enforces it.
+
Each webservice.endpoint (see Description ) has its own
+Content-Type, Timeout, Headers and Querystring Params, overriding the
+backend’s own for that specific endpoint - set only what needs to
+differ.
+
When a database is neutralized, the URL of the backends is replaced by a
+placeholder, and the stored credentials (username, password, API key) of
+backends and endpoints are cleared.
+
+
+
+
Look up the backend (e.g. by its technical name) and call it:
+
+backend = env [ "webservice.backend" ] . search ([( "tech_name" , "=" , "my_api" )])
+ result = backend . call ( "get" ) # -> the full requests.Response object
+
+
call(method, *args, **kwargs) accepts any of the standard HTTP verbs
+(get , post , put , delete ) and forwards everything else to
+requests , so any of its keyword
+arguments work too (data , json , params , files , …):
+
+backend . call ( "post" , data = b "<xml>...</xml>" )
+ backend . call ( "post" , json = { "foo" : "bar" })
+
+
URL : by default the backend’s own url is used. Pass url to
+hit a different path - relative paths are appended to the backend’s URL,
+a full http(s):// URL is used as-is:
+
+backend . call ( "get" , url = "orders" ) # -> <backend url>/orders
+ backend . call ( "get" , url = "https://other.example.com/orders" )
+
+
If the backend’s URL (or the url passed above) contains
+{placeholder} tokens, fill them with url_params :
+
+# backend.url == "https://api.example.com/{endpoint}"
+ backend . call ( "get" , url_params = { "endpoint" : "orders" })
+
+
Headers : pass headers to add/override headers for that call;
+they are merged on top of the backend’s own static headers (configured
+in the “Headers” tab), Content-Type and auth-derived headers (e.g.
+the API key header) - the headers kwarg wins on matching keys:
+
+backend . call ( "get" , headers = { "X-Request-Id" : "42" })
+
+
Querystring params : sent via requests ’ params= , not to be
+confused with url_params above, which fills {placeholder} tokens
+in the URL path itself. Configure static defaults in the “Querystring
+Params” tab - a value there may itself contain a {placeholder} ,
+resolved against the same url_params used for the URL. An explicit
+params kwarg passed to call() wins over the static configuration
+on matching keys:
+
+backend . call ( "get" , params = { "verbose" : "1" })
+
+
Auth override : pass auth to bypass the backend’s configured auth
+type for a single call (same format requests itself accepts, e.g. a
+(user, password) tuple):
+
+backend . call ( "get" , auth = ( "other_user" , "other_password" ))
+
+
Timeout : pass timeout to override the backend’s own configured
+timeout (in seconds) for a single call:
+
+backend . call ( "get" , timeout = 5 )
+
+
Response : call() always returns the full requests.Response
+object (status code, headers, content, …):
+
+response = backend . call ( "get" )
+ response . status_code
+ response . content
+
+
+
+
+
Bugs are tracked on GitHub Issues .
+In case of trouble, please check there if your issue has already been reported.
+If you spotted it first, help us to smash it by providing a detailed and welcomed
+feedback .
+
Do not contact contributors directly about support or help with technical issues.
+
+
+
+
+
+
+Creu Blanca
+Camptocamp
+
+
+
+
+
+
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.
+
Current maintainer :
+
+
This module is part of the OCA/web-api project on GitHub.
+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute .
+
+
+
+
+
+
diff --git a/webservice_core/tests/__init__.py b/webservice_core/tests/__init__.py
new file mode 100644
index 00000000..dfb7f117
--- /dev/null
+++ b/webservice_core/tests/__init__.py
@@ -0,0 +1,4 @@
+from . import test_neutralize
+from . import test_utils
+from . import test_webservice
+from . import test_webservice_endpoint
diff --git a/webservice_core/tests/common.py b/webservice_core/tests/common.py
new file mode 100644
index 00000000..b4658f1d
--- /dev/null
+++ b/webservice_core/tests/common.py
@@ -0,0 +1,38 @@
+# Copyright 2020 Creu Blanca
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from urllib.parse import urlparse
+
+from requests import PreparedRequest, Session
+
+from odoo.tests.common import TransactionCase, tagged
+
+
+@tagged("-at_install", "post_install")
+class CommonWebService(TransactionCase):
+ @classmethod
+ def _setup_context(cls):
+ return dict(
+ cls.env.context,
+ tracking_disable=True,
+ )
+
+ @classmethod
+ def _setup_env(cls):
+ cls.env = cls.env(context=cls._setup_context())
+
+ @classmethod
+ def _setup_records(cls):
+ pass
+
+ @classmethod
+ def setUpClass(cls):
+ cls._super_send = Session.send
+ super().setUpClass()
+ cls._setup_env()
+ cls._setup_records()
+
+ @classmethod
+ def _request_handler(cls, s: Session, r: PreparedRequest, /, **kw):
+ if urlparse(r.url).netloc in ("localhost.demo.odoo", "custom.url"):
+ return cls._super_send(s, r)
+ return super()._request_handler(s, r, **kw)
diff --git a/webservice_core/tests/test_neutralize.py b/webservice_core/tests/test_neutralize.py
new file mode 100644
index 00000000..d6c6ea41
--- /dev/null
+++ b/webservice_core/tests/test_neutralize.py
@@ -0,0 +1,193 @@
+# Copyright 2026 Camptocamp SA
+# @author Simone Orsi
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from odoo.modules import neutralize
+from odoo.tests.common import TransactionCase, tagged
+
+
+@tagged("post_install", "-at_install")
+class TestNeutralize(TransactionCase):
+ """Check the neutralization script on the raw database columns.
+
+ The script works at the SQL level, and modules like
+ `webservice_server_env` make the ORM read these fields from the
+ environment instead of the columns, so values are seeded and checked
+ with plain SQL.
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ cls.backend = cls.env["webservice.backend"].create(
+ {
+ "name": "Neutralize me",
+ "tech_name": "neutralize_me",
+ "protocol": "http",
+ "url": "https://production.example.com/api",
+ }
+ )
+ cls.env.flush_all()
+ cls.env.cr.execute(
+ """
+ UPDATE webservice_backend
+ SET url = %s, username = %s, password = %s, api_key = %s
+ WHERE id = %s
+ """,
+ (
+ "https://production.example.com/api",
+ "prod_user",
+ "prod_password",
+ "prod_api_key",
+ cls.backend.id,
+ ),
+ )
+ cls.endpoint = cls.env["webservice.endpoint"].create(
+ {
+ "name": "Neutralize my endpoint",
+ "tech_name": "neutralize_my_endpoint",
+ "description": "Endpoint with its own credentials",
+ "backend_id": cls.backend.id,
+ }
+ )
+ cls.env.flush_all()
+ cls.env.cr.execute(
+ """
+ UPDATE webservice_endpoint
+ SET username = %s, password = %s, api_key = %s
+ WHERE id = %s
+ """,
+ (
+ "prod_endpoint_user",
+ "prod_endpoint_password",
+ "prod_endpoint_api_key",
+ cls.endpoint.id,
+ ),
+ )
+ cls.public_param, cls.secret_param = cls.env[
+ "webservice.querystring.param"
+ ].create(
+ [
+ {
+ "res_model": cls.backend._name,
+ "res_id": cls.backend.id,
+ "name": "lang",
+ "value": "en",
+ },
+ {
+ "res_model": cls.backend._name,
+ "res_id": cls.backend.id,
+ "name": "token",
+ "value": "prod_token",
+ "secret": True,
+ },
+ ]
+ )
+ cls.public_header, cls.secret_header = cls.env["webservice.header"].create(
+ [
+ {
+ "res_model": cls.backend._name,
+ "res_id": cls.backend.id,
+ "name": "Accept-Language",
+ "value": "en",
+ },
+ {
+ "res_model": cls.backend._name,
+ "res_id": cls.backend.id,
+ "name": "X-Token",
+ "value": "prod_token",
+ "secret": True,
+ },
+ ]
+ )
+ cls.env.flush_all()
+
+ def _run_neutralize(self):
+ """Run the neutralization queries of the webservice_core module."""
+ for query in neutralize.get_neutralization_queries(["webservice_core"]):
+ self.env.cr.execute(query)
+
+ def _read_backend_row(self):
+ """Return the raw database values of the test backend."""
+ self.env.cr.execute(
+ """
+ SELECT name, url, username, password, api_key
+ FROM webservice_backend
+ WHERE id = %s
+ """,
+ (self.backend.id,),
+ )
+ return self.env.cr.dictfetchone()
+
+ def _read_endpoint_row(self):
+ """Return the raw database values of the test endpoint."""
+ self.env.cr.execute(
+ """
+ SELECT name, username, password, api_key
+ FROM webservice_endpoint
+ WHERE id = %s
+ """,
+ (self.endpoint.id,),
+ )
+ return self.env.cr.dictfetchone()
+
+ def _read_param_value(self, param):
+ """Return the raw database value of a querystring param."""
+ self.env.cr.execute(
+ "SELECT value FROM webservice_querystring_param WHERE id = %s",
+ (param.id,),
+ )
+ return self.env.cr.fetchone()[0]
+
+ def _read_header_value(self, header):
+ """Return the raw database value of a header."""
+ self.env.cr.execute(
+ "SELECT value FROM webservice_header WHERE id = %s", (header.id,)
+ )
+ return self.env.cr.fetchone()[0]
+
+ def test_neutralize_replaces_url(self):
+ """The production URL is replaced by a placeholder."""
+ self._run_neutralize()
+ self.assertEqual(self._read_backend_row()["url"], "https://neutralized.invalid")
+
+ def test_neutralize_clears_credentials(self):
+ """Username, password and API key of the backend are cleared."""
+ self._run_neutralize()
+ row = self._read_backend_row()
+ self.assertIsNone(row["username"])
+ self.assertIsNone(row["password"])
+ self.assertIsNone(row["api_key"])
+
+ def test_neutralize_clears_endpoint_credentials(self):
+ """Username, password and API key of the endpoint are cleared."""
+ self._run_neutralize()
+ row = self._read_endpoint_row()
+ self.assertIsNone(row["username"])
+ self.assertIsNone(row["password"])
+ self.assertIsNone(row["api_key"])
+ self.assertEqual(row["name"], "Neutralize my endpoint")
+
+ def test_neutralize_keeps_other_fields(self):
+ """Fields that are not endpoints or credentials are left untouched."""
+ self._run_neutralize()
+ self.assertEqual(self._read_backend_row()["name"], "Neutralize me")
+
+ def test_neutralize_replaces_secret_param_value(self):
+ """The value of a secret querystring param is replaced."""
+ self._run_neutralize()
+ self.assertEqual(self._read_param_value(self.secret_param), "neutralized")
+
+ def test_neutralize_keeps_public_param_value(self):
+ """The value of a non secret querystring param is left untouched."""
+ self._run_neutralize()
+ self.assertEqual(self._read_param_value(self.public_param), "en")
+
+ def test_neutralize_replaces_secret_header_value(self):
+ """The value of a secret header is replaced."""
+ self._run_neutralize()
+ self.assertEqual(self._read_header_value(self.secret_header), "neutralized")
+
+ def test_neutralize_keeps_public_header_value(self):
+ """The value of a non secret header is left untouched."""
+ self._run_neutralize()
+ self.assertEqual(self._read_header_value(self.public_header), "en")
diff --git a/webservice_core/tests/test_utils.py b/webservice_core/tests/test_utils.py
new file mode 100644
index 00000000..75a1a2ba
--- /dev/null
+++ b/webservice_core/tests/test_utils.py
@@ -0,0 +1,27 @@
+# Copyright 2023 Camptocamp SA
+# @author Simone Orsi
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+
+from odoo.tests.common import BaseCase
+
+from odoo.addons.webservice_core.utils import (
+ sanitize_url_for_log,
+ sanitize_values_for_log,
+)
+
+
+class TestUtils(BaseCase):
+ def test_url_cleanup(self):
+ url = "https://custom.url/?a=1&apikey=secret&password=moresecret"
+ self.assertEqual(sanitize_url_for_log(url), "https://custom.url/?a=1")
+
+ def test_values_cleanup(self):
+ """Secret and sensitive looking values are masked, the others kept."""
+ values = {"X-Token": "secret", "Password": "moresecret", "lang": "en"}
+ self.assertEqual(
+ sanitize_values_for_log(values, secret_keys={"x-token"}),
+ {"X-Token": "***", "Password": "***", "lang": "en"},
+ )
+ # the original values are left untouched
+ self.assertEqual(values["X-Token"], "secret")
diff --git a/webservice/tests/test_webservice.py b/webservice_core/tests/test_webservice.py
similarity index 57%
rename from webservice/tests/test_webservice.py
rename to webservice_core/tests/test_webservice.py
index 3c7fc312..73b66e85 100644
--- a/webservice/tests/test_webservice.py
+++ b/webservice_core/tests/test_webservice.py
@@ -3,11 +3,16 @@
# @author Simone Orsi
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from unittest import mock
+
+import psycopg2
import responses
from requests import auth
from requests import exceptions as http_exceptions
from odoo import exceptions
+from odoo.tests import Form
+from odoo.tools.misc import mute_logger
from .common import CommonWebService
@@ -29,6 +34,9 @@ def _setup_records(cls):
)
return res
+ def test_full_url_display(self):
+ self.assertEqual(self.webservice.full_url_display, self.url)
+
def test_web_service_not_found(self):
with self.assertRaises(http_exceptions.ConnectionError):
self.webservice.call("get")
@@ -83,7 +91,8 @@ def test_auth_validation(self):
def test_web_service_get(self):
responses.add(responses.GET, self.url, body="{}")
result = self.webservice.call("get")
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
+ self.assertEqual(result.status_code, 200)
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
@@ -94,7 +103,7 @@ def test_web_service_get_url_combine(self):
endpoint = "api/test"
responses.add(responses.GET, self.url + endpoint, body="{}")
result = self.webservice.call("get", url="api/test")
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
@@ -105,7 +114,7 @@ def test_web_service_get_url_combine_full_url(self):
endpoint = "api/test"
responses.add(responses.GET, self.url + endpoint, body="{}")
result = self.webservice.call("get", url="https://localhost.demo.odoo/api/test")
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
@@ -115,7 +124,7 @@ def test_web_service_get_url_combine_full_url(self):
def test_web_service_post(self):
responses.add(responses.POST, self.url, body="{}")
result = self.webservice.call("post", data="demo_response")
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
)
@@ -125,7 +134,7 @@ def test_web_service_post(self):
def test_web_service_put(self):
responses.add(responses.PUT, self.url, body="{}")
result = self.webservice.call("put", data="demo_response")
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
)
@@ -138,7 +147,7 @@ def test_web_service_backend_username(self):
)
responses.add(responses.GET, self.url, body="{}")
result = self.webservice.call("get")
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
@@ -153,7 +162,7 @@ def test_web_service_username(self):
)
responses.add(responses.GET, self.url, body="{}")
result = self.webservice.call("get", auth=("user2", "pass2"))
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
@@ -168,7 +177,7 @@ def test_web_service_backend_api_key(self):
)
responses.add(responses.POST, self.url, body="{}")
result = self.webservice.call("post")
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
@@ -179,7 +188,7 @@ def test_web_service_backend_api_key(self):
def test_web_service_headers(self):
responses.add(responses.GET, self.url, body="{}")
result = self.webservice.call("get", headers={"demo_header": "HEADER"})
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
@@ -193,7 +202,7 @@ def test_web_service_call_args(self):
result = self.webservice.call(
"post", url=url, headers={"demo_header": "HEADER"}
)
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
@@ -208,9 +217,137 @@ def test_web_service_call_args(self):
url_params={"endpoint": "custom/path"},
headers={"demo_header": "HEADER"},
)
- self.assertEqual(result, b"{}")
+ self.assertEqual(result.content, b"{}")
self.assertEqual(len(responses.calls), 2)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
)
self.assertEqual(responses.calls[0].request.headers["demo_header"], "HEADER")
+
+
+class TestWebServiceTechName(CommonWebService):
+ def test_tech_name_auto_generated_on_create(self):
+ backend = self.env["webservice.backend"].create(
+ {
+ "name": "Á weird nämë plenty of CR@P!",
+ "protocol": "http",
+ "url": "https://localhost.demo.odoo/",
+ "auth_type": "none",
+ }
+ )
+ self.assertEqual(backend.tech_name, "a_weird_name_plenty_of_cr_p")
+
+ def test_tech_name_kept_if_already_set_on_create(self):
+ backend = self.env["webservice.backend"].create(
+ {
+ "name": "WebService",
+ "tech_name": "custom_tech_name",
+ "protocol": "http",
+ "url": "https://localhost.demo.odoo/",
+ "auth_type": "none",
+ }
+ )
+ self.assertEqual(backend.tech_name, "custom_tech_name")
+
+ def test_tech_name_kept_if_write_does_not_touch_name(self):
+ backend = self.env["webservice.backend"].create(
+ {
+ "name": "WebService",
+ "tech_name": "custom_tech_name",
+ "protocol": "http",
+ "url": "https://localhost.demo.odoo/",
+ "auth_type": "none",
+ }
+ )
+ backend.write({"url": "https://other.demo.odoo/"})
+ self.assertEqual(backend.tech_name, "custom_tech_name")
+
+ def test_tech_name_regenerated_on_write_when_name_changes_without_tech_name(self):
+ backend = self.env["webservice.backend"].create(
+ {
+ "name": "WebService",
+ "tech_name": "custom_tech_name",
+ "protocol": "http",
+ "url": "https://localhost.demo.odoo/",
+ "auth_type": "none",
+ }
+ )
+ # Mirrors server_env_tech_name_mixin: `_handle_tech_name` only looks
+ # at the vals of the current write, not at the record's current
+ # value, so omitting `tech_name` while changing `name` regenerates it.
+ backend.write({"name": "WebService renamed"})
+ self.assertEqual(backend.tech_name, "webservice_renamed")
+
+ @mute_logger("odoo.sql_db")
+ def test_tech_name_uniq(self):
+ self.env["webservice.backend"].create(
+ {
+ "name": "WebService",
+ "tech_name": "dup_tech_name",
+ "protocol": "http",
+ "url": "https://localhost.demo.odoo/",
+ "auth_type": "none",
+ }
+ )
+ with self.assertRaises(psycopg2.IntegrityError):
+ self.env["webservice.backend"].create(
+ {
+ "name": "WebService 2",
+ "tech_name": "dup_tech_name",
+ "protocol": "http",
+ "url": "https://localhost.demo.odoo/",
+ "auth_type": "none",
+ }
+ )
+
+ def test_tech_name_onchange(self):
+ form = Form(self.env["webservice.backend"])
+ form.name = "Á weird nämë plenty of CR@P!"
+ form.protocol = "http"
+ form.url = "https://localhost.demo.odoo/"
+ form.auth_type = "none"
+ # tech name auto generated and normalized
+ self.assertEqual(form.tech_name, "a_weird_name_plenty_of_cr_p")
+ form.tech_name = "better name"
+ # tech name normalized on change too
+ self.assertEqual(form.tech_name, "better_name")
+ form.name = "WebService renamed"
+ # name changes no longer affect tech_name once it's set
+ self.assertEqual(form.tech_name, "better_name")
+
+
+class TestWebServiceTimeout(CommonWebService):
+ @classmethod
+ def _setup_records(cls):
+ res = super()._setup_records()
+ cls.webservice = cls.env["webservice.backend"].create(
+ {
+ "name": "WebService",
+ "protocol": "http",
+ "url": "https://localhost.demo.odoo/",
+ "tech_name": "demo_ws_timeout",
+ "auth_type": "none",
+ }
+ )
+ return res
+
+ def _get_requests_timeout(self, mocked_request):
+ self.assertEqual(mocked_request.call_count, 1)
+ return mocked_request.call_args.kwargs["timeout"]
+
+ def test_timeout_unset_by_default(self):
+ with mock.patch("requests.request") as mocked_request:
+ self.webservice.call("get")
+ self.assertIsNone(self._get_requests_timeout(mocked_request))
+
+ def test_timeout_from_backend(self):
+ self.webservice.timeout = 5.0
+ with mock.patch("requests.request") as mocked_request:
+ self.webservice.call("get")
+ self.assertEqual(self._get_requests_timeout(mocked_request), 5.0)
+
+ def test_timeout_call_kwarg_overrides_backend(self):
+ self.webservice.timeout = 5.0
+ with mock.patch("requests.request") as mocked_request:
+ self.webservice.call("get", timeout=1.5)
+ self.assertEqual(self._get_requests_timeout(mocked_request), 1.5)
diff --git a/webservice_core/tests/test_webservice_endpoint.py b/webservice_core/tests/test_webservice_endpoint.py
new file mode 100644
index 00000000..8b1f62b6
--- /dev/null
+++ b/webservice_core/tests/test_webservice_endpoint.py
@@ -0,0 +1,329 @@
+# Copyright 2026 Camptocamp SA
+# @author Simone Orsi
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from unittest import mock
+
+import responses
+from psycopg2 import errors as pg_errors
+
+from odoo import Command, exceptions
+from odoo.tests.common import tagged
+from odoo.tools import mute_logger
+
+from .common import CommonWebService
+
+
+@tagged("-at_install", "post_install")
+class TestWebserviceEndpoint(CommonWebService):
+ @classmethod
+ def _setup_records(cls):
+ res = super()._setup_records()
+ cls.url = "https://localhost.demo.odoo/"
+ cls.backend = cls.env["webservice.backend"].create(
+ {
+ "name": "WebService",
+ "protocol": "http",
+ "url": cls.url,
+ "content_type": "application/xml",
+ "tech_name": "demo_ws",
+ "auth_type": "api_key",
+ "api_key": "backend-key",
+ "api_key_header": "Api-Key",
+ }
+ )
+ cls.endpoint = cls.env["webservice.endpoint"].create(
+ {
+ "name": "Get Order Status",
+ "tech_name": "get_order_status",
+ "description": "Retrieve the status of an order",
+ "backend_id": cls.backend.id,
+ "http_method": "get",
+ "path": "orders/{order_id}/status",
+ }
+ )
+ return res
+
+ def test_tech_name_unique_per_backend(self):
+ with (
+ mute_logger("odoo.sql_db"),
+ self.assertRaises(pg_errors.UniqueViolation),
+ self.cr.savepoint(),
+ ):
+ self.env["webservice.endpoint"].create(
+ {
+ "name": "Duplicate",
+ "tech_name": "get_order_status",
+ "description": "Duplicate tech_name on the same backend",
+ "backend_id": self.backend.id,
+ "http_method": "post",
+ }
+ )
+
+ def test_tech_name_unique_across_backends_ok(self):
+ other_backend = self.backend.copy({"tech_name": "demo_ws_2"})
+ # Same ``tech_name`` on a different backend is allowed.
+ endpoint = self.env["webservice.endpoint"].create(
+ {
+ "name": "Get Order Status",
+ "tech_name": "get_order_status",
+ "description": "Same tech_name, different backend",
+ "backend_id": other_backend.id,
+ "http_method": "get",
+ }
+ )
+ self.assertTrue(endpoint)
+
+ def test_override_auth_requires_auth_type(self):
+ with self.assertRaises(exceptions.UserError):
+ self.endpoint.write({"override_auth": True})
+
+ @responses.activate
+ def test_call_delegates_to_backend_auth(self):
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ result = self.endpoint.call(url_params={"order_id": 42})
+ self.assertEqual(result.content, b"{}")
+ self.assertEqual(len(responses.calls), 1)
+ # No override: the backend's own API key is used.
+ self.assertEqual(responses.calls[0].request.headers["Api-Key"], "backend-key")
+ self.assertEqual(
+ responses.calls[0].request.headers["Content-Type"], "application/xml"
+ )
+
+ @responses.activate
+ def test_call_with_override_auth_uses_own_credentials(self):
+ self.endpoint.write(
+ {
+ "override_auth": True,
+ "auth_type": "api_key",
+ "api_key": "endpoint-key",
+ "api_key_header": "Api-Key",
+ "content_type": "application/json",
+ }
+ )
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ result = self.endpoint.call(url_params={"order_id": 42})
+ self.assertEqual(result.content, b"{}")
+ self.assertEqual(len(responses.calls), 1)
+ self.assertEqual(responses.calls[0].request.headers["Api-Key"], "endpoint-key")
+ self.assertEqual(
+ responses.calls[0].request.headers["Content-Type"], "application/json"
+ )
+
+ @responses.activate
+ def test_call_merges_static_headers(self):
+ self.endpoint.write(
+ {"header_ids": [(0, 0, {"name": "X-Demo", "value": "demo-value"})]}
+ )
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ self.endpoint.call(url_params={"order_id": 42})
+ self.assertEqual(responses.calls[0].request.headers["X-Demo"], "demo-value")
+
+ @responses.activate
+ def test_call_headers_override_static_headers(self):
+ self.endpoint.write(
+ {"header_ids": [(0, 0, {"name": "X-Demo", "value": "demo-value"})]}
+ )
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ self.endpoint.call(
+ url_params={"order_id": 42}, headers={"X-Demo": "call-time-value"}
+ )
+ self.assertEqual(
+ responses.calls[0].request.headers["X-Demo"], "call-time-value"
+ )
+
+ @responses.activate
+ def test_call_sends_default_querystring_params(self):
+ self.endpoint.write(
+ {"querystring_param_ids": [(0, 0, {"name": "verbose", "value": "1"})]}
+ )
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ self.endpoint.call(url_params={"order_id": 42})
+ self.assertIn("verbose=1", responses.calls[0].request.url)
+
+ @responses.activate
+ def test_call_params_kwarg_overrides_default(self):
+ self.endpoint.write(
+ {"querystring_param_ids": [(0, 0, {"name": "verbose", "value": "1"})]}
+ )
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ self.endpoint.call(url_params={"order_id": 42}, params={"verbose": "0"})
+ self.assertIn("verbose=0", responses.calls[0].request.url)
+
+ @responses.activate
+ def test_call_querystring_param_value_placeholder_resolved(self):
+ # A configured querystring param value may itself contain a
+ # `{placeholder}`, resolved against the same `url_params` used for
+ # the URL path.
+ self.endpoint.write(
+ {
+ "querystring_param_ids": [
+ (0, 0, {"name": "ref", "value": "order-{order_id}"})
+ ]
+ }
+ )
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ self.endpoint.call(url_params={"order_id": 42})
+ self.assertIn("ref=order-42", responses.calls[0].request.url)
+
+ @responses.activate
+ def test_call_merges_backend_and_endpoint_headers_endpoint_wins(self):
+ self.backend.write(
+ {"header_ids": [(0, 0, {"name": "X-Demo", "value": "backend-value"})]}
+ )
+ self.endpoint.write(
+ {"header_ids": [(0, 0, {"name": "X-Demo", "value": "endpoint-value"})]}
+ )
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ self.endpoint.call(url_params={"order_id": 42})
+ self.assertEqual(responses.calls[0].request.headers["X-Demo"], "endpoint-value")
+
+ @responses.activate
+ def test_call_inherits_backend_headers_when_endpoint_has_none(self):
+ self.backend.write(
+ {"header_ids": [(0, 0, {"name": "X-Backend", "value": "backend-value"})]}
+ )
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ self.endpoint.call(url_params={"order_id": 42})
+ self.assertEqual(
+ responses.calls[0].request.headers["X-Backend"], "backend-value"
+ )
+
+ @responses.activate
+ def test_backend_call_uses_own_header_and_querystring_param_defaults(self):
+ self.backend.write(
+ {
+ "header_ids": [(0, 0, {"name": "X-Backend", "value": "1"})],
+ "querystring_param_ids": [(0, 0, {"name": "verbose", "value": "1"})],
+ }
+ )
+ responses.add(responses.GET, self.url, body="{}")
+ self.backend.call("get")
+ self.assertEqual(responses.calls[0].request.headers["X-Backend"], "1")
+ self.assertIn("verbose=1", responses.calls[0].request.url)
+
+ @responses.activate
+ def test_call_does_not_log_secret_values(self):
+ """Secret header and param values are masked in the call log."""
+ # One record per side keeps the logged order stable:
+ # backend values first, updated with the endpoint ones.
+ self.backend.write(
+ {
+ "header_ids": [
+ Command.create(
+ {"name": "X-Backend-Token", "value": "b-s3cr3t", "secret": True}
+ )
+ ],
+ "querystring_param_ids": [
+ Command.create({"name": "verbose", "value": "1"})
+ ],
+ }
+ )
+ self.endpoint.write(
+ {
+ "header_ids": [
+ Command.create(
+ {"name": "X-Token", "value": "e-s3cr3t", "secret": True}
+ )
+ ],
+ "querystring_param_ids": [
+ Command.create(
+ {"name": "token", "value": "p-s3cr3t", "secret": True}
+ )
+ ],
+ }
+ )
+ url = f"{self.url}orders/42/status"
+ responses.add(responses.GET, url, body="{}")
+ with self.assertLogs(
+ "odoo.addons.webservice_core.models.webservice_request_mixin", "DEBUG"
+ ) as logs:
+ self.endpoint.call(url_params={"order_id": 42})
+ logger = "odoo.addons.webservice_core.models.webservice_request_mixin"
+ self.assertEqual(
+ logs.output,
+ [
+ f"DEBUG:{logger}:WebService: call get () "
+ "{'url': 'orders/{order_id}/status', 'url_params': {'order_id': 42}, "
+ "'content_type': 'application/xml', "
+ "'headers': {'X-Backend-Token': '***', 'X-Token': '***'}, "
+ "'params': {'verbose': '1', 'token': '***'}}",
+ f"INFO:{logger}:get call to "
+ "https://localhost.demo.odoo/orders/42/status",
+ f"DEBUG:{logger}:WebService: response: \n",
+ ],
+ )
+ # the actual request still gets the secret values
+ request = responses.calls[0].request
+ self.assertEqual(request.headers["X-Backend-Token"], "b-s3cr3t")
+ self.assertEqual(request.headers["X-Token"], "e-s3cr3t")
+ self.assertIn("token=p-s3cr3t", request.url)
+
+ def test_header_line_gets_res_model_and_res_id_set(self):
+ self.backend.write({"header_ids": [(0, 0, {"name": "X", "value": "1"})]})
+ line = self.backend.header_ids
+ self.assertEqual(line.res_model, "webservice.backend")
+ self.assertEqual(line.res_id, self.backend.id)
+
+ def test_display_name_default(self):
+ self.assertEqual(self.endpoint.display_name, "Get Order Status")
+
+ def test_display_name_with_path_via_context(self):
+ endpoint = self.endpoint.with_context(webservice_endpoint_display_path=1)
+ self.assertEqual(
+ endpoint.display_name, "Get Order Status (orders/{order_id}/status)"
+ )
+
+ def test_display_name_with_path_via_context_no_path(self):
+ endpoint = self.endpoint.copy({"tech_name": "no_path", "path": False})
+ endpoint = endpoint.with_context(webservice_endpoint_display_path=1)
+ self.assertEqual(endpoint.display_name, "Get Order Status")
+
+ def _get_requests_timeout(self, mocked_request):
+ self.assertEqual(mocked_request.call_count, 1)
+ return mocked_request.call_args.kwargs["timeout"]
+
+ def test_timeout_endpoint_inherits_backend(self):
+ self.backend.timeout = 5.0
+ with mock.patch("requests.request") as mocked_request:
+ self.endpoint.call(url_params={"order_id": 42})
+ self.assertEqual(self._get_requests_timeout(mocked_request), 5.0)
+
+ def test_timeout_endpoint_overrides_backend(self):
+ self.backend.timeout = 5.0
+ self.endpoint.timeout = 2.5
+ with mock.patch("requests.request") as mocked_request:
+ self.endpoint.call(url_params={"order_id": 42})
+ self.assertEqual(self._get_requests_timeout(mocked_request), 2.5)
+
+ def test_timeout_call_kwarg_overrides_endpoint(self):
+ self.backend.timeout = 5.0
+ self.endpoint.timeout = 2.5
+ with mock.patch("requests.request") as mocked_request:
+ self.endpoint.call(url_params={"order_id": 42}, timeout=1.0)
+ self.assertEqual(self._get_requests_timeout(mocked_request), 1.0)
+
+ def test_full_url_display(self):
+ # `path` has an unresolved `{order_id}` placeholder: left as-is.
+ self.assertEqual(
+ self.endpoint.full_url_display, f"{self.url}orders/{{order_id}}/status"
+ )
+
+ def test_full_url_display_no_path(self):
+ endpoint = self.endpoint.copy({"tech_name": "no_path", "path": False})
+ self.assertEqual(endpoint.full_url_display, self.url)
+
+ def test_full_url_display_updates_with_backend_url(self):
+ self.backend.url = "https://other.demo.odoo/"
+ self.assertEqual(
+ self.endpoint.full_url_display,
+ "https://other.demo.odoo/orders/{order_id}/status",
+ )
diff --git a/webservice/utils.py b/webservice_core/utils.py
similarity index 56%
rename from webservice/utils.py
rename to webservice_core/utils.py
index 1e2aa931..202a0307 100644
--- a/webservice/utils.py
+++ b/webservice_core/utils.py
@@ -26,21 +26,37 @@ def __call__(self, request):
return request
+DEFAULT_BLACKLISTED_KEYS = ("apikey", "password", "pwd")
+
+
+def is_blacklisted_key(key, blacklisted_keys=None):
+ """Tell if a key looks sensitive, comparing case insensitively."""
+ blacklisted_keys = blacklisted_keys or DEFAULT_BLACKLISTED_KEYS
+ return any(bl_key.lower() in key.lower() for bl_key in blacklisted_keys)
+
+
def sanitize_url_for_log(url, blacklisted_keys=None):
"""Sanitize url to avoid loggin sensitive data"""
- blacklisted_keys = blacklisted_keys or ("apikey", "password", "pwd")
parsed = urlparse(url)
query = parse_qs(parsed.query, keep_blank_values=False)
- clean_query = {}
+ clean_query = {
+ k: v for k, v in query.items() if not is_blacklisted_key(k, blacklisted_keys)
+ }
+ parsed = parsed._replace(query=urlencode(clean_query, True))
+ return urlunparse(parsed)
- def is_blacklisted(k):
- for bl_key in blacklisted_keys:
- if bl_key.lower() in k.lower():
- return True
- for k, v in query.items():
- if not is_blacklisted(k):
- clean_query[k] = v
+def sanitize_values_for_log(values, secret_keys=(), blacklisted_keys=None):
+ """Return a copy of `values` (e.g. headers) safe to log.
- parsed = parsed._replace(query=urlencode(clean_query, True))
- return urlunparse(parsed)
+ The values of the `secret_keys` and of the keys looking sensitive
+ (see `is_blacklisted_key`) are masked. Keys are compared case
+ insensitively.
+ """
+ secret_keys = {k.lower() for k in secret_keys}
+ return {
+ k: "***"
+ if k.lower() in secret_keys or is_blacklisted_key(k, blacklisted_keys)
+ else v
+ for k, v in values.items()
+ }
diff --git a/webservice_core/views/webservice_backend.xml b/webservice_core/views/webservice_backend.xml
new file mode 100644
index 00000000..6c8b8e48
--- /dev/null
+++ b/webservice_core/views/webservice_backend.xml
@@ -0,0 +1,190 @@
+
+
+
+
+ webservice.backend.form (in webservice_core)
+ webservice.backend
+
+
+
+
+
+
+ webservice.backend.search (in webservice_core)
+ webservice.backend
+
+
+
+
+
+
+
+
+
+
+
+ webservice.backend.tree (in webservice_core)
+ webservice.backend
+
+
+
+
+
+
+
+
+
+
+
+
+ WebService Backend
+ webservice.backend
+ list,form
+ []
+ {}
+
+
+
+
diff --git a/webservice_core/views/webservice_endpoint.xml b/webservice_core/views/webservice_endpoint.xml
new file mode 100644
index 00000000..7cbd42b5
--- /dev/null
+++ b/webservice_core/views/webservice_endpoint.xml
@@ -0,0 +1,197 @@
+
+
+
+
+ webservice.endpoint.form (in webservice_core)
+ webservice.endpoint
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ webservice.endpoint.search (in webservice_core)
+ webservice.endpoint
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ webservice.endpoint.tree (in webservice_core)
+ webservice.endpoint
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ WebService Endpoint
+ webservice.endpoint
+ list,form
+ []
+ {}
+
+
+
+
diff --git a/webservice_server_env/models/webservice_backend.py b/webservice_server_env/models/webservice_backend.py
index 8e9eae88..a11889a4 100644
--- a/webservice_server_env/models/webservice_backend.py
+++ b/webservice_server_env/models/webservice_backend.py
@@ -4,6 +4,9 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
+from odoo.tools import mute_logger
+
+from odoo.addons.server_environment.models.server_env_mixin import _partialmethod
class WebserviceBackend(models.Model):
@@ -37,9 +40,31 @@ def _server_env_fields(self):
webservice_fields.update(base_fields)
return webservice_fields
- def _compute_server_env(self):
- # OVERRIDE: reset ``oauth2_flow`` when ``auth_type`` is not "oauth2", even if
- # defined otherwise in server env vars
- res = super()._compute_server_env()
- self.filtered(lambda r: r.auth_type != "oauth2").oauth2_flow = None
+ def _server_env_transform_field_to_read_from_env(self, field):
+ # OVERRIDE: give each env-managed field its own compute method. With the
+ # shared ``_compute_server_env``, Odoo groups them all together: writing
+ # one protects the others, and those not cached yet read as False
+ # (e.g. ``auth_type`` in the OAuth2 constraints when writing
+ # ``oauth2_client_auth_method``).
+ res = super()._server_env_transform_field_to_read_from_env(field)
+ compute_name = f"_compute_server_env_{field.name}"
+ compute_method = _partialmethod(
+ type(self)._compute_server_env_field, field.name, __name__=compute_name
+ )
+ # Mute message related to new safeguard (PR odoo/odoo#247151)
+ with mute_logger("odoo.tests.common"):
+ setattr(type(self), compute_name, compute_method)
+ field.compute = compute_name
return res
+
+ def _compute_server_env_field(self, field_name):
+ options = self._server_env_fields[field_name]
+ for record in self:
+ if record._server_env_has_key_defined(field_name):
+ record._compute_server_env_from_config(field_name, options)
+ else:
+ record._compute_server_env_from_default(field_name, options)
+ if field_name == "oauth2_flow":
+ # reset ``oauth2_flow`` when ``auth_type`` is not "oauth2", even if
+ # defined otherwise in server env vars
+ self.filtered(lambda r: r.auth_type != "oauth2").oauth2_flow = None