Skip to content

Commit b330493

Browse files
authored
Rename mime_type configuration option to media_type (#67860)
1 parent cf214f0 commit b330493

File tree

5 files changed

+43
-41
lines changed

5 files changed

+43
-41
lines changed

docs/reference/ingest/processors/set.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ its value will be replaced with the provided one.
1717
| `copy_from` | no | - | The origin field which will be copied to `field`, cannot set `value` simultaneously. Supported data types are `boolean`, `number`, `array`, `object`, `string`, `date`, etc.
1818
| `override` | no | `true` | If processor will update fields with pre-existing non-null-valued field. When set to `false`, such fields will not be touched.
1919
| `ignore_empty_value` | no | `false` | If `true` and `value` is a <<accessing-template-fields,template snippet>> that evaluates to `null` or the empty string, the processor quietly exits without modifying the document
20-
| `mime_type` | no | `application/json` | The MIME type for encoding `value`. Applies only when `value` is a <<accessing-template-fields,template snippet>>. Must be one of `application/json`, `text/plain`, or `application/x-www-form-urlencoded`.
20+
| `media_type` | no | `application/json` | The media type for encoding `value`. Applies only when `value` is a <<accessing-template-fields,template snippet>>. Must be one of `application/json`, `text/plain`, or `application/x-www-form-urlencoded`.
2121
include::common-options.asciidoc[]
2222
|======
2323

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SetProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ public SetProcessor create(Map<String, Processor.Factory> registry, String proce
111111
String description, Map<String, Object> config) throws Exception {
112112
String field = ConfigurationUtils.readStringProperty(TYPE, processorTag, config, "field");
113113
String copyFrom = ConfigurationUtils.readOptionalStringProperty(TYPE, processorTag, config, "copy_from");
114-
String mimeType = ConfigurationUtils.readMimeTypeProperty(TYPE, processorTag, config, "mime_type", "application/json");
114+
String mediaType = ConfigurationUtils.readMediaTypeProperty(TYPE, processorTag, config, "media_type", "application/json");
115115
ValueSource valueSource = null;
116116
if (copyFrom == null) {
117117
Object value = ConfigurationUtils.readObject(TYPE, processorTag, config, "value");
118-
valueSource = ValueSource.wrap(value, scriptService, Map.of(Script.CONTENT_TYPE_OPTION, mimeType));
118+
valueSource = ValueSource.wrap(value, scriptService, Map.of(Script.CONTENT_TYPE_OPTION, mediaType));
119119
} else {
120120
Object value = config.remove("value");
121121
if (value != null) {

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,25 @@ public void testCreateWithCopyFromAndValue() throws Exception {
137137
assertThat(exception.getMessage(), equalTo("[copy_from] cannot set both `copy_from` and `value` in the same processor"));
138138
}
139139

140-
public void testMimeType() throws Exception {
141-
// valid mime type
142-
String expectedMimeType = randomFrom(ConfigurationUtils.VALID_MIME_TYPES);
140+
public void testMediaType() throws Exception {
141+
// valid media type
142+
String expectedMediaType = randomFrom(ConfigurationUtils.VALID_MEDIA_TYPES);
143143
Map<String, Object> config = new HashMap<>();
144144
config.put("field", "field1");
145145
config.put("value", "value1");
146-
config.put("mime_type", expectedMimeType);
146+
config.put("media_type", expectedMediaType);
147147
String processorTag = randomAlphaOfLength(10);
148148
SetProcessor setProcessor = factory.create(null, processorTag, null, config);
149149
assertThat(setProcessor.getTag(), equalTo(processorTag));
150150

151-
// invalid mime type
152-
expectedMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MIME_TYPES).contains(m),
151+
// invalid media type
152+
expectedMediaType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MEDIA_TYPES).contains(m),
153153
() -> randomAlphaOfLengthBetween(5, 9));
154154
final Map<String, Object> config2 = new HashMap<>();
155155
config2.put("field", "field1");
156156
config2.put("value", "value1");
157-
config2.put("mime_type", expectedMimeType);
157+
config2.put("media_type", expectedMediaType);
158158
ElasticsearchException e = expectThrows(ElasticsearchException.class, () -> factory.create(null, processorTag, null, config2));
159-
assertThat(e.getMessage(), containsString("property does not contain a supported MIME type [" + expectedMimeType + "]"));
159+
assertThat(e.getMessage(), containsString("property does not contain a supported media type [" + expectedMediaType + "]"));
160160
}
161161
}

server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public final class ConfigurationUtils {
4949

5050
public static final String TAG_KEY = "tag";
5151
public static final String DESCRIPTION_KEY = "description";
52-
public static final String[] VALID_MIME_TYPES = {"application/json", "text/plain", "application/x-www-form-urlencoded"};
52+
public static final String[] VALID_MEDIA_TYPES = {"application/json", "text/plain", "application/x-www-form-urlencoded"};
5353

5454
private ConfigurationUtils() {
5555
}
@@ -306,16 +306,16 @@ public static Object readObject(String processorType, String processorTag, Map<S
306306
return value;
307307
}
308308

309-
public static String readMimeTypeProperty(String processorType, String processorTag, Map<String, Object> configuration,
309+
public static String readMediaTypeProperty(String processorType, String processorTag, Map<String, Object> configuration,
310310
String propertyName, String defaultValue) {
311-
String mimeType = readStringProperty(processorType, processorTag, configuration, propertyName, defaultValue);
311+
String mediaType = readStringProperty(processorType, processorTag, configuration, propertyName, defaultValue);
312312

313-
if (Arrays.asList(VALID_MIME_TYPES).contains(mimeType) == false) {
313+
if (Arrays.asList(VALID_MEDIA_TYPES).contains(mediaType) == false) {
314314
throw newConfigurationException(processorType, processorTag, propertyName,
315-
"property does not contain a supported MIME type [" + mimeType + "]");
315+
"property does not contain a supported media type [" + mediaType + "]");
316316
}
317317

318-
return mimeType;
318+
return mediaType;
319319
}
320320

321321
public static ElasticsearchException newConfigurationException(String processorType, String processorTag,

server/src/test/java/org/elasticsearch/ingest/ConfigurationUtilsTests.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,34 +116,36 @@ public void testReadStringOrIntPropertyInvalidType() {
116116
}
117117
}
118118

119-
public void testReadMimeProperty() {
120-
// valid mime type
121-
String expectedMimeType = randomFrom(ConfigurationUtils.VALID_MIME_TYPES);
122-
config.put("mime_type", expectedMimeType);
123-
String readMimeType = ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", "");
124-
assertThat(readMimeType, equalTo(expectedMimeType));
125-
126-
// missing mime type with valid default
127-
expectedMimeType = randomFrom(ConfigurationUtils.VALID_MIME_TYPES);
128-
config.remove("mime_type");
129-
readMimeType = ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", expectedMimeType);
130-
assertThat(readMimeType, equalTo(expectedMimeType));
131-
132-
// invalid mime type
133-
expectedMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MIME_TYPES).contains(m),
119+
public void testReadMediaProperty() {
120+
// valid media type
121+
String expectedMediaType = randomFrom(ConfigurationUtils.VALID_MEDIA_TYPES);
122+
config.put("media_type", expectedMediaType);
123+
String readMediaType = ConfigurationUtils.readMediaTypeProperty(null, null, config, "media_type", "");
124+
assertThat(readMediaType, equalTo(expectedMediaType));
125+
126+
// missing media type with valid default
127+
expectedMediaType = randomFrom(ConfigurationUtils.VALID_MEDIA_TYPES);
128+
config.remove("media_type");
129+
readMediaType = ConfigurationUtils.readMediaTypeProperty(null, null, config, "media_type", expectedMediaType);
130+
assertThat(readMediaType, equalTo(expectedMediaType));
131+
132+
// invalid media type
133+
expectedMediaType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MEDIA_TYPES).contains(m),
134134
() -> randomAlphaOfLengthBetween(5, 9));
135-
config.put("mime_type", expectedMimeType);
135+
config.put("media_type", expectedMediaType);
136136
ElasticsearchException e = expectThrows(ElasticsearchException.class,
137-
() -> ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", ""));
138-
assertThat(e.getMessage(), containsString("property does not contain a supported MIME type [" + expectedMimeType + "]"));
137+
() -> ConfigurationUtils.readMediaTypeProperty(null, null, config, "media_type", ""));
138+
assertThat(e.getMessage(), containsString("property does not contain a supported media type [" + expectedMediaType + "]"));
139139

140-
// missing mime type with invalid default
141-
final String invalidDefaultMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MIME_TYPES).contains(m),
142-
() -> randomAlphaOfLengthBetween(5, 9));
143-
config.remove("mime_type");
140+
// missing media type with invalid default
141+
final String invalidDefaultMediaType = randomValueOtherThanMany(
142+
m -> Arrays.asList(ConfigurationUtils.VALID_MEDIA_TYPES).contains(m),
143+
() -> randomAlphaOfLengthBetween(5, 9)
144+
);
145+
config.remove("media_type");
144146
e = expectThrows(ElasticsearchException.class,
145-
() -> ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", invalidDefaultMimeType));
146-
assertThat(e.getMessage(), containsString("property does not contain a supported MIME type [" + invalidDefaultMimeType + "]"));
147+
() -> ConfigurationUtils.readMediaTypeProperty(null, null, config, "media_type", invalidDefaultMediaType));
148+
assertThat(e.getMessage(), containsString("property does not contain a supported media type [" + invalidDefaultMediaType + "]"));
147149
}
148150

149151
public void testReadProcessors() throws Exception {

0 commit comments

Comments
 (0)