Skip to content

Commit 6e49bac

Browse files
authored
Merge pull request #447 from infosiftr/ini-style-config
Detect/ignore the old INI-style configuration
2 parents 8a27bbb + c9d4281 commit 6e49bac

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

3.6/docker-entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ _parse_config() {
152152
if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155+
if grep -vEm1 '^[[:space:]]*(#|$)' "$configPath" | grep -qE '^[[:space:]]*[^=:]+[[:space:]]*='; then
156+
# if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+
# https://docs.mongodb.com/v2.4/reference/configuration-options/
158+
# https://docs.mongodb.com/v2.6/reference/configuration-options/
159+
# https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+
# https://stackoverflow.com/a/25518018/433558
161+
echo >&2
162+
echo >&2 "WARNING: it appears that '$configPath' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+
echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+
echo >&2
165+
return 1
166+
fi
155167
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156168
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157169
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out

4.0/docker-entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ _parse_config() {
152152
if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155+
if grep -vEm1 '^[[:space:]]*(#|$)' "$configPath" | grep -qE '^[[:space:]]*[^=:]+[[:space:]]*='; then
156+
# if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+
# https://docs.mongodb.com/v2.4/reference/configuration-options/
158+
# https://docs.mongodb.com/v2.6/reference/configuration-options/
159+
# https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+
# https://stackoverflow.com/a/25518018/433558
161+
echo >&2
162+
echo >&2 "WARNING: it appears that '$configPath' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+
echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+
echo >&2
165+
return 1
166+
fi
155167
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156168
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157169
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out

4.2/docker-entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ _parse_config() {
152152
if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155+
if grep -vEm1 '^[[:space:]]*(#|$)' "$configPath" | grep -qE '^[[:space:]]*[^=:]+[[:space:]]*='; then
156+
# if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+
# https://docs.mongodb.com/v2.4/reference/configuration-options/
158+
# https://docs.mongodb.com/v2.6/reference/configuration-options/
159+
# https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+
# https://stackoverflow.com/a/25518018/433558
161+
echo >&2
162+
echo >&2 "WARNING: it appears that '$configPath' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+
echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+
echo >&2
165+
return 1
166+
fi
155167
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156168
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157169
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out

4.4/docker-entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ _parse_config() {
152152
if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155+
if grep -vEm1 '^[[:space:]]*(#|$)' "$configPath" | grep -qE '^[[:space:]]*[^=:]+[[:space:]]*='; then
156+
# if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+
# https://docs.mongodb.com/v2.4/reference/configuration-options/
158+
# https://docs.mongodb.com/v2.6/reference/configuration-options/
159+
# https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+
# https://stackoverflow.com/a/25518018/433558
161+
echo >&2
162+
echo >&2 "WARNING: it appears that '$configPath' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+
echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+
echo >&2
165+
return 1
166+
fi
155167
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156168
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157169
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out

docker-entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ _parse_config() {
152152
if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155+
if grep -vEm1 '^[[:space:]]*(#|$)' "$configPath" | grep -qE '^[[:space:]]*[^=:]+[[:space:]]*='; then
156+
# if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+
# https://docs.mongodb.com/v2.4/reference/configuration-options/
158+
# https://docs.mongodb.com/v2.6/reference/configuration-options/
159+
# https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+
# https://stackoverflow.com/a/25518018/433558
161+
echo >&2
162+
echo >&2 "WARNING: it appears that '$configPath' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+
echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+
echo >&2
165+
return 1
166+
fi
155167
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156168
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157169
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out

0 commit comments

Comments
 (0)