mirror of
https://github.com/netinvent/npbackup.git
synced 2025-12-18 06:01:57 +08:00
Add max recursion for variable evaluation in config file
This commit is contained in:
parent
3703f43fbe
commit
a45d5f783b
1 changed files with 8 additions and 3 deletions
|
|
@ -7,8 +7,8 @@ __intname__ = "npbackup.configuration"
|
||||||
__author__ = "Orsiris de Jong"
|
__author__ = "Orsiris de Jong"
|
||||||
__copyright__ = "Copyright (C) 2022-2023 NetInvent"
|
__copyright__ = "Copyright (C) 2022-2023 NetInvent"
|
||||||
__license__ = "GPL-3.0-only"
|
__license__ = "GPL-3.0-only"
|
||||||
__build__ = "2023050301"
|
__build__ = "2023052801"
|
||||||
__version__ = "1.7.0 for npbackup 2.2.0+"
|
__version__ = "1.7.1 for npbackup 2.2.0+"
|
||||||
|
|
||||||
from typing import Tuple, Optional, List
|
from typing import Tuple, Optional, List
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -259,12 +259,16 @@ def evaluate_variables(config_dict: dict, value: str) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# We need to make a loop to catch all nested variables
|
# We need to make a loop to catch all nested variables
|
||||||
|
# but we also need a max recursion limit
|
||||||
|
# If each variable has two sub variables, we'd have max 4x2x2 loops
|
||||||
|
count = 0
|
||||||
|
maxcount = 4*2*2
|
||||||
while (
|
while (
|
||||||
"${MACHINE_ID}" in value
|
"${MACHINE_ID}" in value
|
||||||
or "${MACHINE_GROUP}" in value
|
or "${MACHINE_GROUP}" in value
|
||||||
or "${BACKUP_JOB}" in value
|
or "${BACKUP_JOB}" in value
|
||||||
or "${HOSTNAME}" in value
|
or "${HOSTNAME}" in value
|
||||||
):
|
) and count <= maxcount:
|
||||||
value = value.replace("${HOSTNAME}", platform.node())
|
value = value.replace("${HOSTNAME}", platform.node())
|
||||||
try:
|
try:
|
||||||
value = value.replace(
|
value = value.replace(
|
||||||
|
|
@ -285,6 +289,7 @@ def evaluate_variables(config_dict: dict, value: str) -> str:
|
||||||
)
|
)
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
pass
|
pass
|
||||||
|
count += 1
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue