Skip to content

Commit

Permalink
add a flag for maintain compatibility with rundeck 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ltamaster committed Jan 30, 2024
1 parent dab71ac commit f753b9f
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> allData
Expand Down Expand Up @@ -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<JsonNode> out = new ArrayList<>()
q.apply(rootScope, inData, out::add)
final List<JsonNode> out = new ArrayList<>();
q.apply(rootScope, inData, out::add);

out.each {it->
//process object
Expand All @@ -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())
}
Expand All @@ -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++
}
}
Expand All @@ -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)
}
}

Expand Down

0 comments on commit f753b9f

Please sign in to comment.