Skip to content

Commit

Permalink
format template and services multiples
Browse files Browse the repository at this point in the history
  • Loading branch information
syrk4web committed Jul 9, 2024
1 parent 6d2905c commit 8e1bd26
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 25 deletions.
17 changes: 7 additions & 10 deletions src/client/tests/globalconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4850,8 +4850,7 @@
"containerClass": "z-12"
}
}
},
"removeDisabled": true
}
},
{
"id": "jobs",
Expand Down Expand Up @@ -5227,8 +5226,7 @@
"containerClass": "z-5"
}
}
},
"removeDisabled": true
}
},
{
"id": "metrics",
Expand Down Expand Up @@ -7557,8 +7555,7 @@
"mobile": 12
},
"disabled": false,
"value": "",
"method": "ui",
"value": "service",
"popovers": [
{
"iconName": "disk",
Expand All @@ -7569,7 +7566,8 @@
"text": "Full URL of the proxied resource (proxy_pass)."
}
],
"containerClass": "z-26"
"containerClass": "z-26",
"method": "ui"
},
"REVERSE_PROXY_URL": {
"context": "multisite",
Expand Down Expand Up @@ -7975,8 +7973,7 @@
"containerClass": "z-13"
}
}
},
"removeDisabled": true
}
},
{
"id": "reversescan",
Expand Down Expand Up @@ -9012,7 +9009,7 @@
"raw": {
"default": {
"USE_GZIP": "dsfrgrdgrdgrdhgd",
"REVERSE_PROXY_HOST": "test",
"REVERSE_PROXY_HOST": "service",
"USE_UI": "yes"
}
}
Expand Down
122 changes: 108 additions & 14 deletions src/client/tests/globalconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3036,7 +3036,14 @@
},
],
"configs": {},
"settings": {"USE_UI": "no", "USE_CORS": "no", "USE_GZIP": "dsfrgrdgrdgrdhgd"},
"settings": {
"USE_UI": "no",
"USE_CORS": "no",
"USE_GZIP": "dsfrgrdgrdgrdhgd",
"REVERSE_PROXY_HOST_1": "template1",
"REVERSE_PROXY_HOST_2": "template2",
"REVERSE_PROXY_HOST": "template",
},
}


Expand Down Expand Up @@ -3164,11 +3171,102 @@ def set_advanced(template, plugins_base, service_settings):


def get_multiple_from_template(template, plugins):
pass

"""
We are gonna loop on each plugins multiples group, in case a setting is matching a template setting,
we will create a group using the prefix as key (or "0" if no prefix) with default settings at first.
Then we will override by the template value in case there is one.
This will return something of this type :
{'0' : {'setting' : value, 'setting2': value2}, '1' : {'setting_1': value, 'setting2_1': value}} }
"""
# Loop on each plugin and loop on multiples key
# Check if the name us matching a template key
multiple_plugins = {}
for plugin in plugins:
for setting, value in plugin.get("multiples").items():
multiple_plugins.update(plugin["multiples"])

multiple_template = {}
for setting, value in template.get("settings").items():
# Sanitize setting name to remove prefix of type _1 if exists
# Slipt by _ and check if last element is a digit
format_setting = setting
setting_split = setting.split("_")
prefix = "0"
if setting_split[-1].isdigit():
prefix = setting_split[-1]
format_setting = "_".join(setting_split[:-1])
# loop on settings of a multiple group
for mult_name, mult_settings in multiple_plugins.items():
# Check if at least one multiple plugin setting is matching the template setting
if format_setting in mult_settings:
multiple_template[mult_name] = {}
# Case it is, we will check if already a group with the right prefix exists
# If not, we will create it
if not prefix in multiple_template:
# We want each settings to have the prefix if exists
# We will get the value of the setting without the prefix and create a prefix key with the same value
# And after that we can delete the original setting
new_multiple_group = {}
for multSett, multValue in mult_settings.items():
new_multiple_group[f"{multSett}{f'_{prefix}' if prefix != '0' else ''}"] = multValue

multiple_template[mult_name][prefix] = new_multiple_group
# We can now add the template value to setting using the same setting name with prefix
multiple_template[mult_name][prefix][setting]["value"] = value

# Sort key incrementally
for mult_name, mult_settings in multiple_template.items():
multiple_template[mult_name] = dict(sorted(mult_settings.items(), key=lambda item: int(item[0])))

return multiple_template


def get_multiple_from_settings(settings, plugins):
"""
We are gonna loop on each plugins multiples group, in case a setting is matching a service / global config setting,
we will create a group using the prefix as key (or "0" if no prefix) with default settings at first.
Then we will override by the service / global config value in case there is one.
This will return something of this type :
{'0' : {'setting' : value, 'setting2': value2}, '1' : {'setting_1': value, 'setting2_1': value}} }
"""

def get_multiple_from_settings(template, settings):
pass
# Loop on each plugin and loop on multiples key
# Check if the name us matching a template key
multiple_plugins = {}
for plugin in plugins:
for setting, value in plugin.get("multiples").items():
multiple_plugins.update(plugin["multiples"])

multiple_settings = {}
for setting, value in settings.items():
# Sanitize setting name to remove prefix of type _1 if exists
# Slipt by _ and check if last element is a digit
format_setting = setting
setting_split = setting.split("_")
prefix = "0"
if setting_split[-1].isdigit():
prefix = setting_split[-1]
format_setting = "_".join(setting_split[:-1])
# loop on settings of a multiple group
for mult_name, mult_settings in multiple_plugins.items():
# Check if at least one multiple plugin setting is matching the template setting
if format_setting in mult_settings:
multiple_settings[mult_name] = {}
# Case it is, we will check if already a group with the right prefix exists
# If not, we will create it
if not prefix in multiple_settings:
# We want each settings to have the prefix if exists
# We will get the value of the setting without the prefix and create a prefix key with the same value
# And after that we can delete the original setting
new_multiple_group = {}
for multSett, multValue in mult_settings.items():
new_multiple_group[f"{multSett}{f'_{prefix}' if prefix != '0' else ''}"] = multValue

multiple_settings[mult_name][prefix] = new_multiple_group
# We can now add the template value to setting using the same setting name with prefix
multiple_settings[mult_name][prefix][setting]["value"] = value.get("value", multiple_settings[mult_name][prefix][setting]["value"])
multiple_settings[mult_name][prefix][setting]["method"] = value.get("method", "ui")
return multiple_settings


def set_multiples(template, format_plugins, service_settings):
Expand Down Expand Up @@ -3205,19 +3303,15 @@ def set_multiples(template, format_plugins, service_settings):
for setting in settings_to_delete:
del plugin["settings"][setting]

# Case all settings are disabled or at least one setting has a method different than "ui" or "default" or "manual"
# we need to add key "removeDisabled" to True
for setting, value in multiples.items():
if all([v.get("disabled") for v in value.values()]) or any([v.get("method") not in ("ui", "default", "manual") for v in value.values()]):
plugin["removeDisabled"] = True

if len(multiples):
plugin["multiples"].update(multiples)

# Now that we have for each plugin the multiples settings, we need to do the following
# get all settings from template that are multiples
# get all settings from service settings / global config that are multiples
# separate them per multiple group (no prefix, _1, _2, etc.)
# Get all settings from template that are multiples
template_multiples = get_multiple_from_template(template, format_plugins)
# Get all settings from service settings / global config that are multiples
service_multiples = get_multiple_from_settings(service_settings, format_plugins)
# We need

return format_plugins

Expand Down
2 changes: 1 addition & 1 deletion src/client/tests/globalconfig64.txt

Large diffs are not rendered by default.

0 comments on commit 8e1bd26

Please sign in to comment.