Lastly (for today), I have another use case that i...
# talk-oathkeeper
w
Lastly (for today), I have another use case that is now possible to implement because of the enhancements I've listed above; regexp named groups specifically. I have a rule that captures a named group that I want to make available to the
MatchContext
via a new field:
RegexpNamedCaptureGroups
. Currently,
MatchContext
has a field:
RegexpCaptureGroups
but this field only (naively?) sets capture groups to a
[]string
with no reference to the regexp group the capture is associated. My enhancement adds
RegexpNamedCaptureGroups map[string]string
to
MatchContext
and populates the map based on the groups captured and their values. The groups include all numbered and named groups; similar to
FindStringSubmatch
, group "0" is skipped. The result map can be used to look up "named" as well as numerical e.g., "1" capture groups. These can then be accessed within
text {{ print "templates" }}
within config files. I feel this can be carried over into use within jsonnet. As an example, a config can contain a regexp url match rule such as:
<https://example.com/><<(?<id>[-0-9a-fA-F]+)>>
and within that same rule, any text templates can refer to
.MatchContext.RegexpNamedCaptureGroups.id
or
index .MatchContext.RegexpNamedCaptureGroups "id"
. My changes enable this construct.