diff --git a/auth_api_key_server_env/README.rst b/auth_api_key_server_env/README.rst new file mode 100644 index 0000000000..11e0b47803 --- /dev/null +++ b/auth_api_key_server_env/README.rst @@ -0,0 +1,94 @@ +=============================== +Auth API key server environment +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e6609698db2b7ba4cab3f9aa8cfca5e51a1418bbf74c8bd802b9bce9be8c54a9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github + :target: https://github.com/OCA/server-auth/tree/18.0/auth_api_key_server_env + :alt: OCA/server-auth +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-auth-18-0/server-auth-18-0-auth_api_key_server_env + :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/server-auth&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Configure api keys via server env. + +This can be very useful to avoid mixing your keys between your various +environments when restoring databases. All you have to do is to add a +new section to your configuration file according to the following +convention: + +.. code:: ini + + [api_key_] + key=my_api_key + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Camptocamp + +Contributors +------------ + +- Simone Orsi +- Florian da Costa +- Thien Vo Hong + +Other credits +------------- + +The migration of this module from 17.0 to 18.0 was financially supported +by Camptocamp. + +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. + +This module is part of the `OCA/server-auth `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/auth_api_key_server_env/__init__.py b/auth_api_key_server_env/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/auth_api_key_server_env/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/auth_api_key_server_env/__manifest__.py b/auth_api_key_server_env/__manifest__.py new file mode 100644 index 0000000000..c81ff89a49 --- /dev/null +++ b/auth_api_key_server_env/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2021 Camptocamp SA +# @author: Simone Orsi +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Auth API key server environment", + "summary": """ +Configure api keys via server env. + +This can be very useful to avoid mixing your keys between your various +environments when restoring databases. All you have to do is to add a new +section to your configuration file according to the following convention: + """, + "version": "18.0.1.0.0", + "development_status": "Production/Stable", + "license": "LGPL-3", + "website": "https://github.com/OCA/server-auth", + "author": "Camptocamp,Odoo Community Association (OCA)", + "depends": ["auth_api_key", "server_environment"], + "data": [], +} diff --git a/auth_api_key_server_env/i18n/auth_api_key_server_env.pot b/auth_api_key_server_env/i18n/auth_api_key_server_env.pot new file mode 100644 index 0000000000..d8a75c2c29 --- /dev/null +++ b/auth_api_key_server_env/i18n/auth_api_key_server_env.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * auth_api_key_server_env +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.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: auth_api_key_server_env +#: model:ir.model,name:auth_api_key_server_env.model_auth_api_key +msgid "API Key" +msgstr "" + +#. module: auth_api_key_server_env +#: model:ir.model.fields,field_description:auth_api_key_server_env.field_auth_api_key__server_env_defaults +msgid "Server Env Defaults" +msgstr "" + +#. module: auth_api_key_server_env +#: model:ir.model.fields,field_description:auth_api_key_server_env.field_auth_api_key__tech_name +msgid "Tech Name" +msgstr "" + +#. module: auth_api_key_server_env +#: model:ir.model.fields,help:auth_api_key_server_env.field_auth_api_key__tech_name +msgid "Unique name for technical purposes. Eg: server env keys." +msgstr "" diff --git a/auth_api_key_server_env/i18n/it.po b/auth_api_key_server_env/i18n/it.po new file mode 100644 index 0000000000..81dba352b5 --- /dev/null +++ b/auth_api_key_server_env/i18n/it.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * auth_api_key_server_env +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-04 22:36+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 4.17\n" + +#. module: auth_api_key_server_env +#: model:ir.model,name:auth_api_key_server_env.model_auth_api_key +msgid "API Key" +msgstr "Chiave API" + +#. module: auth_api_key_server_env +#: model:ir.model.fields,field_description:auth_api_key_server_env.field_auth_api_key__server_env_defaults +msgid "Server Env Defaults" +msgstr "Server ambiente predefinito" + +#. module: auth_api_key_server_env +#: model:ir.model.fields,field_description:auth_api_key_server_env.field_auth_api_key__tech_name +msgid "Tech Name" +msgstr "Nome tecnico" + +#. module: auth_api_key_server_env +#: model:ir.model.fields,help:auth_api_key_server_env.field_auth_api_key__tech_name +msgid "Unique name for technical purposes. Eg: server env keys." +msgstr "Nome univoco per motivi tecnici. Es: chiavi server ambiente." diff --git a/auth_api_key_server_env/models/__init__.py b/auth_api_key_server_env/models/__init__.py new file mode 100644 index 0000000000..6dfe3f790b --- /dev/null +++ b/auth_api_key_server_env/models/__init__.py @@ -0,0 +1 @@ +from . import auth_api_key diff --git a/auth_api_key_server_env/models/auth_api_key.py b/auth_api_key_server_env/models/auth_api_key.py new file mode 100644 index 0000000000..64db93d4e8 --- /dev/null +++ b/auth_api_key_server_env/models/auth_api_key.py @@ -0,0 +1,29 @@ +# Copyright 2018 ACSONE SA/NV +# Copyright 2021 Camptocamp SA +# @author: Simone Orsi +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + + +from odoo import models + + +class AuthApiKey(models.Model): + _name = "auth.api.key" + _inherit = ["auth.api.key", "server.env.techname.mixin", "server.env.mixin"] + + def _server_env_section_name(self): + """Name of the section in the configuration files + We override the default implementation to keep the compatibility + with the previous implementation of auth_api_key. The section name + into the configuration file must be formatted as + 'api_key_{name}' + """ + self.ensure_one() + return f"api_key_{getattr(self, self._server_env_section_name_field)}" + + @property + def _server_env_fields(self): + base_fields = super()._server_env_fields + api_key_fields = {"key": {}} + api_key_fields.update(base_fields) + return api_key_fields diff --git a/auth_api_key_server_env/pyproject.toml b/auth_api_key_server_env/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/auth_api_key_server_env/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/auth_api_key_server_env/readme/CONTRIBUTORS.md b/auth_api_key_server_env/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..28d0ec9385 --- /dev/null +++ b/auth_api_key_server_env/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Simone Orsi \<\> +- Florian da Costa \<\> +- Thien Vo Hong \<\> diff --git a/auth_api_key_server_env/readme/CREDITS.md b/auth_api_key_server_env/readme/CREDITS.md new file mode 100644 index 0000000000..83b3ec91f7 --- /dev/null +++ b/auth_api_key_server_env/readme/CREDITS.md @@ -0,0 +1 @@ +The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp. diff --git a/auth_api_key_server_env/readme/DESCRIPTION.md b/auth_api_key_server_env/readme/DESCRIPTION.md new file mode 100644 index 0000000000..fd3f7ddf12 --- /dev/null +++ b/auth_api_key_server_env/readme/DESCRIPTION.md @@ -0,0 +1,11 @@ +Configure api keys via server env. + +This can be very useful to avoid mixing your keys between your various +environments when restoring databases. All you have to do is to add a +new section to your configuration file according to the following +convention: + +``` ini +[api_key_] +key=my_api_key +``` diff --git a/auth_api_key_server_env/static/description/icon.png b/auth_api_key_server_env/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/auth_api_key_server_env/static/description/icon.png differ diff --git a/auth_api_key_server_env/static/description/index.html b/auth_api_key_server_env/static/description/index.html new file mode 100644 index 0000000000..a27a17f60a --- /dev/null +++ b/auth_api_key_server_env/static/description/index.html @@ -0,0 +1,439 @@ + + + + + +Auth API key server environment + + + +
+

Auth API key server environment

+ + +

Production/Stable License: LGPL-3 OCA/server-auth Translate me on Weblate Try me on Runboat

+

Configure api keys via server env.

+

This can be very useful to avoid mixing your keys between your various +environments when restoring databases. All you have to do is to add a +new section to your configuration file according to the following +convention:

+
+[api_key_<record.tech_name>]
+key=my_api_key
+
+

Table of contents

+ +
+

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

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 17.0 to 18.0 was financially supported +by Camptocamp.

+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

This module is part of the OCA/server-auth project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/auth_api_key_server_env/tests/__init__.py b/auth_api_key_server_env/tests/__init__.py new file mode 100644 index 0000000000..56e3e32a3a --- /dev/null +++ b/auth_api_key_server_env/tests/__init__.py @@ -0,0 +1 @@ +from . import test_auth_api_key diff --git a/auth_api_key_server_env/tests/test_auth_api_key.py b/auth_api_key_server_env/tests/test_auth_api_key.py new file mode 100644 index 0000000000..1444349a79 --- /dev/null +++ b/auth_api_key_server_env/tests/test_auth_api_key.py @@ -0,0 +1,37 @@ +# Copyright 2018 ACSONE SA/NV +# Copyright 2021 Camptocamp SA +# @author: Simone Orsi +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + +from odoo.addons.server_environment import serv_config + + +class TestAuthApiKey(TransactionCase): + @classmethod + def setUpClass(cls, *args, **kwargs): + super().setUpClass(*args, **kwargs) + cls.AuthApiKey = cls.env["auth.api.key"] + cls.demo_user = cls.env.ref("base.user_demo") + cls.api_key_from_env = cls.AuthApiKey.create( + { + "name": "From Env", + "key": "dummy", + "user_id": cls.demo_user.id, + "tech_name": "test_env", + } + ) + cls.api_key_from_env.invalidate_recordset() + serv_config.add_section("api_key_test_env") + serv_config.set("api_key_test_env", "key", "api_key_from_env") + + def test_lookup_key_from_env(self): + self.assertEqual( + self.env["auth.api.key"]._retrieve_uid_from_api_key("api_key_from_env"), + self.demo_user.id, + ) + with self.assertRaises(ValidationError): + # dummy key must be replace with the one from env and + # therefore should be unusable + self.env["auth.api.key"]._retrieve_uid_from_api_key("dummy")