Package: odoo12-addon-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 theserver_environment_filescompanion
module.Theserver_environment_filesmodule 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 the defined secret keys
(by default : ‘passw’, ‘key’, ‘secret’ and ‘token’).Table of contentsInstallationConfigurationserver_environment_filesEnvironment variableDefault valuesKeychain integrationUsageKnown issues / RoadmapBug TrackerCreditsAuthorsContributorsMaintainersInstallationBy itself, this module does little. See for instance themail_environmentaddon which depends on this one to allow configuring
the incoming and outgoing mail servers depending on the environment.You can store your configuration values in a companion module calledserver_environment_files. You can copy and customize the providedserver_environment_files_samplemodule for this purpose. Alternatively, you
can provide them in environment variablesSERVER_ENV_CONFIGandSERVER_ENV_CONFIG_SECRET.ConfigurationTo configure this module, you need to edit the main configuration file
of your instance, and add a directive calledrunning_env. Commonly
used values are ‘dev’, ‘test’, ‘production’:[options]
running_env=devValues associated to keys containing ‘passw’ are only displayed in the ‘dev’
environment.If you don’t provide any value,testis used as a safe default.You have several possibilities to set configuration values:server_environment_filesYou can edit the settings you need in theserver_environment_filesaddon. Theserver_environment_files_samplecan be used as an example:values common to all / most environments can be stored in thedefault/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;you can override or extend values in the main configuration
file of your instance;Environment variableYou can define configuration in the environment variableSERVER_ENV_CONFIGand/orSERVER_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 inserver_environment_files, the options set in the
environment variable override them.The options in the environment variable are not dependent ofrunning_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
"WARNINGmy_sftpmust match the name of the record.
If you want something more reliable useserver.env.techname.mixinand usetech_namefield to reference records.
See “USAGE”.Default valuesWhen using theserver.env.mixinmixin, for each env-computed field, a
companion field<field>_env_defaultis 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 fieldsKeychain integrationRead the documentation of the classmodels/server_env_mixin.py.UsageYou can include a mixin in your model and configure the env-computed fields
by an override of_server_env_fields.class StorageBackend(models.Model):
    _name = "storage.backend"
    _inherit = ["storage.backend", "server.env.mixin"]

    @property
    def _server_env_fields(self):
        return {"directory_path": {}}Read the documentation of the class and methods inmodels/server_env_mixin.py.If you want to have a technical name to reference:class StorageBackend(models.Model):
    _name = "storage.backend"
    _inherit = ["storage.backend", "server.env.techname.mixin", "server.env.mixin"]

    [...]Known issues / Roadmapit is not possible to set the environment from the command line. A
configuration file must be used.the module does not allow to set low level attributes such as database server, etc.server.env.techname.mixin’stech_namefield could leverage the new option
for computable / writable fields and get rid of some onchange / read / write code.Bug TrackerBugs are tracked onGitHub 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 welcomedfeedback.Do not contact contributors directly about support or help with technical issues.CreditsAuthorsCamptocampContributorsFlorent Xicluna (Wingo) <florent.xicluna@gmail.com>Nicolas Bessi <nicolas.bessi@camptocamp.com>Alexandre Fayolle <alexandre.fayolle@camptocamp.com>Daniel Reis <dgreis@sapo.pt>Holger Brunn <hbrunn@therp.nl>Leonardo Pistone <leonardo.pistone@camptocamp.com>Adrien Peiffer <adrien.peiffer@acsone.com>Thierry Ducrest <thierry.ducrest@camptocamp.com>Guewen Baconnier <guewen.baconnier@camptocamp.com>Thomas Binfeld <thomas.binsfeld@acsone.eu>Stéphane Bidoul <stefane.bidoul@acsone.com>Simone Orsi <simahawk@gmail.com>MaintainersThis 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.This module is part of theOCA/server-envproject on GitHub.You are welcome to contribute. To learn how please visithttps://odoo-community.org/page/Contribute.