Use abstraction from core
Original commit: elastic/x-pack-elasticsearch@01b66264e0
This commit is contained in:
parent
ba86e3968c
commit
6103d96e83
|
@ -7,6 +7,7 @@ package org.elasticsearch.marvel.agent.renderer.cluster;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
|
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
|
||||||
|
import org.elasticsearch.common.hash.MessageDigests;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
|
@ -16,34 +17,12 @@ import org.elasticsearch.marvel.agent.renderer.AbstractRenderer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ClusterInfoRenderer extends AbstractRenderer<ClusterInfoMarvelDoc> {
|
public class ClusterInfoRenderer extends AbstractRenderer<ClusterInfoMarvelDoc> {
|
||||||
|
|
||||||
static final class MessageDigestSHA256Provider {
|
|
||||||
private static final MessageDigest digest;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
digest = MessageDigest.getInstance("SHA-256");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new ElasticsearchException("Unexpected exception creating MessageDigest instance", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MessageDigest sha256() {
|
|
||||||
try {
|
|
||||||
MessageDigest sha = (MessageDigest) digest.clone();
|
|
||||||
sha.reset();
|
|
||||||
return sha;
|
|
||||||
} catch (CloneNotSupportedException e) {
|
|
||||||
throw new ElasticsearchException("Unexpected exception creating MessageDigest instance", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClusterInfoRenderer() {
|
public ClusterInfoRenderer() {
|
||||||
super(null, false);
|
super(null, false);
|
||||||
}
|
}
|
||||||
|
@ -88,16 +67,7 @@ public class ClusterInfoRenderer extends AbstractRenderer<ClusterInfoMarvelDoc>
|
||||||
|
|
||||||
public static String hash(String licenseStatus, String licenseUid, String licenseType, String licenseExpiryDate, String clusterUUID) {
|
public static String hash(String licenseStatus, String licenseUid, String licenseType, String licenseExpiryDate, String clusterUUID) {
|
||||||
String toHash = licenseStatus + licenseUid + licenseType + licenseExpiryDate + clusterUUID;
|
String toHash = licenseStatus + licenseUid + licenseType + licenseExpiryDate + clusterUUID;
|
||||||
try {
|
return MessageDigests.toHexString(MessageDigests.sha256().digest(toHash.getBytes(StandardCharsets.UTF_8)));
|
||||||
byte[] sha256Bytes = MessageDigestSHA256Provider.sha256().digest(toHash.getBytes("UTF-8"));
|
|
||||||
StringBuffer hash = new StringBuffer();
|
|
||||||
for (int i = 0; i < sha256Bytes.length; i++) {
|
|
||||||
hash.append(Integer.toHexString(0xff & sha256Bytes[i]));
|
|
||||||
}
|
|
||||||
return hash.toString();
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new ElasticsearchException("Unexpected error calculating SHA-256 MessageDigest", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class Fields {
|
static final class Fields {
|
||||||
|
|
Loading…
Reference in New Issue