-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
306 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
plugins/command-manager/src/main/java/com/wazuh/commandmanager/model/Agent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package com.wazuh.commandmanager.model; | ||
|
||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Command's agent fields. | ||
*/ | ||
public class Agent implements ToXContentObject { | ||
public static final String AGENT = "agent"; | ||
public static final String GROUPS = "groups"; | ||
private final List<String> groups; | ||
|
||
/** | ||
* Default constructor. | ||
* | ||
* @param groups Agent's groups | ||
*/ | ||
public Agent(List<String> groups) { | ||
this.groups = groups; | ||
} | ||
|
||
/** | ||
* @param parser | ||
* @return | ||
* @throws IOException | ||
*/ | ||
public static Agent parse(XContentParser parser) throws IOException { | ||
List<Object> groups = List.of(); | ||
|
||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
String fieldName = parser.currentName(); | ||
parser.nextToken(); | ||
if (fieldName.equals(GROUPS)) { | ||
groups = parser.list(); | ||
} else { | ||
parser.skipChildren(); | ||
} | ||
} | ||
|
||
// Cast args field Object list to String list | ||
List<String> convertedGroupFields = (List<String>) (List<?>) (groups); | ||
return new Agent(convertedGroupFields); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(AGENT); | ||
builder.field(GROUPS, this.groups); | ||
return builder.endObject(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Agent{" + | ||
"groups=" + groups + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.