Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ public ActionRequestValidationException validateIndexTemplate(@Nullable ActionRe
if (indexTemplate == null) {
validationException = addValidationError("an index template is required", validationException);
} else {
if (indexTemplate.indexPatterns().stream().anyMatch(Regex::isMatchAllPattern)) {
if (IndexMetadata.INDEX_HIDDEN_SETTING.exists(indexTemplate.template().settings())) {
validationException = addValidationError(
"global composable templates may not specify the setting " + IndexMetadata.INDEX_HIDDEN_SETTING.getKey(),
validationException
);
}
if (indexTemplate.indexPatterns().stream().anyMatch(Regex::isMatchAllPattern)
&& indexTemplate.template() != null
&& indexTemplate.template().settings() != null
&& IndexMetadata.INDEX_HIDDEN_SETTING.exists(indexTemplate.template().settings())) {
validationException = addValidationError(
"global composable templates may not specify the setting " + IndexMetadata.INDEX_HIDDEN_SETTING.getKey(),
validationException
);
}
if (indexTemplate.priority() != null && indexTemplate.priority() < 0) {
validationException = addValidationError("index template priority must be >= 0", validationException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

public class PutComposableIndexTemplateRequestTests extends AbstractWireSerializingTestCase<PutComposableIndexTemplateAction.Request> {
@Override
Expand Down Expand Up @@ -84,6 +85,25 @@ public void testPutGlobalTemplatesCannotHaveHiddenIndexSetting() {
assertThat(error, is("global composable templates may not specify the setting " + IndexMetadata.SETTING_INDEX_HIDDEN));
}

public void testPutGlobalTemplateWithoutInlineTemplateSucceeds() {
ComposableIndexTemplate globalTemplate = new ComposableIndexTemplate(List.of("*"), null, List.of("ct"), null, null, null, null);

PutComposableIndexTemplateAction.Request request = new PutComposableIndexTemplateAction.Request("test");
request.indexTemplate(globalTemplate);

assertThat(request.validate(), is(nullValue()));
}

public void testPutGlobalTemplateWithoutSettingsSucceeds() {
Template template = new Template(null, null, null);
ComposableIndexTemplate globalTemplate = new ComposableIndexTemplate(List.of("*"), template, null, null, null, null, null);

PutComposableIndexTemplateAction.Request request = new PutComposableIndexTemplateAction.Request("test");
request.indexTemplate(globalTemplate);

assertThat(request.validate(), is(nullValue()));
}

public void testPutIndexTemplateV2RequestMustContainTemplate() {
PutComposableIndexTemplateAction.Request requestWithoutTemplate = new PutComposableIndexTemplateAction.Request("test");

Expand Down
Loading