Skip to content

Commit

Permalink
Fixes custom action parsing (#309)
Browse files Browse the repository at this point in the history
Signed-off-by: Clay Downs <[email protected]>
  • Loading branch information
downsrob authored Mar 15, 2022
1 parent 6d93359 commit 901d887
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class ISMActionsParser private constructor() {
Action.CUSTOM_ACTION_FIELD -> {
// The "custom" wrapper allows extensions to create arbitrary actions without updating the config mappings
// We consume the full custom wrapper and parse the action in this step
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp)
val customActionType = xcp.currentName()
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp)
val customActionType = xcp.currentName()
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp)
action = parseAction(xcp, totalActions, customActionType)
XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, xcp.nextToken(), xcp)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,19 @@ class ISMActionsParserTests : OpenSearchTestCase() {
assertEquals("Round tripping custom action doesn't work", customAction.convertToMap(), parsedCustomAction.convertToMap())
assertTrue("Custom action did not have custom keyword after parsing", parsedCustomAction.convertToMap().containsKey("custom"))
}

fun `test parsing custom action with custom flag`() {
val customActionParser = SampleCustomActionParser()
ISMActionsParser.instance.addParser(customActionParser, extensionName)
val customAction = SampleCustomActionParser.SampleCustomAction(randomInt(), 0)
customAction.customAction = true

val customActionString = "{\"retry\":{\"count\":3,\"backoff\":\"exponential\",\"delay\":\"1m\"},\"custom\": {\"some_custom_action\":{\"some_int_field\":${customAction.someInt}}}}"
val parser = XContentType.JSON.xContent().createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, customActionString)
parser.nextToken()
val parsedCustomAction = ISMActionsParser.instance.parse(parser, 1)
assertTrue("Action was not set to be custom after parsing", parsedCustomAction.customAction)
assertEquals("Round tripping custom action doesn't work", customAction.convertToMap(), parsedCustomAction.convertToMap())
assertTrue("Custom action did not have custom keyword after parsing", parsedCustomAction.convertToMap().containsKey("custom"))
}
}

0 comments on commit 901d887

Please sign in to comment.