Skip to content

Commit

Permalink
Improve the process to support any order of attributes in commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mcasas993 committed Jan 27, 2025
1 parent b454db5 commit ff1e451
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.wazuh.commandmanager.model;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
Expand All @@ -30,6 +32,7 @@ public class Action implements ToXContentObject {
public static final String ACTION = "action";
public static final String NAME = "name";
public static final String VERSION = "version";
private static final Logger log = LogManager.getLogger(Action.class);
private final String name;
private final Args args;
private final String version;
Expand Down Expand Up @@ -114,6 +117,10 @@ private static Args parseArgs(String actionName, XContentParser parser)
}
actionNameEnum = ActionName.FETCH_GROUP;
if (actionName.contains(actionNameEnum.getName())) {
while (parser.currentToken() != XContentParser.Token.END_OBJECT) {
//Just move the parser to the end of the object
parser.nextToken();
}
return new Args();
}
return Args.generalParse(parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public static Args generalParse(XContentParser parser) throws IOException {
break;
}
}
log.info("General parse args. FINISH token {}", parser.currentToken());
return new Args(args);
}

Expand Down Expand Up @@ -134,13 +135,14 @@ public static Args setGroupParse(XContentParser parser)
}
}
args.put(fieldName, list);

// to end the object parser
parser.nextToken();
return new Args(args);
} else {
throw new IllegalArgumentException(
"Incorrect request. An array of agents is expected in args.");
if (parser.currentToken() == XContentParser.Token.END_OBJECT) {
return new Args(args);
}
}
throw new IllegalArgumentException("Incorrect request. An array of agents is expected in args.");
}

/**
Expand Down

0 comments on commit ff1e451

Please sign in to comment.