Skip to content

Commit

Permalink
Fix fragment issue
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Dec 10, 2024
1 parent e504960 commit 58478d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ public static ApiToken fromXContent(XContentParser parser) throws IOException {
private static RoleV7.Index parseIndexPermission(XContentParser parser) throws IOException {
List<String> indexPatterns = new ArrayList<>();
List<String> allowedActions = new ArrayList<>();
String dls = null;
List<String> fls = null;
List<String> maskedFields = null;
String dls = "";
List<String> fls = new ArrayList<>();
List<String> maskedFields = new ArrayList<>();

String currentFieldName = null;
XContentParser.Token token;
Expand All @@ -140,13 +140,11 @@ private static RoleV7.Index parseIndexPermission(XContentParser parser) throws I
}
break;
case "fls":
fls = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
fls.add(parser.text());
}
break;
case "masked_fields":
maskedFields = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
maskedFields.add(parser.text());
}
Expand All @@ -159,13 +157,7 @@ private static RoleV7.Index parseIndexPermission(XContentParser parser) throws I
throw new IllegalArgumentException("index_patterns is required for index permission");
}

return new RoleV7.Index(
indexPatterns,
allowedActions,
dls, // Now passing String instead of List<String>
fls,
maskedFields
);
return new RoleV7.Index(indexPatterns, allowedActions, dls, fls, maskedFields);
}

public String getDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import java.util.Collections;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.opensearch.core.xcontent.ToXContent;
Expand All @@ -55,7 +55,8 @@ public RoleV7() {

}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonIgnoreProperties(value = { "fragment" }, ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Index implements ToXContent {

private List<String> index_patterns = Collections.emptyList();
Expand All @@ -68,14 +69,7 @@ public Index() {
super();
}

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES) // Add mode = PROPERTIES
public Index(
@JsonProperty("index_patterns") List<String> indexPatterns,
@JsonProperty("allowed_actions") List<String> allowedActions,
@JsonProperty("dls") String dls,
@JsonProperty("fls") List<String> fls,
@JsonProperty("masked_fields") List<String> maskedFields
) {
public Index(List<String> indexPatterns, List<String> allowedActions, String dls, List<String> fls, List<String> maskedFields) {
this.index_patterns = indexPatterns;
this.allowed_actions = allowedActions;
this.dls = dls;
Expand All @@ -90,17 +84,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field("index_patterns", index_patterns);
builder.field("allowed_actions", allowed_actions);

if (dls != null) {
builder.field("dls", dls);
}
builder.field("dls", dls);

if (fls != null && !fls.isEmpty()) {
builder.field("fls", fls);
}
builder.field("fls", fls);

if (masked_fields != null && !masked_fields.isEmpty()) {
builder.field("masked_fields", masked_fields);
}
builder.field("masked_fields", masked_fields);

builder.endObject();
return builder;
Expand Down

0 comments on commit 58478d4

Please sign in to comment.