Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4173767663


##########
hugegraph-server/hugegraph-dist/docker/props.awk:
##########
@@ -0,0 +1,299 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means.  grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+#   PROPS_MODE=get  PROPS_KEY=K PROPS_FILE=F
+#       print the value of K's first logical definition
+#   PROPS_MODE=set  PROPS_KEY=K PROPS_FILE=F
+#       replace K's first definition in place, drop every other
+#       definition of K, append one when the file has none.  The new
+#       value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+#       variable, so secrets never appear in `ps` output or in awk's
+#       argv), and -v is not used for it so awk cannot mangle its
+#       backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+#   - '#' / '!' comments and blank lines
+#   - '=' / ':' / whitespace separators, with whitespace then an optional
+#     single '=' or ':' accepted as one separator
+#   - continuations: a physical line ending in an odd number of
+#     backslashes joins the next line (its leading whitespace stripped)
+#   - backslash escapes in keys and values, including \uXXXX
+#   - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+    printf "props.awk: %s\n", msg > "/dev/stderr"
+    exit 1
+}
+
+function hex_digit(c) {
+    return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \uXXXX is a UTF-16 code unit in Java.  Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,    out, i, n, c, code, j, d, ok) {
+    out = ""
+    n = length(s)
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (c != "\\") { out = out c; continue }
+        if (i == n) break
+        i++
+        c = substr(s, i, 1)
+        if (c == "u" && i + 4 <= n) {
+            code = 0
+            ok = 1
+            for (j = 1; j <= 4; j++) {
+                d = hex_digit(substr(s, i + j, 1))
+                if (d < 0) { ok = 0; break }
+                code = code * 16 + d
+            }
+            if (ok) {
+                i += 4
+                if (code <= 255) out = out sprintf("%c", code)
+                else out = out substr(s, i - 5, 6)
+                continue
+            }
+        }
+        if (c == "t") out = out "\t"
+        else if (c == "n") out = out "\n"
+        else if (c == "r") out = out "\r"
+        else if (c == "f") out = out "\f"
+        else out = out c
+    }
+    return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,    n, k) {
+    n = length(s)
+    k = 0
+    while (k < n && substr(s, n - k, 1) == "\\") k++
+    return k
+}
+
+function is_skipped(raw) {
+    return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,    n, i, c, esc, sep_at, rest) {
+    n = length(s)
+    esc = 0
+    sep_at = 0
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (esc) { esc = 0; continue }
+        if (c == "\\") { esc = 1; continue }
+        if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break 
}
+    }
+    if (sep_at == 0) {
+        K_RAW = s
+        V_RAW = ""
+        return
+    }
+    K_RAW = substr(s, 1, sep_at - 1)
+    rest = substr(s, sep_at)
+    c = substr(rest, 1, 1)
+    if (c == "=" || c == ":") {
+        rest = substr(rest, 2)
+    } else {
+        sub(/^[ \t]+/, "", rest)
+        c = substr(rest, 1, 1)
+        if (c == "=" || c == ":") rest = substr(rest, 2)
+    }
+    sub(/^[ \t]+/, "", rest)
+    V_RAW = rest
+}
+
+function shquote(s) {
+    gsub(/'/, "'\\''", s)
+    return "'" s "'"
+}
+
+# Load `file` into per-block arrays: one block per comment/blank line or
+# logical entry, spanning exactly the physical lines it occupies.
+function props_load(file,    raw, rc, nl, stripped, next_raw, start, logical) {
+    NLINES = 0
+    while ((rc = (getline raw < file)) > 0) {

Review Comment:
   Does not reproduce here: the helper re-scans each record for CR, LF and CRLF 
before parsing, so setting the first key of a three-key CR-only file leaves all 
three readable. Honest limit: this host has gawk 5.0.0, and neither Dockerfile 
installs gawk, so mawk in the image is untested locally. Head Docker CI run 
36620073649 is success.



##########
hugegraph-server/hugegraph-dist/docker/props.awk:
##########
@@ -0,0 +1,299 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means.  grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+#   PROPS_MODE=get  PROPS_KEY=K PROPS_FILE=F
+#       print the value of K's first logical definition
+#   PROPS_MODE=set  PROPS_KEY=K PROPS_FILE=F
+#       replace K's first definition in place, drop every other
+#       definition of K, append one when the file has none.  The new
+#       value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+#       variable, so secrets never appear in `ps` output or in awk's
+#       argv), and -v is not used for it so awk cannot mangle its
+#       backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+#   - '#' / '!' comments and blank lines
+#   - '=' / ':' / whitespace separators, with whitespace then an optional
+#     single '=' or ':' accepted as one separator
+#   - continuations: a physical line ending in an odd number of
+#     backslashes joins the next line (its leading whitespace stripped)
+#   - backslash escapes in keys and values, including \uXXXX
+#   - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+    printf "props.awk: %s\n", msg > "/dev/stderr"
+    exit 1
+}
+
+function hex_digit(c) {
+    return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \uXXXX is a UTF-16 code unit in Java.  Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,    out, i, n, c, code, j, d, ok) {
+    out = ""
+    n = length(s)
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (c != "\\") { out = out c; continue }
+        if (i == n) break
+        i++
+        c = substr(s, i, 1)
+        if (c == "u" && i + 4 <= n) {
+            code = 0
+            ok = 1
+            for (j = 1; j <= 4; j++) {
+                d = hex_digit(substr(s, i + j, 1))
+                if (d < 0) { ok = 0; break }
+                code = code * 16 + d
+            }
+            if (ok) {
+                i += 4
+                if (code <= 255) out = out sprintf("%c", code)
+                else out = out substr(s, i - 5, 6)
+                continue
+            }
+        }
+        if (c == "t") out = out "\t"
+        else if (c == "n") out = out "\n"
+        else if (c == "r") out = out "\r"
+        else if (c == "f") out = out "\f"
+        else out = out c
+    }
+    return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,    n, k) {
+    n = length(s)
+    k = 0
+    while (k < n && substr(s, n - k, 1) == "\\") k++
+    return k
+}
+
+function is_skipped(raw) {
+    return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,    n, i, c, esc, sep_at, rest) {
+    n = length(s)
+    esc = 0
+    sep_at = 0
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (esc) { esc = 0; continue }
+        if (c == "\\") { esc = 1; continue }
+        if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break 
}

Review Comment:
   No longer reproduces at head 0be7fde. Form feed now counts as separator 
whitespace in the key scan, the leading strip and the blank test, so that 
spelling reads as one property and get mode returns its class, exit 0. Added to 
the same suite group as the CR cases.



##########
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##########
@@ -0,0 +1,405 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator?  Prints exactly one of:
+#
+#   none      there is no top-level authentication mapping
+#   nameless  the mapping exists but names no authenticator class
+#   named     the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together.  Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+#   1. the mapping must sit at the indentation of the document root -- an
+#      `authentication:` nested under some other key belongs to that feature,
+#      not to the Gremlin server, while a root mapping written indented below a
+#      document marker still counts because the server reads it as the root;
+#   2. only a direct child `authenticator` counts -- a class reached through
+#      `authentication.config`, or through any other nested mapping, is not
+#      the server authenticator, because TinkerPop keeps `config` as its own
+#      map;
+#   3. `#` outside quotes starts a comment: text behind one is not content,
+#      and a comment-only line is neither a child nor the end of the mapping;
+#   4. in a flow mapping the key must sit at depth one between the braces, so
+#      `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+#      does not;
+#   5. a direct `authenticator` whose value is empty, `null` or `~` names no
+#      class -- the server reads the key, gets nothing and leaves
+#      authentication off, which is the nameless case that must be refused;
+#   6. a mapping is read to its end before it is answered, because the server
+#      sees the whole node: a direct `authenticator` defined twice is refused
+#      rather than settled by whoever met it first;
+#   6b. the file is read to its end, not to the first mapping, because two
+#      top-level `authentication` mappings resolve to the last one (or are
+#      rejected outright).  Answering from the first reported `named` for a
+#      server left on AllowAllAuthenticator by the empty second mapping, so a
+#      duplicate root mapping is refused rather than guessed at;
+#   7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+#      comment being stripped is line noise, not part of a key or a value.
+#      Reading `authentication:\r` as no key at all reported a Gremlin mapping
+#      that names a class as absent, which is the direction that leaves REST
+#      open while Gremlin authenticates.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,    i, n, c, q, prev) {
+    q = ""
+    prev = ""
+    n = length(s)
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (q != "") {
+            if (c == q) q = ""
+        } else if (is_quote(c)) {
+            q = c
+        } else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+            return rtrim(substr(s, 1, i - 1))
+        }
+        prev = c
+    }
+    return s
+}
+
+# How many whitespace characters open the line, i.e. its block nesting level.
+function indent_of(s,    i, n, c) {
+    n = length(s)
+    i = 1
+    while (i <= n) {
+        c = substr(s, i, 1)
+        if (c != " " && c != "\t") break
+        i++
+    }
+    return i - 1
+}
+
+# One layer of matching quotes off a key or scalar.
+function unquote(s,    f) {
+    s = trim(s)
+    if (length(s) >= 2) {
+        f = substr(s, 1, 1)
+        if ((f == apos() || f == dquo()) && substr(s, length(s), 1) == f)
+            return substr(s, 2, length(s) - 2)
+    }
+    return s
+}
+
+# Split `name: value` at the first colon outside quotes that is followed by end
+# of line or a space, which is what makes a colon inside `http://host` part of
+# the scalar.  Results go to K_TXT / V_TXT because awk returns one value.
+function split_pair(s,    i, n, c, q) {
+    q = ""
+    n = length(s)
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (q != "") {
+            if (c == q) q = ""
+            continue
+        }
+        if (is_quote(c)) { q = c; continue }
+        if (c != ":") continue
+        if (i == n || substr(s, i + 1, 1) ~ /^[ \t]/) {
+            K_TXT = rtrim(substr(s, 1, i - 1))
+            V_TXT = ltrim(substr(s, i + 1))
+            return 1
+        }
+    }
+    return 0
+}
+
+function names_authenticator(k) { return unquote(k) == "authenticator" }
+
+# An authenticator entry only counts when it actually names a class, and the
+# answer has to be what snakeyaml hands the server rather than what the bytes
+# look like.  The unsafe direction is `named` for a config that leaves Gremlin
+# on AllowAllAuthenticator while REST enforces, so anything this scanner cannot
+# resolve to a class is refused instead of guessed at:
+#
+#   - a plain scalar that resolves to null in any spelling, and YAML resolves
+#     null case-insensitively (null, Null, NULL, nUll) as well as to ~, names
+#     no class;
+#   - a leading `!` makes the tag, not the text, decide the type: !!null is the
+#     explicit spelling of empty and every other tag is a type not resolvable
+#     here, so neither counts;
+#   - a quoted scalar is a string and never null, but `""` and the empty single
+#     quoted form are the empty string, and loadAuthenticator("") returns null,
+#     which is the same no-authenticator state;
+#   - `&label value` is an anchor: the label is not part of the value, so the
+#     text after it decides, and `&label` alone anchors an empty node, which is
+#     the explicit spelling of null;
+#   - `*label` is an alias whose class lives in another node.  This scanner
+#     does not resolve nodes, so an alias is refused rather than read as a
+#     class name -- `authenticator: &noAuth null` is a valid document whose
+#     value is null, and calling it named is the exact mistake this guards.
+#   - an unterminated quote is not a scalar at all.
+function names_class(v,    first, last, body, rest) {
+    v = trim(v)
+    if (v == "") return 0
+    first = substr(v, 1, 1)
+    if (first == "!") return 0
+    if (first == "*") return 0
+    if (first == "&") {
+        rest = trim(substr(v, 2))
+        sub(/^[^ \t]*/, "", rest)
+        return names_class(trim(rest))
+    }
+    if (first == apos() || first == dquo()) {
+        if (length(v) < 2) return 0
+        last = substr(v, length(v), 1)
+        if (last != first) return 0
+        body = trim(substr(v, 2, length(v) - 2))
+        return body != ""
+    }
+    if (v == "~") return 0
+    if (tolower(v) == "null") return 0
+    return 1
+}
+
+# The answer for the mapping read so far, for both the block and the flow form.
+# AUTH_SEEN counts direct `authenticator` children and AUTH_NAMED remembers
+# whether the last one named a class.  A key defined twice has no answer this
+# scanner can give honestly: snakeyaml either keeps the last value or, with
+# unique keys enforced, rejects the document and the server never starts.
+# Either way the operator has to be told which line to fix, so the duplicate is
+# reported on stderr and the mapping is refused through the nameless state,
+# which check_auth_sides stops the boot on and enable-auth.sh will not append
+# beside.
+function auth_state(    msg) {
+    if (AUTH_SEEN > 1) {
+        msg = "yamlscan.awk: a mapping with " AUTH_SEEN " direct authenticator 
entries"
+        print msg > "/dev/stderr"
+        print "cannot be answered here: the server takes the last one, or 
rejects the file." > "/dev/stderr"
+        print "Remove the duplicate authenticator entry from 
gremlin-server.yaml." > "/dev/stderr"
+        return "nameless"
+    }
+    if (AUTH_SEEN == 1 && AUTH_NAMED) return "named"
+    return "nameless"
+}
+
+# The answer when the file carries more than one top-level `authentication`
+# mapping.  SnakeYAML either takes the last one or, with unique keys enforced,
+# rejects the document and the server never starts -- either way the effective
+# mapping is not the first the scanner met, so this cannot be answered here.
+# Report it on stderr and refuse through the nameless state, exactly like the
+# duplicate-authenticator case above, so check_auth_sides stops the boot.
+function duplicate_root(    msg) {
+    msg = "yamlscan.awk: " AUTH_BLOCKS " top-level authentication mappings"
+    print msg > "/dev/stderr"
+    print "cannot be answered here: the server takes the last one, or rejects 
the file." > "/dev/stderr"
+    print "Keep a single top-level authentication mapping in 
gremlin-server.yaml." > "/dev/stderr"
+    return "nameless"
+}
+
+# Feed one line of a flow collection to the brace scanner.  DEPTH counts open
+# collections; keys and values are only read at depth one, which is what makes
+# a nested mapping under `config` invisible to it.  A direct authenticator seen
+# at depth one is recorded for auth_state.  Returns 1 once the outermost
+# collection has closed.
+function scan_flow(s,    i, n, c, q, esc) {
+    n = length(s)
+    q = ""
+    esc = 0
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (q != "") {
+            # Every byte inside the quotes belongs to the scalar, delimiters
+            # included; unquote and names_class take the quotes off.  Dropping
+            # the value here is what made {authenticator: "org.A"} read as
+            # nameless and refuse a valid mounted config.  A backslash escapes
+            # the next byte in a double quoted scalar only -- in a single
+            # quoted one the way out is a doubled quote, which this loop
+            # already gets right because the first one closes and the next
+            # reopens, and the pair still counts as content.
+            if (FST == "key") CUR = CUR c
+            else if (FST == "val") CUR_VAL = CUR_VAL c
+            if (esc) esc = 0
+            else if (q == dquo() && c == "\\") esc = 1
+            else if (c == q) q = ""
+            continue
+        }
+        if (is_quote(c)) {
+            q = c
+            if (FST == "key") CUR = CUR c
+            else if (FST == "val") CUR_VAL = CUR_VAL c
+            continue
+        }
+        if (c == "{" || c == "[") {
+            DEPTH++
+            CUR = ""
+            # Past depth one the whole entry is nested content and is skipped,
+            # including an authenticator key inside it.
+            FST = (DEPTH == 1 ? "key" : "skip")
+            continue
+        }
+        if (c == "}" || c == "]") {
+            if (DEPTH == 1 && FST == "val") commit_val()
+            DEPTH--
+            CUR = ""
+            if (DEPTH == 0) { FST = "key"; return 1 }
+            FST = "skip"
+            continue
+        }
+        if (c == "\r") continue
+        if (DEPTH != 1) continue
+        if (c == ":") {
+            if (FST == "key") {
+                CUR_KEY = CUR
+                CUR_VAL = ""
+                FST = "val"
+            }
+            CUR = ""
+            continue
+        }
+        if (c == ",") {
+            if (FST == "val") commit_val()
+            FST = "key"
+            CUR = ""
+            continue
+        }
+        if (c == " " || c == "\t") {
+            # A space ends an unquoted key but never carries a value byte.
+            continue
+        }
+        if (FST == "key") CUR = CUR c
+        else if (FST == "val") CUR_VAL = CUR_VAL c
+    }
+    return 0
+}
+
+# Close out the depth-one entry that was being read when a `,` or `}` arrived.
+function commit_val(    k) {
+    k = CUR_KEY
+    if (names_authenticator(k)) {
+        AUTH_SEEN++
+        AUTH_NAMED = names_class(CUR_VAL)
+    }
+}
+
+BEGIN {
+    DEPTH = 0
+    FST = "key"
+    CUR = ""
+    CUR_KEY = ""
+    CUR_VAL = ""
+    AUTH_SEEN = 0
+    AUTH_NAMED = 0
+    ROOT_IND = -1
+    AUTH_BLOCKS = 0
+    in_auth = 0
+    child = -1
+    flow = 0
+    RESULT = ""
+}
+
+{
+    # A CR here is the terminator of a CRLF line, not content: YAML ends a line
+    # at either byte, so `authentication:\r` is the key line and leaving the CR
+    # on it made split_pair see no colon followed by end of line, which 
reported
+    # a whole mapping as absent.
+    line = strip_comment($0)
+    sub(/[ \t\r]+$/, "", line)
+    if (trim(line) == "") next
+
+    ind = indent_of(line)
+
+    # The indentation of the first real content line is the root indentation.
+    # A document marker or a stray scalar opens no mapping, so keep looking
+    # until a key:value line is met.  Every comparison below is against that
+    # indentation rather than column 0, so a root mapping written indented --
+    # valid to Settings.read() -- is recognized, while an `authentication:`
+    # nested under some other key is still not mistaken for the Gremlin one.
+    if (ROOT_IND < 0) {
+        if (!split_pair(line)) next

Review Comment:
   Still real, and this is a choice I want your call on. head 0be7fde 
deliberately refuses a document that opens as one root flow mapping 
(yamlscan.awk line 776): answering none for it was exactly what left REST open 
beside an authenticating Gremlin. Measured: the scanner refuses, while 
SnakeYAML 1.27 reads your authenticator. Say prefer-parsing and I will walk the 
flow.



##########
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##########
@@ -0,0 +1,405 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator?  Prints exactly one of:
+#
+#   none      there is no top-level authentication mapping
+#   nameless  the mapping exists but names no authenticator class
+#   named     the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together.  Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+#   1. the mapping must sit at the indentation of the document root -- an
+#      `authentication:` nested under some other key belongs to that feature,
+#      not to the Gremlin server, while a root mapping written indented below a
+#      document marker still counts because the server reads it as the root;
+#   2. only a direct child `authenticator` counts -- a class reached through
+#      `authentication.config`, or through any other nested mapping, is not
+#      the server authenticator, because TinkerPop keeps `config` as its own
+#      map;
+#   3. `#` outside quotes starts a comment: text behind one is not content,
+#      and a comment-only line is neither a child nor the end of the mapping;
+#   4. in a flow mapping the key must sit at depth one between the braces, so
+#      `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+#      does not;
+#   5. a direct `authenticator` whose value is empty, `null` or `~` names no
+#      class -- the server reads the key, gets nothing and leaves
+#      authentication off, which is the nameless case that must be refused;
+#   6. a mapping is read to its end before it is answered, because the server
+#      sees the whole node: a direct `authenticator` defined twice is refused
+#      rather than settled by whoever met it first;
+#   6b. the file is read to its end, not to the first mapping, because two
+#      top-level `authentication` mappings resolve to the last one (or are
+#      rejected outright).  Answering from the first reported `named` for a
+#      server left on AllowAllAuthenticator by the empty second mapping, so a
+#      duplicate root mapping is refused rather than guessed at;
+#   7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+#      comment being stripped is line noise, not part of a key or a value.
+#      Reading `authentication:\r` as no key at all reported a Gremlin mapping
+#      that names a class as absent, which is the direction that leaves REST
+#      open while Gremlin authenticates.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,    i, n, c, q, prev) {
+    q = ""
+    prev = ""
+    n = length(s)
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (q != "") {
+            if (c == q) q = ""
+        } else if (is_quote(c)) {
+            q = c
+        } else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+            return rtrim(substr(s, 1, i - 1))
+        }
+        prev = c
+    }
+    return s
+}
+
+# How many whitespace characters open the line, i.e. its block nesting level.
+function indent_of(s,    i, n, c) {
+    n = length(s)
+    i = 1
+    while (i <= n) {
+        c = substr(s, i, 1)
+        if (c != " " && c != "\t") break
+        i++
+    }
+    return i - 1
+}
+
+# One layer of matching quotes off a key or scalar.
+function unquote(s,    f) {
+    s = trim(s)
+    if (length(s) >= 2) {
+        f = substr(s, 1, 1)
+        if ((f == apos() || f == dquo()) && substr(s, length(s), 1) == f)
+            return substr(s, 2, length(s) - 2)
+    }
+    return s
+}
+
+# Split `name: value` at the first colon outside quotes that is followed by end
+# of line or a space, which is what makes a colon inside `http://host` part of
+# the scalar.  Results go to K_TXT / V_TXT because awk returns one value.
+function split_pair(s,    i, n, c, q) {
+    q = ""
+    n = length(s)
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (q != "") {
+            if (c == q) q = ""
+            continue
+        }
+        if (is_quote(c)) { q = c; continue }
+        if (c != ":") continue
+        if (i == n || substr(s, i + 1, 1) ~ /^[ \t]/) {
+            K_TXT = rtrim(substr(s, 1, i - 1))
+            V_TXT = ltrim(substr(s, i + 1))
+            return 1
+        }
+    }
+    return 0
+}
+
+function names_authenticator(k) { return unquote(k) == "authenticator" }
+
+# An authenticator entry only counts when it actually names a class, and the
+# answer has to be what snakeyaml hands the server rather than what the bytes
+# look like.  The unsafe direction is `named` for a config that leaves Gremlin
+# on AllowAllAuthenticator while REST enforces, so anything this scanner cannot
+# resolve to a class is refused instead of guessed at:
+#
+#   - a plain scalar that resolves to null in any spelling, and YAML resolves
+#     null case-insensitively (null, Null, NULL, nUll) as well as to ~, names
+#     no class;
+#   - a leading `!` makes the tag, not the text, decide the type: !!null is the
+#     explicit spelling of empty and every other tag is a type not resolvable
+#     here, so neither counts;
+#   - a quoted scalar is a string and never null, but `""` and the empty single
+#     quoted form are the empty string, and loadAuthenticator("") returns null,
+#     which is the same no-authenticator state;
+#   - `&label value` is an anchor: the label is not part of the value, so the
+#     text after it decides, and `&label` alone anchors an empty node, which is
+#     the explicit spelling of null;
+#   - `*label` is an alias whose class lives in another node.  This scanner
+#     does not resolve nodes, so an alias is refused rather than read as a
+#     class name -- `authenticator: &noAuth null` is a valid document whose
+#     value is null, and calling it named is the exact mistake this guards.
+#   - an unterminated quote is not a scalar at all.
+function names_class(v,    first, last, body, rest) {
+    v = trim(v)
+    if (v == "") return 0
+    first = substr(v, 1, 1)
+    if (first == "!") return 0
+    if (first == "*") return 0
+    if (first == "&") {
+        rest = trim(substr(v, 2))
+        sub(/^[^ \t]*/, "", rest)
+        return names_class(trim(rest))
+    }
+    if (first == apos() || first == dquo()) {
+        if (length(v) < 2) return 0
+        last = substr(v, length(v), 1)
+        if (last != first) return 0
+        body = trim(substr(v, 2, length(v) - 2))
+        return body != ""
+    }
+    if (v == "~") return 0
+    if (tolower(v) == "null") return 0
+    return 1
+}
+
+# The answer for the mapping read so far, for both the block and the flow form.
+# AUTH_SEEN counts direct `authenticator` children and AUTH_NAMED remembers
+# whether the last one named a class.  A key defined twice has no answer this
+# scanner can give honestly: snakeyaml either keeps the last value or, with
+# unique keys enforced, rejects the document and the server never starts.
+# Either way the operator has to be told which line to fix, so the duplicate is
+# reported on stderr and the mapping is refused through the nameless state,
+# which check_auth_sides stops the boot on and enable-auth.sh will not append
+# beside.
+function auth_state(    msg) {
+    if (AUTH_SEEN > 1) {
+        msg = "yamlscan.awk: a mapping with " AUTH_SEEN " direct authenticator 
entries"
+        print msg > "/dev/stderr"
+        print "cannot be answered here: the server takes the last one, or 
rejects the file." > "/dev/stderr"
+        print "Remove the duplicate authenticator entry from 
gremlin-server.yaml." > "/dev/stderr"
+        return "nameless"
+    }
+    if (AUTH_SEEN == 1 && AUTH_NAMED) return "named"
+    return "nameless"
+}
+
+# The answer when the file carries more than one top-level `authentication`
+# mapping.  SnakeYAML either takes the last one or, with unique keys enforced,
+# rejects the document and the server never starts -- either way the effective
+# mapping is not the first the scanner met, so this cannot be answered here.
+# Report it on stderr and refuse through the nameless state, exactly like the
+# duplicate-authenticator case above, so check_auth_sides stops the boot.
+function duplicate_root(    msg) {
+    msg = "yamlscan.awk: " AUTH_BLOCKS " top-level authentication mappings"
+    print msg > "/dev/stderr"
+    print "cannot be answered here: the server takes the last one, or rejects 
the file." > "/dev/stderr"
+    print "Keep a single top-level authentication mapping in 
gremlin-server.yaml." > "/dev/stderr"
+    return "nameless"
+}
+
+# Feed one line of a flow collection to the brace scanner.  DEPTH counts open
+# collections; keys and values are only read at depth one, which is what makes
+# a nested mapping under `config` invisible to it.  A direct authenticator seen
+# at depth one is recorded for auth_state.  Returns 1 once the outermost
+# collection has closed.
+function scan_flow(s,    i, n, c, q, esc) {
+    n = length(s)
+    q = ""
+    esc = 0
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (q != "") {
+            # Every byte inside the quotes belongs to the scalar, delimiters
+            # included; unquote and names_class take the quotes off.  Dropping
+            # the value here is what made {authenticator: "org.A"} read as
+            # nameless and refuse a valid mounted config.  A backslash escapes
+            # the next byte in a double quoted scalar only -- in a single
+            # quoted one the way out is a doubled quote, which this loop
+            # already gets right because the first one closes and the next
+            # reopens, and the pair still counts as content.
+            if (FST == "key") CUR = CUR c
+            else if (FST == "val") CUR_VAL = CUR_VAL c
+            if (esc) esc = 0
+            else if (q == dquo() && c == "\\") esc = 1
+            else if (c == q) q = ""
+            continue
+        }
+        if (is_quote(c)) {
+            q = c
+            if (FST == "key") CUR = CUR c
+            else if (FST == "val") CUR_VAL = CUR_VAL c
+            continue
+        }
+        if (c == "{" || c == "[") {
+            DEPTH++
+            CUR = ""
+            # Past depth one the whole entry is nested content and is skipped,
+            # including an authenticator key inside it.
+            FST = (DEPTH == 1 ? "key" : "skip")
+            continue
+        }
+        if (c == "}" || c == "]") {
+            if (DEPTH == 1 && FST == "val") commit_val()
+            DEPTH--
+            CUR = ""
+            if (DEPTH == 0) { FST = "key"; return 1 }
+            FST = "skip"
+            continue
+        }
+        if (c == "\r") continue
+        if (DEPTH != 1) continue
+        if (c == ":") {
+            if (FST == "key") {
+                CUR_KEY = CUR
+                CUR_VAL = ""
+                FST = "val"
+            }
+            CUR = ""
+            continue
+        }
+        if (c == ",") {
+            if (FST == "val") commit_val()
+            FST = "key"
+            CUR = ""
+            continue
+        }
+        if (c == " " || c == "\t") {
+            # A space ends an unquoted key but never carries a value byte.
+            continue
+        }
+        if (FST == "key") CUR = CUR c
+        else if (FST == "val") CUR_VAL = CUR_VAL c
+    }
+    return 0
+}
+
+# Close out the depth-one entry that was being read when a `,` or `}` arrived.
+function commit_val(    k) {
+    k = CUR_KEY
+    if (names_authenticator(k)) {
+        AUTH_SEEN++
+        AUTH_NAMED = names_class(CUR_VAL)
+    }
+}
+
+BEGIN {
+    DEPTH = 0
+    FST = "key"
+    CUR = ""
+    CUR_KEY = ""
+    CUR_VAL = ""
+    AUTH_SEEN = 0
+    AUTH_NAMED = 0
+    ROOT_IND = -1
+    AUTH_BLOCKS = 0
+    in_auth = 0
+    child = -1
+    flow = 0
+    RESULT = ""
+}
+
+{
+    # A CR here is the terminator of a CRLF line, not content: YAML ends a line
+    # at either byte, so `authentication:\r` is the key line and leaving the CR
+    # on it made split_pair see no colon followed by end of line, which 
reported
+    # a whole mapping as absent.
+    line = strip_comment($0)
+    sub(/[ \t\r]+$/, "", line)
+    if (trim(line) == "") next
+
+    ind = indent_of(line)
+
+    # The indentation of the first real content line is the root indentation.
+    # A document marker or a stray scalar opens no mapping, so keep looking
+    # until a key:value line is met.  Every comparison below is against that
+    # indentation rather than column 0, so a root mapping written indented --
+    # valid to Settings.read() -- is recognized, while an `authentication:`
+    # nested under some other key is still not mistaken for the Gremlin one.
+    if (ROOT_IND < 0) {
+        if (!split_pair(line)) next
+        ROOT_IND = ind
+    } else if (ind == ROOT_IND && in_auth) {

Review Comment:
   No longer reproduces at head 0be7fde. The root-sibling branch that closed 
the mapping now checks for an open flow first, so the closing brace is consumed 
and its last pair committed: your three-line fixture answers named, and the 
class-less variant still answers nameless rather than passing silently.



##########
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##########
@@ -0,0 +1,405 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator?  Prints exactly one of:
+#
+#   none      there is no top-level authentication mapping
+#   nameless  the mapping exists but names no authenticator class
+#   named     the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together.  Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+#   1. the mapping must sit at the indentation of the document root -- an
+#      `authentication:` nested under some other key belongs to that feature,
+#      not to the Gremlin server, while a root mapping written indented below a
+#      document marker still counts because the server reads it as the root;
+#   2. only a direct child `authenticator` counts -- a class reached through
+#      `authentication.config`, or through any other nested mapping, is not
+#      the server authenticator, because TinkerPop keeps `config` as its own
+#      map;
+#   3. `#` outside quotes starts a comment: text behind one is not content,
+#      and a comment-only line is neither a child nor the end of the mapping;
+#   4. in a flow mapping the key must sit at depth one between the braces, so
+#      `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+#      does not;
+#   5. a direct `authenticator` whose value is empty, `null` or `~` names no
+#      class -- the server reads the key, gets nothing and leaves
+#      authentication off, which is the nameless case that must be refused;
+#   6. a mapping is read to its end before it is answered, because the server
+#      sees the whole node: a direct `authenticator` defined twice is refused
+#      rather than settled by whoever met it first;
+#   6b. the file is read to its end, not to the first mapping, because two
+#      top-level `authentication` mappings resolve to the last one (or are
+#      rejected outright).  Answering from the first reported `named` for a
+#      server left on AllowAllAuthenticator by the empty second mapping, so a
+#      duplicate root mapping is refused rather than guessed at;
+#   7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+#      comment being stripped is line noise, not part of a key or a value.
+#      Reading `authentication:\r` as no key at all reported a Gremlin mapping
+#      that names a class as absent, which is the direction that leaves REST
+#      open while Gremlin authenticates.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,    i, n, c, q, prev) {
+    q = ""
+    prev = ""
+    n = length(s)
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (q != "") {
+            if (c == q) q = ""
+        } else if (is_quote(c)) {
+            q = c
+        } else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+            return rtrim(substr(s, 1, i - 1))
+        }
+        prev = c
+    }
+    return s
+}
+
+# How many whitespace characters open the line, i.e. its block nesting level.
+function indent_of(s,    i, n, c) {
+    n = length(s)
+    i = 1
+    while (i <= n) {
+        c = substr(s, i, 1)
+        if (c != " " && c != "\t") break
+        i++
+    }
+    return i - 1
+}
+
+# One layer of matching quotes off a key or scalar.
+function unquote(s,    f) {
+    s = trim(s)
+    if (length(s) >= 2) {
+        f = substr(s, 1, 1)
+        if ((f == apos() || f == dquo()) && substr(s, length(s), 1) == f)
+            return substr(s, 2, length(s) - 2)
+    }
+    return s
+}
+
+# Split `name: value` at the first colon outside quotes that is followed by end
+# of line or a space, which is what makes a colon inside `http://host` part of
+# the scalar.  Results go to K_TXT / V_TXT because awk returns one value.
+function split_pair(s,    i, n, c, q) {
+    q = ""
+    n = length(s)
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (q != "") {
+            if (c == q) q = ""
+            continue
+        }
+        if (is_quote(c)) { q = c; continue }
+        if (c != ":") continue
+        if (i == n || substr(s, i + 1, 1) ~ /^[ \t]/) {
+            K_TXT = rtrim(substr(s, 1, i - 1))
+            V_TXT = ltrim(substr(s, i + 1))
+            return 1
+        }
+    }
+    return 0
+}
+
+function names_authenticator(k) { return unquote(k) == "authenticator" }
+
+# An authenticator entry only counts when it actually names a class, and the
+# answer has to be what snakeyaml hands the server rather than what the bytes
+# look like.  The unsafe direction is `named` for a config that leaves Gremlin
+# on AllowAllAuthenticator while REST enforces, so anything this scanner cannot
+# resolve to a class is refused instead of guessed at:
+#
+#   - a plain scalar that resolves to null in any spelling, and YAML resolves
+#     null case-insensitively (null, Null, NULL, nUll) as well as to ~, names
+#     no class;
+#   - a leading `!` makes the tag, not the text, decide the type: !!null is the
+#     explicit spelling of empty and every other tag is a type not resolvable
+#     here, so neither counts;
+#   - a quoted scalar is a string and never null, but `""` and the empty single
+#     quoted form are the empty string, and loadAuthenticator("") returns null,
+#     which is the same no-authenticator state;
+#   - `&label value` is an anchor: the label is not part of the value, so the
+#     text after it decides, and `&label` alone anchors an empty node, which is
+#     the explicit spelling of null;
+#   - `*label` is an alias whose class lives in another node.  This scanner
+#     does not resolve nodes, so an alias is refused rather than read as a
+#     class name -- `authenticator: &noAuth null` is a valid document whose
+#     value is null, and calling it named is the exact mistake this guards.
+#   - an unterminated quote is not a scalar at all.
+function names_class(v,    first, last, body, rest) {
+    v = trim(v)
+    if (v == "") return 0
+    first = substr(v, 1, 1)
+    if (first == "!") return 0
+    if (first == "*") return 0
+    if (first == "&") {
+        rest = trim(substr(v, 2))
+        sub(/^[^ \t]*/, "", rest)
+        return names_class(trim(rest))
+    }
+    if (first == apos() || first == dquo()) {
+        if (length(v) < 2) return 0
+        last = substr(v, length(v), 1)
+        if (last != first) return 0
+        body = trim(substr(v, 2, length(v) - 2))
+        return body != ""
+    }
+    if (v == "~") return 0
+    if (tolower(v) == "null") return 0
+    return 1
+}
+
+# The answer for the mapping read so far, for both the block and the flow form.
+# AUTH_SEEN counts direct `authenticator` children and AUTH_NAMED remembers
+# whether the last one named a class.  A key defined twice has no answer this
+# scanner can give honestly: snakeyaml either keeps the last value or, with
+# unique keys enforced, rejects the document and the server never starts.
+# Either way the operator has to be told which line to fix, so the duplicate is
+# reported on stderr and the mapping is refused through the nameless state,
+# which check_auth_sides stops the boot on and enable-auth.sh will not append
+# beside.
+function auth_state(    msg) {
+    if (AUTH_SEEN > 1) {
+        msg = "yamlscan.awk: a mapping with " AUTH_SEEN " direct authenticator 
entries"
+        print msg > "/dev/stderr"
+        print "cannot be answered here: the server takes the last one, or 
rejects the file." > "/dev/stderr"
+        print "Remove the duplicate authenticator entry from 
gremlin-server.yaml." > "/dev/stderr"
+        return "nameless"
+    }
+    if (AUTH_SEEN == 1 && AUTH_NAMED) return "named"
+    return "nameless"
+}
+
+# The answer when the file carries more than one top-level `authentication`
+# mapping.  SnakeYAML either takes the last one or, with unique keys enforced,
+# rejects the document and the server never starts -- either way the effective
+# mapping is not the first the scanner met, so this cannot be answered here.
+# Report it on stderr and refuse through the nameless state, exactly like the
+# duplicate-authenticator case above, so check_auth_sides stops the boot.
+function duplicate_root(    msg) {
+    msg = "yamlscan.awk: " AUTH_BLOCKS " top-level authentication mappings"
+    print msg > "/dev/stderr"
+    print "cannot be answered here: the server takes the last one, or rejects 
the file." > "/dev/stderr"
+    print "Keep a single top-level authentication mapping in 
gremlin-server.yaml." > "/dev/stderr"
+    return "nameless"
+}
+
+# Feed one line of a flow collection to the brace scanner.  DEPTH counts open
+# collections; keys and values are only read at depth one, which is what makes
+# a nested mapping under `config` invisible to it.  A direct authenticator seen
+# at depth one is recorded for auth_state.  Returns 1 once the outermost
+# collection has closed.
+function scan_flow(s,    i, n, c, q, esc) {
+    n = length(s)
+    q = ""
+    esc = 0
+    for (i = 1; i <= n; i++) {
+        c = substr(s, i, 1)
+        if (q != "") {
+            # Every byte inside the quotes belongs to the scalar, delimiters
+            # included; unquote and names_class take the quotes off.  Dropping
+            # the value here is what made {authenticator: "org.A"} read as
+            # nameless and refuse a valid mounted config.  A backslash escapes
+            # the next byte in a double quoted scalar only -- in a single
+            # quoted one the way out is a doubled quote, which this loop
+            # already gets right because the first one closes and the next
+            # reopens, and the pair still counts as content.
+            if (FST == "key") CUR = CUR c
+            else if (FST == "val") CUR_VAL = CUR_VAL c
+            if (esc) esc = 0
+            else if (q == dquo() && c == "\\") esc = 1
+            else if (c == q) q = ""
+            continue
+        }
+        if (is_quote(c)) {
+            q = c
+            if (FST == "key") CUR = CUR c
+            else if (FST == "val") CUR_VAL = CUR_VAL c
+            continue
+        }
+        if (c == "{" || c == "[") {
+            DEPTH++
+            CUR = ""
+            # Past depth one the whole entry is nested content and is skipped,
+            # including an authenticator key inside it.
+            FST = (DEPTH == 1 ? "key" : "skip")
+            continue
+        }
+        if (c == "}" || c == "]") {
+            if (DEPTH == 1 && FST == "val") commit_val()
+            DEPTH--
+            CUR = ""
+            if (DEPTH == 0) { FST = "key"; return 1 }
+            FST = "skip"
+            continue
+        }
+        if (c == "\r") continue
+        if (DEPTH != 1) continue
+        if (c == ":") {
+            if (FST == "key") {
+                CUR_KEY = CUR
+                CUR_VAL = ""
+                FST = "val"
+            }
+            CUR = ""
+            continue
+        }
+        if (c == ",") {
+            if (FST == "val") commit_val()
+            FST = "key"
+            CUR = ""
+            continue
+        }
+        if (c == " " || c == "\t") {
+            # A space ends an unquoted key but never carries a value byte.
+            continue
+        }
+        if (FST == "key") CUR = CUR c
+        else if (FST == "val") CUR_VAL = CUR_VAL c
+    }
+    return 0
+}
+
+# Close out the depth-one entry that was being read when a `,` or `}` arrived.
+function commit_val(    k) {
+    k = CUR_KEY
+    if (names_authenticator(k)) {
+        AUTH_SEEN++
+        AUTH_NAMED = names_class(CUR_VAL)
+    }
+}
+
+BEGIN {
+    DEPTH = 0
+    FST = "key"
+    CUR = ""
+    CUR_KEY = ""
+    CUR_VAL = ""
+    AUTH_SEEN = 0
+    AUTH_NAMED = 0
+    ROOT_IND = -1
+    AUTH_BLOCKS = 0
+    in_auth = 0
+    child = -1
+    flow = 0
+    RESULT = ""
+}
+
+{
+    # A CR here is the terminator of a CRLF line, not content: YAML ends a line
+    # at either byte, so `authentication:\r` is the key line and leaving the CR
+    # on it made split_pair see no colon followed by end of line, which 
reported
+    # a whole mapping as absent.
+    line = strip_comment($0)
+    sub(/[ \t\r]+$/, "", line)

Review Comment:
   Does not reproduce here: every record is split on CR before parsing, so a 
bare-CR document presents its lines separately and the root key is met; your 
shape answers named, terminated or not. Same limit as the props case: gawk 
here, mawk in the image untested locally, no container boot possible on this 
host.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to