From a9d4a01d390c6cf10e0457e94ff3b21d80705648 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Thu, 9 Feb 2023 14:51:48 -0500 Subject: [PATCH 1/3] Switch from XContentType to MediaType Signed-off-by: Craig Perkins --- .../java/org/opensearch/security/support/ConfigHelper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/opensearch/security/support/ConfigHelper.java b/src/main/java/org/opensearch/security/support/ConfigHelper.java index 23f93e3672..5d9b36192e 100644 --- a/src/main/java/org/opensearch/security/support/ConfigHelper.java +++ b/src/main/java/org/opensearch/security/support/ConfigHelper.java @@ -41,6 +41,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -116,11 +117,11 @@ public static String createEmptySdcYaml(CType cType, int configVersion) throws E return DefaultObjectMapper.YAML_MAPPER.writeValueAsString(createEmptySdc(cType, configVersion)); } - public static BytesReference readXContent(final Reader reader, final XContentType xContentType) throws IOException { + public static BytesReference readXContent(final Reader reader, final MediaType mediaType) throws IOException { BytesReference retVal; XContentParser parser = null; try { - parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, reader); + parser = XContentFactory.xContent(mediaType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, reader); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); From 12a8e1f22f283cc3b16e5aa88e967e265fe2189c Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Thu, 9 Feb 2023 15:14:04 -0500 Subject: [PATCH 2/3] Also get instance in SecurityAdmin Signed-off-by: Craig Perkins --- .../java/org/opensearch/security/tools/SecurityAdmin.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/opensearch/security/tools/SecurityAdmin.java b/src/main/java/org/opensearch/security/tools/SecurityAdmin.java index c9717e20be..a24e16a6e9 100644 --- a/src/main/java/org/opensearch/security/tools/SecurityAdmin.java +++ b/src/main/java/org/opensearch/security/tools/SecurityAdmin.java @@ -114,6 +114,7 @@ import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -945,11 +946,11 @@ private static boolean retrieveFile(final RestHighLevelClient restHighLevelClien return false; } - private static BytesReference readXContent(final String content, final XContentType xContentType) throws IOException { + private static BytesReference readXContent(final String content, final MediaType mediaType) throws IOException { BytesReference retVal; XContentParser parser = null; try { - parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, content); + parser = XContentFactory.xContent(mediaType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, content); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); From 05c82eb29c238f5e6feac5440701fd46f95c0c8b Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Tue, 14 Feb 2023 03:58:29 +0000 Subject: [PATCH 3/3] Fix test reference to media type Signed-off-by: Peter Nied --- .../org/opensearch/security/auditlog/sink/KafkaSinkTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/opensearch/security/auditlog/sink/KafkaSinkTest.java b/src/test/java/org/opensearch/security/auditlog/sink/KafkaSinkTest.java index ea9ce18e3d..b074dd2b62 100644 --- a/src/test/java/org/opensearch/security/auditlog/sink/KafkaSinkTest.java +++ b/src/test/java/org/opensearch/security/auditlog/sink/KafkaSinkTest.java @@ -54,7 +54,7 @@ public void after() { public void testKafka() throws Exception { String configYml = FileHelper.loadFile("auditlog/endpoints/sink/configuration_kafka.yml"); configYml = configYml.replace("_RPLC_BOOTSTRAP_SERVERS_",embeddedKafka.getEmbeddedKafka().getBrokersAsString()); - Settings.Builder settingsBuilder = Settings.builder().loadFromSource(configYml, YamlXContent.yamlXContent.type()); + Settings.Builder settingsBuilder = Settings.builder().loadFromSource(configYml, YamlXContent.yamlXContent.mediaType()); try(KafkaConsumer consumer = createConsumer()) { consumer.subscribe(Arrays.asList("compliance"));