Skip to content
Snippets Groups Projects
Commit 20c1d1a2 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '7000-corrections' into 'master'

detector: Do not show error for file[]

See merge request !131
parents 11f6afaa c9c63d1f
No related branches found
No related tags found
1 merge request!131detector: Do not show error for file[]
...@@ -80,7 +80,7 @@ function dbdetect.validate(){ ...@@ -80,7 +80,7 @@ function dbdetect.validate(){
local _config="${1:-$DBD_INIFILE}" local _config="${1:-$DBD_INIFILE}"
# show errors in profile ini files # show errors in profile ini files
ini.validate "$_config" "$( dirname "$0")/includes/dbdetect_validate_profile.ini" 0 && dbdetect._wd "OK: Validation of '$_config' was successful" ini.validate "$_config" "$( dirname "$0")/includes/dbdetect_validate_profile.ini" "$DBD_DEBUG" && dbdetect._wd "OK: Validation of '$_config' was successful"
} }
# check if the requirements for a database match # check if the requirements for a database match
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# IDEA # IDEA
[style] [style]
section = "^[a-zA-Z0-9_]*$" section = "^[a-zA-Z0-9_]*$"
key = "^[a-zA-Z0-9_\-]*$" key = "^[a-zA-Z0-9_\-]*(|\[\])$"
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# section names # section names
......
...@@ -10,6 +10,16 @@ ...@@ -10,6 +10,16 @@
# Docs: https://www.axel-hahn.de/docs/bash_iniparser/ # Docs: https://www.axel-hahn.de/docs/bash_iniparser/
# #
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# TODO
# - ini.validate:
# - handle non existing validation rules
# - define all vars as local
# - detect invalid lines (all except sections, values, comments, empty lines)
# - ini.export:
# - detect unsafe entries $() and backticks
# - ini.value:
# - detect comment after value
# ----------------------------------------------------------------------
# 2024-02-04 v0.1 Initial version # 2024-02-04 v0.1 Initial version
# 2024-02-08 v0.2 add ini.varexport; improve replacements of quotes # 2024-02-08 v0.2 add ini.varexport; improve replacements of quotes
# 2024-02-10 v0.3 handle spaces and tabs around vars and values # 2024-02-10 v0.3 handle spaces and tabs around vars and values
...@@ -18,6 +28,7 @@ ...@@ -18,6 +28,7 @@
# 2024-02-21 v0.6 harden ini.value for keys with special chars; fix fetching last value # 2024-02-21 v0.6 harden ini.value for keys with special chars; fix fetching last value
# 2024-03-17 v0.7 add ini.validate # 2024-03-17 v0.7 add ini.validate
# 2024-03-17 v0.8 errors are written to STDERR; update help; use [[:space:]] in regex; update help # 2024-03-17 v0.8 errors are written to STDERR; update help; use [[:space:]] in regex; update help
# 2024-03-18 v0.9 validator improvements (but ini validate is not rock solid yet)
# ====================================================================== # ======================================================================
INI_FILE= INI_FILE=
...@@ -299,15 +310,17 @@ function ini.validate(){ ...@@ -299,15 +310,17 @@ function ini.validate(){
return 1 return 1
fi fi
# declare all needed variables in case that those sections are not defined
# in vilidation ini
declare -A validate_style
declare -A validate_sections
declare -A validate_varsMust
declare -A validate_varsCan
eval "$( ini.varexport "validate_" "$myvalidationfile" )" eval "$( ini.varexport "validate_" "$myvalidationfile" )"
if [ -z "${validate_sections[*]}" ]; then if [ -z "${validate_style[*]}${validate_sections[*]}${validate_varsMust[*]}${validate_varsCan[*]}" ]; then
echo -e "$ERROR: Validation file in 2nd param '${myvalidationfile}' has no section definition [sections]." >&2 echo -e "$ERROR: Validation file in 2nd param doesn't seem to be a validation.ini." >&2
echo " Hint: Maybe it is no validation file (yet) or you flipped the parameters." >&2
return 1
fi
if [ -z "${validate_varsMust[*]}${validate_varsCan[*]}" ]; then
echo -e "$ERROR: Validation file in 2nd param '${myvalidationfile}' has no key definition [varsMust] and [varsCan]." >&2
echo " Hint: Maybe it is no validation file (yet) or you flipped the parameters." >&2 echo " Hint: Maybe it is no validation file (yet) or you flipped the parameters." >&2
return 1 return 1
fi fi
...@@ -319,7 +332,7 @@ function ini.validate(){ ...@@ -319,7 +332,7 @@ function ini.validate(){
for section in $( tr "," " " <<< "${validate_sections['must']}"); for section in $( tr "," " " <<< "${validate_sections['must']}");
do do
if ini.sections "$myinifile" | grep -q "^$section$" ; then if ini.sections "$myinifile" | grep -q "^$section$" ; then
_vd "OK: Section [$section] is present." _vd "OK: Section is present [$section]."
else else
echo -e "$ERROR: Section [$section] is not present." >&2 echo -e "$ERROR: Section [$section] is not present." >&2
iErr+=1 iErr+=1
...@@ -332,11 +345,17 @@ function ini.validate(){ ...@@ -332,11 +345,17 @@ function ini.validate(){
for section in $( ini.sections "$myinifile" ) for section in $( ini.sections "$myinifile" )
do do
# ----- Check if our section name has the allowed syntax # ----- Check if our section name has the allowed syntax
if ! grep -q "${validate_style['section']}" <<< "$section" ; then if [ -n "${validate_style['section']}" ]; then
echo -e "$ERROR: Section [$section] violates style rule '${validate_style['section']}'" >&2 if ! grep -qE "${validate_style['section']}" <<< "$section" ; then
echo -e "$ERROR: Section [$section] violates style rule '${validate_style['section']}'" >&2
iErr+=1
else
_vd "OK: Section name [$section] matches style rule '${validate_style['section']}'"
fi
fi fi
# ----- Check if our sections are in MUST or CAN # ----- Check if our sections are in MUST or CAN
if ! grep -Fq ",${section}," <<< ",${validate_sections['must']},${validate_sections['must']},"; then if ! grep -Fq ",${section}," <<< ",${validate_sections['must']},${validate_sections['must']},"; then
echo -e "$ERROR: Unknown section name: [$section] - ist is not listed as MUST nor CAN." >&2 echo -e "$ERROR: Unknown section name: [$section] - ist is not listed as MUST nor CAN." >&2
iErr+=1 iErr+=1
...@@ -364,8 +383,13 @@ function ini.validate(){ ...@@ -364,8 +383,13 @@ function ini.validate(){
# ----- Check if our keys are MUST or CAN keys # ----- Check if our keys are MUST or CAN keys
for mykey in $( ini.keys "$myinifile" "$section"); do for mykey in $( ini.keys "$myinifile" "$section"); do
if ! grep -q "${validate_style['key']}" <<< "$mykey" ; then if [ -n "${validate_style['key']}" ]; then
echo -e "$ERROR: Key [$section] -> $mykey violates style rule '${validate_style['key']}'" >&2 if ! grep -qE "${validate_style['key']}" <<< "$mykey" ; then
echo -e "$ERROR: Key [$section] -> $mykey violates style rule '${validate_style['key']}'" >&2
iErr+=1
else
_vd " OK: [$section] -> $mykey matches style rule '${validate_style['key']}'"
fi
fi fi
keyregex="$( echo "${mykey}" | sed -e's,\[,\\[,g' | sed -e's,\],\\],g' )" keyregex="$( echo "${mykey}" | sed -e's,\[,\\[,g' | sed -e's,\],\\],g' )"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment