From dab71ace972d5574822c7bbf40c4a9c7f1e59089 Mon Sep 17 00:00:00 2001 From: Luis Toledo Date: Mon, 29 Jan 2024 21:15:24 -0300 Subject: [PATCH 1/2] use toString instead to asText() when the string is parsed --- .../plugins/logging/JsonLogFilter.groovy | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy b/src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy index 3b6be39..29ddce6 100644 --- a/src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy +++ b/src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy @@ -94,15 +94,15 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre void processJson(final PluginLoggingContext context){ try{ - Scope rootScope = Scope.newEmptyScope(); - BuiltinFunctionLoader.getInstance().loadFunctions(Versions.JQ_1_6, rootScope); + Scope rootScope = Scope.newEmptyScope() + BuiltinFunctionLoader.getInstance().loadFunctions(Versions.JQ_1_6, rootScope) - JsonNode inData = mapper.readTree(buffer.toString()); + JsonNode inData = mapper.readTree(buffer.toString()) - JsonQuery q = JsonQuery.compile(replacedFilter, Versions.JQ_1_6); + JsonQuery q = JsonQuery.compile(replacedFilter, Versions.JQ_1_6) - final List out = new ArrayList<>(); - q.apply(rootScope, inData, out::add); + final List out = new ArrayList<>() + q.apply(rootScope, inData, out::add) out.each {it-> //process object @@ -114,8 +114,6 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre }else{ if(it.getNodeType()==JsonNodeType.ARRAY){ this.iterateArray(it.elements()) - } else if(it.getNodeType()==JsonNodeType.STRING) { - allData.put(prefix, it.asText()) } else { allData.put(prefix, it.toString()) } @@ -133,12 +131,7 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre Integer i=0 list.each{it-> - if(it.getNodeType() == JsonNodeType.STRING){ - allData.put(prefix +"."+ i.toString(),it.asText()) - }else{ - allData.put(prefix +"."+ i.toString(),it.toString()) - } - + allData.put(prefix +"."+ i.toString(),it.toString()) i++ } } @@ -160,14 +153,7 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre iterateJsonObject(subKey, newPath) } }else{ - def extractValue - if(value.getNodeType() == JsonNodeType.STRING){ - extractValue=value.asText() - }else{ - extractValue = value.toString() - } - - allData.put(newPath,extractValue) + allData.put(newPath,value.toString()) } } From f753b9f29be031a9bc6f971df2fc6a2058a78feb Mon Sep 17 00:00:00 2001 From: Luis Toledo Date: Tue, 30 Jan 2024 17:22:49 -0300 Subject: [PATCH 2/2] add a flag for maintain compatibility with rundeck 4.x --- .../plugins/logging/JsonLogFilter.groovy | 50 ++++++++++++++++--- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy b/src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy index 29ddce6..1f64052 100644 --- a/src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy +++ b/src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy @@ -47,6 +47,13 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre ) Boolean logData + @PluginProperty( + title = 'Extra quotes', + description = '''If true, the result will be parse to string, that will add extra quotes to the result (compatible with rundeck 4.x)''', + defaultValue = 'false' + ) + Boolean extraQuotes=false + private StringBuffer buffer; OutputContext outputContext Map allData @@ -94,15 +101,15 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre void processJson(final PluginLoggingContext context){ try{ - Scope rootScope = Scope.newEmptyScope() - BuiltinFunctionLoader.getInstance().loadFunctions(Versions.JQ_1_6, rootScope) + Scope rootScope = Scope.newEmptyScope(); + BuiltinFunctionLoader.getInstance().loadFunctions(Versions.JQ_1_6, rootScope); - JsonNode inData = mapper.readTree(buffer.toString()) + JsonNode inData = mapper.readTree(buffer.toString()); - JsonQuery q = JsonQuery.compile(replacedFilter, Versions.JQ_1_6) + JsonQuery q = JsonQuery.compile(replacedFilter, Versions.JQ_1_6); - final List out = new ArrayList<>() - q.apply(rootScope, inData, out::add) + final List out = new ArrayList<>(); + q.apply(rootScope, inData, out::add); out.each {it-> //process object @@ -114,6 +121,12 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre }else{ if(it.getNodeType()==JsonNodeType.ARRAY){ this.iterateArray(it.elements()) + } else if(it.getNodeType()==JsonNodeType.STRING) { + def value = it.asText() + if(extraQuotes){ + value = it.toString() + } + allData.put(prefix, value) } else { allData.put(prefix, it.toString()) } @@ -131,7 +144,16 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre Integer i=0 list.each{it-> - allData.put(prefix +"."+ i.toString(),it.toString()) + if(it.getNodeType() == JsonNodeType.STRING){ + def value = it.textValue() + if(extraQuotes){ + value = it.toString() + } + allData.put(prefix +"."+ i.toString(),value) + }else{ + allData.put(prefix +"."+ i.toString(),it.toString()) + } + i++ } } @@ -153,7 +175,19 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre iterateJsonObject(subKey, newPath) } }else{ - allData.put(newPath,value.toString()) + def extractValue + if(value.getNodeType() == JsonNodeType.STRING){ + if(extraQuotes){ + extractValue=value.toString() + }else{ + extractValue=value.asText() + } + + }else{ + extractValue = value.toString() + } + + allData.put(newPath,extractValue) } }