Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .oca/oca-port/blacklist/server_environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pull_requests": {
"OCA/server-env#176": "(auto) Nothing to port from PR #176",
"OCA/server-env#190": "(auto) Nothing to port from PR #190"
}
}
17 changes: 10 additions & 7 deletions server_environment/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

======================================
server configuration environment files
======================================
Expand All @@ -11,13 +7,13 @@ server configuration environment files
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:39cd61c3a9621d0b7ee7a346adf45f4a2c90e80e6a61e18f182386c6fc90fd19
!! source digest: sha256:dcc784d558683190d604281faea315ff44a3c8ffe998f31f749b06e4def888e1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-LGPL--3-blue.png
.. |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--env-lightgray.png?logo=github
Expand All @@ -40,7 +36,7 @@ are stored in the ``server_environment_files`` companion module.

The ``server_environment_files`` module is optional, the values can be
set using an environment variable with a fallback on default values in
the database.
the database. you will be able to overwrite some odoo options.

The configuration read from the files are visible under the
Configuration menu. If you are not in the 'dev' environment you will not
Expand Down Expand Up @@ -106,6 +102,13 @@ example:
can override or extend default values;
- you can override or extend values in the main configuration file of
your instance;
- In some platforms (like odoo.sh where production config file is copied
to staging) it can be useful to overwrite options written in the
``[options]`` section. You must allow the override by adding
``server_environment_allow_overwrite_options_section = True`` to the
former ``odoo.cfg`` config file or through the environment variable:
``export SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION=True`` (if
both are set config file takes precedence).

Environment variable
--------------------
Expand Down
7 changes: 7 additions & 0 deletions server_environment/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ addon. The `server_environment_files_sample` can be used as an example:
can override or extend default values;
- you can override or extend values in the main configuration file of
your instance;
- In some platforms (like odoo.sh where production config file is copied to staging)
it can be useful to overwrite options written in the `[options]` section. You must
allow the override by adding `server_environment_allow_overwrite_options_section = True`
to the former `odoo.cfg` config file or through the environment variable:
`export SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION=True` (if both are set
config file takes precedence).


## Environment variable

Expand Down
4 changes: 2 additions & 2 deletions server_environment/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ configuration file, and the values for the various possible environments
are stored in the `server_environment_files` companion module.

The `server_environment_files` module is optional, the values can be set
using an environment variable with a fallback on default values in the
database.
using an environment variable with a fallback on default values in the database. you
will be able to overwrite some odoo options.

The configuration read from the files are visible under the
Configuration menu. If you are not in the 'dev' environment you will not
Expand Down
14 changes: 14 additions & 0 deletions server_environment/server_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ def _listconf(env_path):
return files


def _update_odoo_config_options(config_p):
allow_overwrite = system_base_config.get(
"server_environment_allow_overwrite_options_section",
os.environ.get("SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION"),
)
if isinstance(allow_overwrite, str) and allow_overwrite:
allow_overwrite = _boolean_states.get(allow_overwrite.lower(), False)
if allow_overwrite and config_p.has_section("options"):
system_base_config.options.update(
{k: v for k, v in config_p["options"].items()}
)


def _load_config_from_server_env_files(config_p):
default = os.path.join(_dir, "default")
running_env = os.path.join(_dir, system_base_config["running_env"])
Expand All @@ -119,6 +132,7 @@ def _load_config_from_server_env_files(config_p):
config_p.read(conf_files)
except Exception as e:
raise Exception(f'Cannot read config files "{conf_files}": {e}') from e
_update_odoo_config_options(config_p)


def _load_config_from_rcfile(config_p):
Expand Down
51 changes: 26 additions & 25 deletions server_environment/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>server configuration environment files</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,29 +360,24 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="server-configuration-environment-files">
<h1 class="title">server configuration environment files</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="server-configuration-environment-files">
<h1>server configuration environment files</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:39cd61c3a9621d0b7ee7a346adf45f4a2c90e80e6a61e18f182386c6fc90fd19
!! source digest: sha256:dcc784d558683190d604281faea315ff44a3c8ffe998f31f749b06e4def888e1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-env/tree/18.0/server_environment"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-env-18-0/server-env-18-0-server_environment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-env&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-env/tree/18.0/server_environment"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-env-18-0/server-env-18-0-server_environment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-env&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module provides a way to define an environment in the main Odoo
configuration file and to read some configurations from files depending
on the configured environment: you define the environment in the main
configuration file, and the values for the various possible environments
are stored in the <tt class="docutils literal">server_environment_files</tt> companion module.</p>
<p>The <tt class="docutils literal">server_environment_files</tt> module is optional, the values can be
set using an environment variable with a fallback on default values in
the database.</p>
the database. you will be able to overwrite some odoo options.</p>
<p>The configuration read from the files are visible under the
Configuration menu. If you are not in the ‘dev’ environment you will not
be able to see the values contained in the defined secret keys (by
Expand Down Expand Up @@ -410,7 +405,7 @@ <h1>server configuration environment files</h1>
</ul>
</div>
<div class="section" id="installation">
<h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
<p>By itself, this module does little. See for instance the
<tt class="docutils literal">mail_environment</tt> addon which depends on this one to allow
configuring the incoming and outgoing mail servers depending on the
Expand All @@ -422,7 +417,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
<tt class="docutils literal">SERVER_ENV_CONFIG</tt> and <tt class="docutils literal">SERVER_ENV_CONFIG_SECRET</tt>.</p>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
<p>To configure this module, you need to edit the main configuration file
of your instance, and add a directive called <tt class="docutils literal">running_env</tt>. Commonly
used values are ‘dev’, ‘test’, ‘production’:</p>
Expand All @@ -441,7 +436,7 @@ <h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
<p>If you don’t provide any value, test is used as a safe default.</p>
<p>You have several possibilities to set configuration values:</p>
<div class="section" id="server-environment-files">
<h3><a class="toc-backref" href="#toc-entry-3">server_environment_files</a></h3>
<h2><a class="toc-backref" href="#toc-entry-3">server_environment_files</a></h2>
<p>You can edit the settings you need in the <tt class="docutils literal">server_environment_files</tt>
addon. The <tt class="docutils literal">server_environment_files_sample</tt> can be used as an
example:</p>
Expand All @@ -452,10 +447,17 @@ <h3><a class="toc-backref" href="#toc-entry-3">server_environment_files</a></h3>
can override or extend default values;</li>
<li>you can override or extend values in the main configuration file of
your instance;</li>
<li>In some platforms (like odoo.sh where production config file is copied
to staging) it can be useful to overwrite options written in the
<tt class="docutils literal">[options]</tt> section. You must allow the override by adding
<tt class="docutils literal">server_environment_allow_overwrite_options_section = True</tt> to the
former <tt class="docutils literal">odoo.cfg</tt> config file or through the environment variable:
<tt class="docutils literal">export SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION=True</tt> (if
both are set config file takes precedence).</li>
</ul>
</div>
<div class="section" id="environment-variable">
<h3><a class="toc-backref" href="#toc-entry-4">Environment variable</a></h3>
<h2><a class="toc-backref" href="#toc-entry-4">Environment variable</a></h2>
<p>You can define configuration in the environment variable
<tt class="docutils literal">SERVER_ENV_CONFIG</tt> and/or <tt class="docutils literal">SERVER_ENV_CONFIG_SECRET</tt>. The 2
variables are handled the exact same way, this is only a convenience for
Expand Down Expand Up @@ -505,7 +507,7 @@ <h3><a class="toc-backref" href="#toc-entry-4">Environment variable</a></h3>
reference records. See “USAGE”.</blockquote>
</div>
<div class="section" id="default-values">
<h3><a class="toc-backref" href="#toc-entry-5">Default values</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Default values</a></h2>
<p>When using the <tt class="docutils literal">server.env.mixin</tt> mixin, for each env-computed field,
a companion field <tt class="docutils literal">&lt;field&gt;_env_default</tt> is created. This field is not
environment-dependent. It’s a fallback value used when no key is set in
Expand All @@ -514,15 +516,15 @@ <h3><a class="toc-backref" href="#toc-entry-5">Default values</a></h3>
<p>Note: empty environment keys always take precedence over default fields</p>
</div>
<div class="section" id="server-environment-integration">
<h3><a class="toc-backref" href="#toc-entry-6">Server environment integration</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Server environment integration</a></h2>
<p>Read the documentation of the class
<a class="reference external" href="models/server_env_mixin.py">models/server_env_mixin.py</a> and
[models/server_env_tech_name_mixin.py]
(models/server_env_tech_name_mixin.py)</p>
</div>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-7">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-7">Usage</a></h1>
<p>You can include a mixin in your model and configure the env-computed
fields by an override of <tt class="docutils literal">_server_env_fields</tt>.</p>
<pre class="literal-block">
Expand All @@ -546,7 +548,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Usage</a></h2>
</pre>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>it is not possible to set the environment from the command line. A
configuration file must be used.</li>
Expand All @@ -558,23 +560,23 @@ <h2><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h2>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-9">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-9">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-env/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/server-env/issues/new?body=module:%20server_environment%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-10">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-10">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-11">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-11">Authors</a></h2>
<ul class="simple">
<li>Camptocamp</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-12">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-12">Contributors</a></h2>
<ul class="simple">
<li>Florent Xicluna (Wingo) &lt;<a class="reference external" href="mailto:florent.xicluna&#64;gmail.com">florent.xicluna&#64;gmail.com</a>&gt;</li>
<li>Nicolas Bessi &lt;<a class="reference external" href="mailto:nicolas.bessi&#64;camptocamp.com">nicolas.bessi&#64;camptocamp.com</a>&gt;</li>
Expand All @@ -591,7 +593,7 @@ <h3><a class="toc-backref" href="#toc-entry-12">Contributors</a></h3>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-13">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-13">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -604,6 +606,5 @@ <h3><a class="toc-backref" href="#toc-entry-13">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
58 changes: 58 additions & 0 deletions server_environment/tests/test_server_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,61 @@ def test_default_hidden_password(self):
self.assertIn("odoo_I_db_password", defaults)
self.assertIn("odoo_I_smtp_password", defaults)
self.assertIn("outgoing_mail_provider_promail_I_smtp_pass", defaults)

@patch.dict(os.environ, {"SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION": "0"})
@patch.dict(
odoo_config.options,
{
"running_env": "testing",
"server_environment_allow_overwrite_options_section": True,
"odoo_test_option": "fake odoo config",
},
)
def test_server_environment_allow_overwrite_options_section(self):
with self.set_config_dir("testfiles"):
server_env._load_config()
self.assertEqual(
odoo_config["odoo_test_option"], "Set in config file for testing env"
)

@patch.dict(os.environ, {"SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION": "1"})
@patch.dict(
odoo_config.options,
{
"running_env": "testing",
"server_environment_allow_overwrite_options_section": False,
"odoo_test_option": "fake odoo config",
},
)
def test_server_environment_disabled_overwrite_options_section(self):
with self.set_config_dir("testfiles"):
server_env._load_config()
self.assertEqual(odoo_config["odoo_test_option"], "fake odoo config")

@patch.dict(os.environ, {"SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION": "1"})
@patch.dict(
odoo_config.options,
{
"running_env": "testing",
"odoo_test_option": "fake odoo config",
},
)
def test_server_environment_allow_overwrite_options_section_by_env(self):
with self.set_config_dir("testfiles"):
server_env._load_config()
self.assertEqual(
odoo_config["odoo_test_option"], "Set in config file for testing env"
)

@patch.dict(os.environ, {"SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION": "0"})
@patch.dict(
odoo_config.options,
{
"running_env": "testing",
"odoo_test_option": "fake odoo config",
},
)
def test_server_environment_disabled_overwrite_options_section_by_env(self):
with self.set_config_dir("testfiles"):
server_env._load_config()
self.assertEqual(odoo_config["odoo_test_option"], "fake odoo config")
3 changes: 3 additions & 0 deletions server_environment/tests/testfiles/testing/base.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[options]
odoo_test_option = Set in config file for testing env

[external_service.ftp]
user = testing