Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] server_environment: Migration to 17.0 #168

Merged
merged 71 commits into from
Jan 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
703b613
[ADD] server evironment file + sample
jgrandguillaume Oct 12, 2011
bbfa090
[FIX] openerp\assert_exit_level does not exist ! in server_environment
nbessi Nov 4, 2011
ceea098
[FIX] typo
nbessi Jan 18, 2012
64c4733
[FIX] drop the hack for the GTK client, because for 6.1 the web clien…
florentx Mar 5, 2012
a36b2fd
[MRG] from upstream
Mar 5, 2012
c3b9090
[MRG] Fix by florent.x on server_environment: drop the hack for the G…
Oct 23, 2012
d33532c
[7.0] mark all unported modules as not installable
gurneyalex Jan 18, 2013
743ab1a
[7.0] 1st pass at porting server_environment
gurneyalex Jan 18, 2013
07a4577
Generate .pot files
Mar 14, 2014
b313422
[PEP8] server_environment
yvaucher Jul 11, 2014
6c8e804
move all modules to __unported__ on master branch and set installable…
sbidoul Jul 12, 2014
9ba8b7b
Moving server environment module and sample module
nbessi Sep 9, 2014
4e77ccb
Port server environment to version 8.0
nbessi Sep 9, 2014
c099bfc
[FIX] travis
hbrunn Dec 8, 2014
1bb955e
capture stderr as well as stdout when diagnosing
lepistone Feb 5, 2015
fad42ea
Add license key in __openerp__.py
yvaucher Feb 6, 2015
5978607
fix pep8 W503
gurneyalex Feb 16, 2015
7c2ea11
Add OCA as author of OCA addons
gurneyalex Mar 2, 2015
382eb04
Add missing default oca icons
yvaucher Aug 18, 2015
31cad8e
[FIX] unconfigured server_environment doesn't play
hbrunn Aug 18, 2015
09342d0
remove deprecated checks list
lepistone Aug 31, 2015
2afff73
[UPD] prefix versions with 8.0
sbidoul Oct 9, 2015
261f8a1
[MIG] Make modules uninstallable
pedrobaeza Oct 14, 2015
72bdd08
9.0 migration of server_environment
gurneyalex Jan 21, 2016
626fdc9
[IMP] load server environment options from odoo rcfile too (#556)
sbidoul Sep 26, 2016
0bd957a
[MIG] Make modules uninstallable
pedrobaeza Oct 6, 2016
81b343e
[MIG] Rename manifest files
pedrobaeza Oct 6, 2016
9b58d8c
Migration of server_environment to 10.0
adrienpeiffer Nov 7, 2016
bd35a03
[MIG] server_environment: Migration to 11.0
TDu Nov 13, 2017
13ddf3d
server_environment: bump version
sbidoul Mar 30, 2018
b1c3943
[REF] Server Environment: remove dependency on server_environement_files
ThomasBinsfeld Jun 4, 2018
853bcb3
remove obsolete .pot files [ci skip]
sbidoul Jun 15, 2018
afb1e2d
Add SERVER_ENV_CONFIG to configure vars from env. variable
guewen Jul 19, 2018
abd6b5a
[REF] Server Environment: restrict access to server config to allowed…
ThomasBinsfeld Oct 8, 2018
b8496b7
[MIG] server_environment from 11 to 12
sbidoul Nov 5, 2018
00ab78d
[MIG] server_environment: Migration to 13.0
grindtildeath Oct 9, 2019
7f4a81a
pre-commit, black, isort
sbidoul Oct 12, 2019
e9d8dcc
server_environment: lint fixes after migration
grindtildeath Oct 22, 2019
65ba74b
server-environment: Run pre-commit
grindtildeath Oct 23, 2019
13213d6
pre-commit, black, isort
sbidoul Nov 12, 2019
b2945fa
[13.0][FIX] server_environment: Change import for Serialized field
rousseldenis Dec 19, 2019
85ee7ca
Store the 'server.config' fields in sparse fields
guewen Dec 3, 2019
e3c1da6
server_environment: Improve tests.common to allow redefinition of ser…
grindtildeath Feb 13, 2020
569b00c
server_environment: running_env default to `test` (fix #44)
simahawk Apr 1, 2020
f4b9cee
Fix server_environment version
simahawk Jul 3, 2020
091852e
Add mixin for tech name
simahawk Jul 15, 2020
4757188
Update server_environment/serv_config.py
oscarolar Sep 22, 2020
70ac80e
[IMP] : black, isort, prettier
mourad-ehm Oct 12, 2020
20cc600
[MIG] server_environment: Migration to 14.0
mourad-ehm Oct 12, 2020
0cd268b
Translated using Weblate (French)
sbidoul Dec 13, 2020
e2238bc
Translated using Weblate (Spanish)
Mat-moran Feb 11, 2021
742b1f0
[UPD] Change LICENSE to LGPL
ivantodorovich Jul 6, 2021
73b77ae
[MIG] server_environment: migration to 15.0
JuMiSanAr Oct 18, 2021
cae9e7d
[FIX] Update server_env_mixin.py to avoid NoneType error
JuMiSanAr Oct 27, 2021
97c4c5b
15.0 server_environment is Production/Stable
gurneyalex Dec 2, 2021
ef20d82
server_environment: Update default fields label
adrienpeiffer Mar 18, 2022
9d1453d
[IMP] server_environment: black, isort, prettier
FrancoMaxime Sep 1, 2022
f9f1cdc
[MIG] server_environment: Migration to 16.0
FrancoMaxime Sep 1, 2022
82237b9
Remove required from tech_name mixin
guewen Jan 14, 2021
5900959
server_environment: do not copy tech_name
simahawk May 10, 2022
d847929
[IMP] server_environment: don't print stack trace when the field can'…
ivantodorovich Jul 12, 2022
8df08c4
server_env: fix inverse method (closes #151)
simahawk Apr 4, 2023
e90a755
[IMP] Server env default fields string
qgroulard Jun 19, 2023
b2f9c69
Translated using Weblate (Italian)
francesco-ooops Jun 22, 2023
22425ec
Translated using Weblate (Spanish)
Ivorra78 Jul 25, 2023
9d7e6fe
[FIX] don't use deprecated get_default_locale
sbidoul Aug 28, 2023
399d7ae
Cache get_serverenvironment()
sbidoul Aug 28, 2023
3bdf064
Translated using Weblate (Spanish)
Ivorra78 Aug 21, 2023
1748ef0
[IMP] server_environment: pre-commit stuff
moitabenfdz Nov 13, 2023
344d6a7
[MIG] server_environment: Migration to 17.0
moitabenfdz Nov 13, 2023
35e6ef9
[17.0][FIX]server_environment: custom fields must start with x_
moitabenfdz Nov 15, 2023
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
Prev Previous commit
Next Next commit
Add SERVER_ENV_CONFIG to configure vars from env. variable
Add SERVER_ENV_CONFIG_SECRET alongside SERVER_ENV_CONFIG

Allows to isolate the secrets in your deployment

Improve documentation regarding variables

Add a server environment mixin

To automatically convert fields into fields reading values from the
environment. Until now, every module reimplements the same computed
field.

Read default values from database when no config is provided

Automatically add <field_name>_env_default for every field transformed
to a "computed from env" field, so a default value can be set. It will
be used when the configuration is not set in a configuration file
(when the key is absent, not empty).

Allow to edit default values for env-computed fields

When they don't have any key in the environment configuration files.
In the UI, when a field is set in a configuration file, the field is
readonly, if not the field is editable. Which means you can selectively
choose which fields depend on the environment and which can use a
"default" value stored in database.

Fix a few small issues in mixin

Use a dictionary to configure the fields

Add global section

Disable prefetch on env-computed fields

As in the inverse field that write the value into the <field>_env_default
we have to browse the record, the prefetch has the effect of calling
compute on the env-computed field which resets the value to it's
previous state before we have the occasion to store it.

Use global section name as first part of the section

Allow to edit all fields on creation

Make server_environment_files optional

Allow integration with keychain

By adding options to change the compute and inverse methods for default
fields

Update documentation of server_environment, bump

Add SERVER_ENV_CONFIG_SECRET alongside SERVER_ENV_CONFIG

Allows to isolate the secrets in your deployment

Reinforce server_environment base tests

Add tests for the server env mixin

Infer configparser getter from field type

Fixes for review feedbacks

Add tests and support of _inherits

Use SavepointCase instead of TransactionCase

It means less records to create for each test

Fix iteration on records
guewen authored and moitabenfdz committed Nov 13, 2023
commit afb1e2de80563fbb4fded104bad740fecd075d15
124 changes: 103 additions & 21 deletions server_environment/README.rst
Original file line number Diff line number Diff line change
@@ -3,67 +3,149 @@
:alt: License: GPL-3

==================
server environment
Server Environment
==================

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 `server_environment_files` companion
environments are stored in the ``server_environment_files`` companion
module.

All the settings will be read only and visible under the Configuration
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 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 keys named '*passw*'.

Installation
============

By itself, this module does little. See for instance the
`mail_environment` addon which depends on this one to allow configuring
``mail_environment`` addon which depends on this one to allow configuring
the incoming and outgoing mail servers depending on the environment.

To install this module, you need to provide a companion module called
`server_environment_files`. You can copy and customize the provided
`server_environment_files_sample` module for this purpose.
You can store your configuration values in a companion module called
``server_environment_files``. You can copy and customize the provided
``server_environment_files_sample`` module for this purpose. Alternatively, you
can provide them in environment variables ``SERVER_ENV_CONFIG`` and
``SERVER_ENV_CONFIG_SECRET``.


Configuration
=============

To configure this module, you need to edit the main configuration file
of your instance, and add a directive called `running_env`. Commonly
of your instance, and add a directive called ``running_env``. Commonly
used values are 'dev', 'test', 'production'::

[options]
running_env=dev

You should then edit the settings you need in the
`server_environment_files` addon. The
`server_environment_files_sample` can be used as an example:
Values associated to keys containing 'passw' are only displayed in the 'dev'
environment.

You have several possibilities to set configuration values:

server_environment_files
------------------------

You can edit the settings you need in the ``server_environment_files`` addon. The
``server_environment_files_sample`` can be used as an example:

* values common to all / most environments can be stored in the
`default/` directory using the .ini file syntax;
``default/`` directory using the .ini file syntax;
* each environment you need to define is stored in its own directory
and can override or extend default values;
* finally, you can override or extend values in the main configuration
file of you instance.
* you can override or extend values in the main configuration
file of your instance;

Environment variable
--------------------

You can define configuration in the environment variable ``SERVER_ENV_CONFIG``
and/or ``SERVER_ENV_CONFIG_SECRET``. The 2 variables are handled the exact same
way, this is only a convenience for the deployment where you can isolate the
secrets in a different, encrypted, file. They are multi-line environment variables
in the same configparser format than the files.
If you used options in ``server_environment_files``, the options set in the
environment variable overrides them.

The options in the environment variable are not dependent of ``running_env``,
the content of the variable must be set accordingly to the running environment.

Example of setup:

A public file, containing that will contain public variables::

# These variables are not odoo standard variables,
# they are there to represent what your file could look like
export WORKERS='8'
export MAX_CRON_THREADS='1'
export LOG_LEVEL=info
export LOG_HANDLER=":INFO"
export DB_MAXCONN=5

# server environment options
export SERVER_ENV_CONFIG="
[storage_backend.my-sftp]
sftp_server=10.10.10.10
sftp_login=foo
sftp_port=22200
directory_path=Odoo
"

A second file which is encrypted and contains secrets::

# This variable is not an odoo standard variable,
# it is there to represent what your file could look like
export DB_PASSWORD='xxxxxxxxx'
# server environment options
export SERVER_ENV_CONFIG_SECRET="
[storage_backend.my-sftp]
sftp_password=xxxxxxxxx
"

Default values
--------------

When using the ``server.env.mixin`` mixin, for each env-computed field, a
companion field ``<field>_env_default`` is created. This field is not
environment-dependent. It's a fallback value used when no key is set in
configuration files / environment variable.

When the default field is used, the field is made editable on Odoo.

Note: empty environment keys always take precedence over default fields


Keychain integration
--------------------

Read the documentation of the class `models/server_env_mixin.py
<models/server_env_mixin.py>`_.

Values associated to keys
containing 'passw' are only displayed in the 'dev' environment.

Usage
=====

To use this module, in your code, you can follow this example::
You can include a mixin in your model and configure the env-computed fields
by an override of ``_server_env_fields``.

::

from openerp.addons.server_environment import serv_config
for key, value in serv_config.items('external_service.ftp'):
print (key, value)
class StorageBackend(models.Model):
_name = "storage.backend"
_inherit = ["storage.backend", "server.env.mixin"]

serv_config.get('external_service.ftp', 'tls')
@property
def _server_env_fields(self):
return {"directory_path": {}}

Read the documentation of the class and methods in `models/server_env_mixin.py
<models/server_env_mixin.py>`__.


.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
7 changes: 7 additions & 0 deletions server_environment/__init__.py
Original file line number Diff line number Diff line change
@@ -17,4 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import models
# TODO when migrating to 12, fix the import of serv_config by renaming the
# file?
# Add an alias to access to the 'serv_config' module as it is shadowed
# in the following line by an import of a variable with the same name.
# We can't change the import of serv_config for backward compatibility.
from . import serv_config as server_env
from .serv_config import serv_config, setboolean
7 changes: 5 additions & 2 deletions server_environment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -20,8 +20,11 @@

{
"name": "server configuration environment files",
"version": "11.0.1.0.1",
"depends": ["base"],
"version": "11.0.2.0.0",
"depends": [
"base",
"base_sparse_field",
],
"author": "Camptocamp,Odoo Community Association (OCA)",
"summary": "move some configurations out of the database",
"website": "http://odoo-community.org/",
1 change: 1 addition & 0 deletions server_environment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import server_env_mixin
Loading