From 49ec4b8d99a1c54dfbabe1cdbb4ab6c34fda5783 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 16 Jan 2024 16:31:59 +0100 Subject: [PATCH] new: [odoo] add ``dbfilter`` option --- odoo-tecnativa/README.org | 40 +++++++++++++++++++++++++++++++++++++++ odoo-tecnativa/README.rst | 8 -------- odoo-tecnativa/hooks/init | 39 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 odoo-tecnativa/README.org delete mode 100644 odoo-tecnativa/README.rst diff --git a/odoo-tecnativa/README.org b/odoo-tecnativa/README.org new file mode 100644 index 0000000..fd06fc7 --- /dev/null +++ b/odoo-tecnativa/README.org @@ -0,0 +1,40 @@ + + +Odoo-tecnativa is a odoo image containing all source and add-ons because +we want to certify the whole image. + +So this means there are no builds being managed by compose, and no injection +of code. + + +* Usage + +** dbfilter + +With image ~16.0~, an advanced version of ~dbfilter~ is installed. Here +a few examples: + +#+begin_src yaml +odoo: + # .. + options: + dbfilter: + ## DOMAIN_REGEX: DBFILTER + '^www.domain.org$': '^bar$' ## domain `www.domain.org` can only see `bar`. + '^foo\.': 'foo_.*' ## domain starting with `foo.` can see db `foo_` + '^(?P[^.]+)\.': '%{name}s_.*' ## domain starting with `.` can see db `PREFIX_` + '': 'other_.*' ## all domains can see db 'other_*' + + ## Don't forget to configure the domains in the web-proxy part ! + relations: + web-proxy: + apache: + domain: www.domain.org + aliases: + - foo.otherdomain.com + - bar.wiz.eu + - test.domain.org +#+end_src + +If there's only one database seen because of the ~dbfilter~, odoo will +use it by default. diff --git a/odoo-tecnativa/README.rst b/odoo-tecnativa/README.rst deleted file mode 100644 index 949ff9a..0000000 --- a/odoo-tecnativa/README.rst +++ /dev/null @@ -1,8 +0,0 @@ - - -Odoo-tecnativa is a odoo image containing all source and add-ons because -we want to certify the whole image. - -So this means there are no builds being managed by compose, and no injection -of code. - diff --git a/odoo-tecnativa/hooks/init b/odoo-tecnativa/hooks/init index 4b75993..504af6b 100755 --- a/odoo-tecnativa/hooks/init +++ b/odoo-tecnativa/hooks/init @@ -36,6 +36,39 @@ else modules="base,${modules}" fi +cmd_args=() + +## dbfilter management +service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1 + +dbfilter=$(e "$service_def" | yq e -r=false '.options.dbfilter') || true +if [ -n "$dbfilter" ]; then + type=$(e "$dbfilter" | yq e "type") + case "${type:2}" in + str) + dbfilter=$(e "$dbfilter" | yq e -o=json '.') + cmd_args+=("--db-filter=${dbfilter}") + ;; + map) + python_expr="[" + while read-0 key val; do + [[ "$key" == "null" ]] && key="None" + python_expr+="(${key//\$/\$\$}, ${val//\$/\$\$})," + done < <(e "$dbfilter" | yq -o=json -0 'to_entries | .[] | [.key, .value] | .[]') + python_expr+="]" + cmd_args+=("--db-filter=${python_expr}") + ;; + null) + : + ;; + *) + err "Invalid value for ${WHITE}dbfilter${NORMAL}: ${dbfilter}" >&2 + echo " It should be a string or a key/value mapping" >&2 + exit 1 + ;; + esac +fi + ## config file conf=$(options-get conf 2>/dev/null) || true @@ -65,4 +98,10 @@ $SERVICE_NAME: command: - \"--workers=${workers}\" - \"-i ${modules}\" +$( +for arg in "${cmd_args[@]}"; do + echo " - |" + e "$arg" | prefix " " +done +) "