Commit baa5e895 authored by Alexis PASQUIER's avatar Alexis PASQUIER
Browse files

🔖 1.3.0

 Activation des session dans redis si les variable d'environement `REDIS_SESSION_HOST` ou `REDIS_HOST` sont detectée 
🎨 Ajout de `get_value` pour aller chercher dans les variables d'environement a la suite tant qu'aucune valeur n'est pas trouvé
- Plus simple que de faire `os.getenv("KEY1", os.getenv("KEY2", ...))` maintenant `get_value(os.environ, ["KEY1", "KEY2"])
- 📝 Doc à faire et mettre à jour
parent 2af27d23
Pipeline #74705 failed with stages
in 2 minutes and 26 seconds
......@@ -9,7 +9,7 @@
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/odoo_launcher.egg-info" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import abc
import sys
from collections import OrderedDict
from typing import Any, Dict, Union
from typing import Any, Dict, List, Optional, Union
if sys.version_info[0] == 2: # Python 2
......@@ -68,6 +68,14 @@ class EnvMapper(ConfigConvert):
# type: (Dict[str, str]) -> Dict[str, str]
raise NotImplementedError()
def get_value(self, env_vars, possible_value, default=None):
# type: (Dict[str, str], List[str], str) -> Optional[str]
for value in possible_value:
res = env_vars.get(value)
if res:
return res
return default
class OdooConfigABC(ConfigConvert, ABC):
def __init__(self, main_instance=True):
......
......@@ -13,14 +13,14 @@ class OdooCompatibilityMapper(EnvMapper):
def map_vars(self, env_vars):
# type: (Dict[str, str]) -> Dict[str, str]
return {
"WORKER_HTTP": env_vars.get("WORKER_HTTP", env_vars.get("WORKERS")),
"WORKER_CRON": env_vars.get("WORKER_CRON", env_vars.get("WORKERS")),
"WORKER_JOB": env_vars.get("WORKER_JOB", env_vars.get("WORKERS")),
"HTTP_INTERFACE": env_vars.get("HTTP_INTERFACE", env_vars.get("XMLRPC_INTERFACE")),
"HTTP_PORT": env_vars.get("HTTP_PORT", env_vars.get("XMLRPC_PORT")),
"HTTP_ENABLE": env_vars.get("HTTP_ENABLE", env_vars.get("XMLRPC_ENABLE")),
"LONGPOLLING_PORT": env_vars.get("LONGPOLLING_PORT"),
"SERVER_WIDE_MODULES": env_vars.get("SERVER_WIDE_MODULES", env_vars.get("LOAD")),
"WORKER_HTTP": self.get_value(env_vars, ["WORKER_HTTP", "WORKERS"]),
"WORKER_CRON": self.get_value(env_vars, ["WORKER_CRON", "WORKERS"]),
"WORKER_JOB": self.get_value(env_vars, ["WORKER_JOB", "WORKERS"]),
"HTTP_INTERFACE": self.get_value(env_vars, ["HTTP_INTERFACE", "XMLRPC_INTERFACE"]),
"HTTP_PORT": self.get_value(env_vars, ["HTTP_PORT", "XMLRPC_PORT"]),
"HTTP_ENABLE": self.get_value(env_vars, ["HTTP_ENABLE", "XMLRPC_ENABLE"]),
"LONGPOLLING_PORT": self.get_value(env_vars, ["LONGPOLLING_PORT"]),
"SERVER_WIDE_MODULES": self.get_value(env_vars, ["SERVER_WIDE_MODULES", "LOAD"]),
}
......@@ -37,28 +37,28 @@ class OdooQueueJobMapper(EnvMapper):
return {
"ODOO_QUEUE_JOB_ENABLE": str(enable),
"ODOO_QUEUE_JOB_CHANNELS": enable
and env_vars.get("ODOO_QUEUE_JOB_CHANNELS", env_vars.get("ODOO_CONNECTOR_CHANNELS"))
and self.get_value(env_vars, ["ODOO_QUEUE_JOB_CHANNELS", "ODOO_CONNECTOR_CHANNELS"])
or None,
"ODOO_QUEUE_JOB_SCHEME": enable
and env_vars.get("ODOO_QUEUE_JOB_SCHEME", env_vars.get("ODOO_CONNECTOR_SCHEME"))
and self.get_value(env_vars, ["ODOO_QUEUE_JOB_SCHEME", "ODOO_CONNECTOR_SCHEME"])
or None,
"ODOO_QUEUE_JOB_HOST": enable
and env_vars.get("ODOO_QUEUE_JOB_HOST", env_vars.get("ODOO_CONNECTOR_HOST"))
and self.get_value(env_vars, ["ODOO_QUEUE_JOB_HOST", "ODOO_CONNECTOR_HOST"])
or None,
"ODOO_QUEUE_JOB_PORT": enable
and env_vars.get("ODOO_QUEUE_JOB_PORT", env_vars.get("ODOO_CONNECTOR_PORT"))
and self.get_value(env_vars, ["ODOO_QUEUE_JOB_PORT", "ODOO_CONNECTOR_PORT"])
or None,
"ODOO_QUEUE_JOB_HTTP_AUTH_USER": enable
and env_vars.get("ODOO_QUEUE_JOB_HTTP_AUTH_USER", env_vars.get("ODOO_CONNECTOR_HTTP_AUTH_USER"))
and self.get_value(env_vars, ["ODOO_QUEUE_JOB_HTTP_AUTH_USER", "ODOO_CONNECTOR_HTTP_AUTH_USER"])
or None,
"ODOO_QUEUE_JOB_HTTP_AUTH_PASSWORD": enable
and env_vars.get("ODOO_QUEUE_JOB_HTTP_AUTH_PASSWORD", env_vars.get("ODOO_CONNECTOR_HTTP_AUTH_PASSWORD"))
and self.get_value(env_vars, ["ODOO_QUEUE_JOB_HTTP_AUTH_PASSWORD", "ODOO_CONNECTOR_HTTP_AUTH_PASSWORD"])
or None,
"ODOO_QUEUE_JOB_JOBRUNNER_DB_HOST": enable
and env_vars.get("ODOO_QUEUE_JOB_JOBRUNNER_DB_HOST", env_vars.get("ODOO_CONNECTOR_JOBRUNNER_DB_HOST"))
and self.get_value(env_vars, ["ODOO_QUEUE_JOB_JOBRUNNER_DB_HOST", "ODOO_CONNECTOR_JOBRUNNER_DB_HOST"])
or None,
"ODOO_QUEUE_JOB_JOBRUNNER_DB_PORT": enable
and env_vars.get("ODOO_QUEUE_JOB_JOBRUNNER_DB_PORT", env_vars.get("ODOO_CONNECTOR_JOBRUNNER_DB_PORT"))
and self.get_value(env_vars, ["ODOO_QUEUE_JOB_JOBRUNNER_DB_PORT", "ODOO_CONNECTOR_JOBRUNNER_DB_PORT"])
or None,
}
......@@ -72,17 +72,19 @@ class OdooRedisSessionMapper(EnvMapper):
def map_vars(self, env_vars):
# type: (Dict[str, str]) -> Dict[str, str]
enable = self.is_true(env_vars.get("REDIS_SESSION_ENABLE", bool(env_vars.get("REDIS_HOST"))))
enable = self.is_true(
env_vars.get("REDIS_SESSION_ENABLE", bool(self.get_value(env_vars, ["REDIS_SESSION_HOST", "REDIS_HOST"])))
)
return {
"REDIS_SESSION_ENABLE": str(enable),
"REDIS_SESSION_URL": enable and env_vars.get("REDIS_SESSION_URL", env_vars.get("REDIS_URL")) or None,
"REDIS_SESSION_HOST": enable and env_vars.get("REDIS_SESSION_HOST", env_vars.get("REDIS_HOST")) or None,
"REDIS_SESSION_PORT": enable and env_vars.get("REDIS_SESSION_PORT", env_vars.get("REDIS_PORT")) or None,
"REDIS_SESSION_URL": enable and self.get_value(env_vars, ["REDIS_SESSION_URL", "REDIS_URL"]) or None,
"REDIS_SESSION_HOST": enable and self.get_value(env_vars, ["REDIS_SESSION_HOST", "REDIS_HOST"]) or None,
"REDIS_SESSION_PORT": enable and self.get_value(env_vars, ["REDIS_SESSION_PORT", "REDIS_PORT"]) or None,
"REDIS_SESSION_DB_INDEX": enable
and env_vars.get("REDIS_SESSION_DB_INDEX", env_vars.get("REDIS_DB_INDEX"))
and self.get_value(env_vars, ["REDIS_SESSION_DB_INDEX", "REDIS_DB_INDEX"])
or None,
"REDIS_SESSION_PASSWORD": enable
and env_vars.get("REDIS_SESSION_PASSWORD", env_vars.get("REDIS_PASSWORD"))
and self.get_value(env_vars, ["REDIS_SESSION_PASSWORD", "REDIS_PASSWORD"])
or None,
}
......@@ -101,21 +103,25 @@ class CleverCloudCellarCompatibilityMapper(EnvMapper):
def map_vars(self, env_vars):
# type: (Dict[str, Union[str, bool, int, None]]) -> Dict[str, Union[str, bool, int, None]]
enable = self.is_true(env_vars.get("S3_FILESTORE_ENABLE", bool(env_vars.get("CELLAR_ADDON_HOST"))))
enable = self.is_true(
env_vars.get(
"S3_FILESTORE_ENABLE", bool(self.get_value(env_vars, ["S3_FILESTORE_HOST", "CELLAR_ADDON_HOST"]))
)
)
return {
"S3_FILESTORE_ENABLE": str(enable),
"S3_FILESTORE_HOST": enable
and env_vars.get("S3_FILESTORE_HOST", env_vars.get("CELLAR_ADDON_HOST"))
and self.get_value(env_vars, ["S3_FILESTORE_HOST", "CELLAR_ADDON_HOST"])
or None,
"S3_FILESTORE_SECRET_KEY": enable
and env_vars.get("S3_FILESTORE_SECRET_KEY", env_vars.get("CELLAR_ADDON_KEY_SECRET"))
and self.get_value(env_vars, ["S3_FILESTORE_SECRET_KEY", "CELLAR_ADDON_KEY_SECRET"])
or None,
"S3_FILESTORE_ACCESS_KEY": enable
and env_vars.get("S3_FILESTORE_ACCESS_KEY", env_vars.get("CELLAR_ADDON_KEY_ID"))
and self.get_value(env_vars, ["S3_FILESTORE_ACCESS_KEY", "CELLAR_ADDON_KEY_ID"])
or None,
# Pas de region fournit par S3 CleverCloud
"S3_FILESTORE_REGION": enable
and (env_vars.get("S3_FILESTORE_REGION", env_vars.get("CELLAR_ADDON_REGION")) or "fr-par")
and self.get_value(env_vars, ["S3_FILESTORE_REGION", "CELLAR_ADDON_REGION"], default="fr-par")
or None,
}
......@@ -123,15 +129,9 @@ class CleverCloudCellarCompatibilityMapper(EnvMapper):
class CleverCloudPostgresCompatibilityMapper(EnvMapper):
def map_vars(self, env_vars):
return {
"DB_NAME": env_vars.get("DB_NAME", env_vars.get("DATABASE", env_vars.get("POSTGRESQL_ADDON_DB"))),
"DB_HOST": env_vars.get(
"DB_HOST", env_vars.get("POSTGRESQL_ADDON_DIRECT_HOST", env_vars.get("POSTGRESQL_ADDON_HOST"))
),
"DB_PORT": (
env_vars.get(
"DB_PORT", env_vars.get("POSTGRESQL_ADDON_DIRECT_PORT", env_vars.get("POSTGRESQL_ADDON_PORT"))
)
),
"DB_USER": env_vars.get("DB_USER", env_vars.get("POSTGRESQL_ADDON_USER")),
"DB_PASSWORD": env_vars.get("DB_PASSWORD", env_vars.get("POSTGRESQL_ADDON_PASSWORD")),
"DB_NAME": self.get_value(env_vars, ["DB_NAME", "DATABASE", "POSTGRESQL_ADDON_DB", "POSTGRES_DB"]),
"DB_HOST": self.get_value(env_vars, ["DB_HOST", "POSTGRESQL_ADDON_DIRECT_HOST", "POSTGRESQL_ADDON_HOST"]),
"DB_PORT": self.get_value(env_vars, ["DB_PORT", "POSTGRESQL_ADDON_DIRECT_PORT", "POSTGRESQL_ADDON_PORT"]),
"DB_USER": self.get_value(env_vars, ["DB_USER", "POSTGRESQL_ADDON_USER", "POSTGRES_USER"]),
"DB_PASSWORD": self.get_value(env_vars, ["DB_PASSWORD", "POSTGRESQL_ADDON_PASSWORD", "POSTGRES_PASSWORD"]),
}
......@@ -10,6 +10,7 @@ skip = "__init__.py"
expand-star-imports = true # expand from module import *
ignore-init-module-imports = true # exclude __init__.py when removing unused imports
remove-duplicate-keys = true # remove all duplicate keys in objects
remove-unused-variables = true
[tool.flakehell]
base = "https://gitlab.ndp-systemes.fr/odoo-addons/ci-files/-/raw/master/jobs/.pre/base_flake_hell.toml"
[metadata]
name = odoo_launcher
version = 1.2.6
version = 1.3.0
url = https://gitlab.ndp-systemes.fr/python-libs/odoo_launcher
license = GPLv3
author = Alexis Pasquier, NDP Systemes
......
......@@ -94,13 +94,11 @@ class TestOdooQueueJobMapper(TestMapper):
def test_not_enable(self):
value1 = "1"
value2 = "2"
value3 = "3"
value4 = "4"
value5 = "5"
to_map = {
"REDIS_URL": value1,
"REDIS_SESSION_HOST": value2,
"REDIS_SESSION_PORT": value3,
"REDIS_SESSION_DB_INDEX": value4,
"REDIS_SESSION_PASSWORD": value5,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment