in src/main/software/amazon/event/ruler/RuleCompiler.java [188:244]
private static void writeRules(final Map<String, List<Patterns>> rule,
final String name,
final JsonParser parser,
final boolean withQuotes) throws IOException {
JsonToken token;
final List<Patterns> values = new ArrayList<>();
while ((token = parser.nextToken()) != JsonToken.END_ARRAY) {
switch (token) {
case START_OBJECT:
values.add(processMatchExpression(parser));
break;
case VALUE_STRING:
final String toMatch = parser.getText();
final Range ipRange = CIDR.ipToRangeIfPossible(toMatch);
if (ipRange != null) {
values.add(ipRange);
} else if (withQuotes) {
values.add(Patterns.exactMatch('"' + toMatch + '"'));
} else {
values.add(Patterns.exactMatch(toMatch));
}
break;
case VALUE_NUMBER_FLOAT:
case VALUE_NUMBER_INT:
/*
* If the rule specifies a match to a number, we'll insert matchers for both the
* literal expression and the ComparableNumber form. But the number might not
* be representble as a ComparableNumber, for example an AWS account number,
* so make that condition survivable.
*/
try {
values.add(Patterns.numericEquals(parser.getText()));
} catch (Exception e) {
// no-op
}
values.add(Patterns.exactMatch(parser.getText()));
break;
case VALUE_NULL:
case VALUE_TRUE:
case VALUE_FALSE:
values.add(Patterns.exactMatch(parser.getText()));
break;
default:
barf(parser, "Match value must be String, number, true, false, or null");
}
}
if (values.isEmpty()) {
barf(parser, "Empty arrays are not allowed");
}
rule.put(name, values);
}