From a411be3336c725b17145c0f41b0b7a1b67b4da26 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Mon, 6 May 2024 14:14:02 +0000 Subject: [PATCH] vyos.template: T3664: use a module-level global variable for the default template directory as a more convenient and secure alternative to environment variable (cherry picked from commit 9aa8c3cd9bb4d11d247895576ab8f90f6a0e19b5) # Conflicts: # python/vyos/template.py --- python/vyos/template.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/vyos/template.py b/python/vyos/template.py index ffccae9a14..de46cf521b 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -25,6 +25,14 @@ from vyos.utils.permission import chmod from vyos.utils.permission import chown +# We use a mutable global variable for the default template directory +# to make it possible to call scripts from this repository +# outside of live VyOS systems. +# If something (like the image build scripts) +# want to call a script, they can modify the default location +# to the repository path. +DEFAULT_TEMPLATE_DIR = directories["templates"] + # Holds template filters registered via register_filter() _FILTERS = {} _TESTS = {} @@ -33,7 +41,11 @@ @functools.lru_cache(maxsize=2) def _get_environment(location=None): if location is None: +<<<<<<< HEAD loc_loader=FileSystemLoader(directories["templates"]) +======= + loc_loader=FileSystemLoader(DEFAULT_TEMPLATE_DIR) +>>>>>>> 9aa8c3cd9 (vyos.template: T3664: use a module-level global variable for the default template directory) else: loc_loader=FileSystemLoader(location) env = Environment(