Generic way for configuring Gitea app.ini #240

Merged
luhahn merged 8 commits from justusbunsi/helm-chart:feature/rework-sensitive-ini-settings into master 2021-12-22 10:44:05 +00:00
Showing only changes of commit 4b56c32e24 - Show all commits

View File

@ -17,22 +17,35 @@ stringData:
function env2ini::read_config_to_env() {
local section="${1}"
local line="${2}"
if [[ -z "${line}" ]]; then
# skip empty line
return
justusbunsi marked this conversation as resolved Outdated

TODO: Proper handling for values with = and " inside.

TODO: Proper handling for values with `=` and `"` inside.
fi
# xargs echo -n trims all whitespaces and a trailing new line
local setting=$(awk -F '=' '{print $1}' <<< "${line}" | xargs echo -n)
local value=$(awk -F '=' '{print $NF}' <<< "${line}" | xargs echo -n)
# 'xargs echo -n' trims all leading/trailing whitespaces and a trailing new line
local setting="$(awk -F '=' '{print $1}' <<< "${line}" | xargs echo -n)"
if [[ -z "${setting}" ]]; then
env2ini::log " ? unprocessable line '${line}'"
return
env2ini::log " - invalid setting"
exit 1
fi
local value=''
local regex="^${setting}(\s*)=(\s*)(.*)"
justusbunsi marked this conversation as resolved Outdated

Users can have spaces around the = character in their config sources. Just like it is possible within app.ini. This regex takes this into account when stripping the setting name from the line to parse.

Users can have spaces around the `=` character in their config sources. Just like it is possible within `app.ini`. This regex takes this into account when stripping the setting name from the line to parse.
if [[ $line =~ $regex ]]; then
value="${BASH_REMATCH[3]}"
else
env2ini::log " - invalid setting"
exit 1
justusbunsi marked this conversation as resolved Outdated

I've decided to let the script fail in case any line is not processable. That way the user is required to fix their configuration before the currently applied breaks somehow. Open for discussion here.

I've decided to let the script fail in case any line is not processable. That way the user is required to fix their configuration before the currently applied breaks somehow. Open for discussion here.
fi
env2ini::log " + '${setting}' to '${section}'"
local masked_section="${section//./_0X2E_}" # // instructs to replace all matches
local masked_section="${section//./_0X2E_}" # '//' instructs to replace all matches
masked_section="${masked_section//-/_0X2D_}"
export "ENV_TO_INI__${masked_section^^}__${setting^^}=${value}"
export "ENV_TO_INI__${masked_section^^}__${setting^^}=${value}" # '^^' makes the variable content uppercase
}
function env2ini::process_config_file() {