use pattern instead of hard coding the version (elastic/elasticsearch#3078)
Original commit: elastic/x-pack-elasticsearch@b86e1cd40c
This commit is contained in:
parent
1b88fd4d11
commit
7b1d7c8e27
|
@ -35,6 +35,7 @@ import org.elasticsearch.xpack.template.TemplateUtils;
|
|||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* SecurityTemplateService is responsible for adding the template needed for the
|
||||
|
@ -45,6 +46,7 @@ public class SecurityTemplateService extends AbstractComponent implements Cluste
|
|||
public static final String SECURITY_INDEX_NAME = ".security";
|
||||
public static final String SECURITY_TEMPLATE_NAME = "security-index-template";
|
||||
private static final String SECURITY_VERSION_STRING = "security-version";
|
||||
static final String SECURITY_INDEX_TEMPLATE_VERSION_PATTERN = Pattern.quote("${security.template.version}");
|
||||
|
||||
private final InternalClient client;
|
||||
final AtomicBoolean templateCreationPending = new AtomicBoolean(false);
|
||||
|
@ -95,15 +97,8 @@ public class SecurityTemplateService extends AbstractComponent implements Cluste
|
|||
}
|
||||
|
||||
private void putSecurityMappings() {
|
||||
BytesReference template;
|
||||
try {
|
||||
template = TemplateUtils.load("/" + SECURITY_TEMPLATE_NAME + ".json");
|
||||
} catch (IOException e) {
|
||||
updateMappingPending.set(false);
|
||||
logger.error("failed to load security index template", e);
|
||||
throw new ElasticsearchException("failed to load security index template", e);
|
||||
}
|
||||
|
||||
String template = TemplateUtils.loadTemplate("/" + SECURITY_TEMPLATE_NAME + ".json", Version.CURRENT.toString()
|
||||
, SECURITY_INDEX_TEMPLATE_VERSION_PATTERN);
|
||||
Map<String, Object> typeMappingMap;
|
||||
try {
|
||||
XContentParser xParser = XContentFactory.xContent(template).createParser(template);
|
||||
|
@ -157,15 +152,8 @@ public class SecurityTemplateService extends AbstractComponent implements Cluste
|
|||
|
||||
private void putSecurityTemplate() {
|
||||
logger.debug("putting the security index template");
|
||||
BytesReference template;
|
||||
try {
|
||||
template = TemplateUtils.load("/" + SECURITY_TEMPLATE_NAME + ".json");
|
||||
} catch (Exception e) {
|
||||
templateCreationPending.set(false);
|
||||
logger.error("failed to load security index templates for [{}]",
|
||||
e, SECURITY_INDEX_NAME);
|
||||
throw new ElasticsearchException("failed to load security index template", e);
|
||||
}
|
||||
String template = TemplateUtils.loadTemplate("/" + SECURITY_TEMPLATE_NAME + ".json", Version.CURRENT.toString()
|
||||
, SECURITY_INDEX_TEMPLATE_VERSION_PATTERN);
|
||||
|
||||
PutIndexTemplateRequest putTemplateRequest = client.admin().indices()
|
||||
.preparePutTemplate(SECURITY_TEMPLATE_NAME).setSource(template).request();
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
"mappings" : {
|
||||
"user" : {
|
||||
"_meta": {
|
||||
"security-version": "5.0.0-alpha5"
|
||||
"security-version": "${security.template.version}"
|
||||
},
|
||||
"dynamic" : "strict",
|
||||
"properties" : {
|
||||
|
@ -63,7 +63,7 @@
|
|||
},
|
||||
"role" : {
|
||||
"_meta": {
|
||||
"security-version": "5.0.0-alpha5"
|
||||
"security-version": "${security.template.version}"
|
||||
},
|
||||
"dynamic" : "strict",
|
||||
"properties" : {
|
||||
|
@ -101,7 +101,7 @@
|
|||
},
|
||||
"reserved-user" : {
|
||||
"_meta": {
|
||||
"security-version": "5.0.0-alpha5"
|
||||
"security-version": "${security.template.version}"
|
||||
},
|
||||
"dynamic" : "strict",
|
||||
"properties" : {
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.LocalTransportAddress;
|
||||
|
@ -43,6 +42,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import static org.elasticsearch.xpack.security.SecurityTemplateService.SECURITY_INDEX_NAME;
|
||||
import static org.elasticsearch.xpack.security.SecurityTemplateService.SECURITY_INDEX_TEMPLATE_VERSION_PATTERN;
|
||||
import static org.elasticsearch.xpack.security.SecurityTemplateService.SECURITY_TEMPLATE_NAME;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -270,7 +270,8 @@ public class SecurityTemplateServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
private IndexMetaData.Builder createIndexMetadata(String templateString) throws IOException {
|
||||
BytesReference template = TemplateUtils.load(templateString);
|
||||
String template = TemplateUtils.loadTemplate(templateString, Version.CURRENT.toString()
|
||||
, SECURITY_INDEX_TEMPLATE_VERSION_PATTERN);
|
||||
PutIndexTemplateRequest request = new PutIndexTemplateRequest();
|
||||
request.source(template);
|
||||
IndexMetaData.Builder indexMetaData = IndexMetaData.builder(SECURITY_INDEX_NAME);
|
||||
|
@ -299,7 +300,8 @@ public class SecurityTemplateServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
private IndexTemplateMetaData.Builder getIndexTemplateMetaData(String templateString) throws IOException {
|
||||
BytesReference template = TemplateUtils.load(templateString);
|
||||
String template = TemplateUtils.loadTemplate(templateString, Version.CURRENT.toString()
|
||||
, SECURITY_INDEX_TEMPLATE_VERSION_PATTERN);
|
||||
PutIndexTemplateRequest request = new PutIndexTemplateRequest();
|
||||
request.source(template);
|
||||
IndexTemplateMetaData.Builder templateBuilder = IndexTemplateMetaData.builder(SECURITY_TEMPLATE_NAME);
|
||||
|
|
Loading…
Reference in New Issue