Lazily generate san string for certificates

The san string used by certificate generation for ssl tests currently
runs at gradle configuration time. This takes several seconds, and
significantly slows down gradle configuration on every invocation.
This change wraps the code into a lazy evaluator that will be invoked at
runtime, and cache the string once it is generated.

Original commit: elastic/x-pack-elasticsearch@812036f416
This commit is contained in:
Ryan Ernst 2016-03-14 17:22:05 -07:00
parent 7d377a5b7f
commit 1b21f20e5b
1 changed files with 138 additions and 123 deletions

View File

@ -8,7 +8,7 @@ dependencies {
}
// needed to be consistent with ssl host checking
String san = getSubjectAlternativeNameString()
Object san = new SanEvaluator()
// location of generated keystores and certificates
File keystoreDir = new File(project.buildDir, 'keystore')
@ -200,10 +200,23 @@ processTestResources {
}
}
/** A lazy evaluator to find the san to use for certificate generation. */
class SanEvaluator {
private static String san = null
String toString() {
synchronized (SanEvaluator.class) {
if (san == null) {
san = getSubjectAlternativeNameString()
}
}
return san
}
// Code stolen from NetworkUtils/InetAddresses/NetworkAddress to support SAN
/** Return all interfaces (and subinterfaces) on the system */
static List<NetworkInterface> getInterfaces() throws SocketException {
private static List<NetworkInterface> getInterfaces() throws SocketException {
List<NetworkInterface> all = new ArrayList<>();
addAllInterfaces(all, Collections.list(NetworkInterface.getNetworkInterfaces()));
Collections.sort(all, new Comparator<NetworkInterface>() {
@ -341,3 +354,5 @@ private static String hextetsToIPv6String(int[] hextets) {
}
return buf.toString();
}
}