aboutsummaryrefslogtreecommitdiffstats
path: root/zookeeper-common/src/main/java/com/yahoo/vespa/zookeeper/tls/VespaZookeeperTlsContextUtils.java
blob: 78de6c61e179f293465bcc29c8301511afeab9c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.yahoo.vespa.zookeeper.tls;

import com.yahoo.security.tls.ConfigFileBasedTlsContext;
import com.yahoo.security.tls.TlsContext;
import com.yahoo.security.tls.TransportSecurityUtils;
import com.yahoo.vespa.defaults.Defaults;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

/**
 * @author jonmv
 */
public class VespaZookeeperTlsContextUtils {

    private static final Path ZOOKEEPER_TLS_CONFIG_FILE = Path.of(Defaults.getDefaults().underVespaHome("var/zookeeper/conf/tls.conf.json"));
    private static final TlsContext tlsContext = Files.exists(ZOOKEEPER_TLS_CONFIG_FILE)
                                                 ? new ConfigFileBasedTlsContext(ZOOKEEPER_TLS_CONFIG_FILE, TransportSecurityUtils.getInsecureAuthorizationMode())
                                                 : TransportSecurityUtils.getSystemTlsContext().orElse(null);

    public static Optional<TlsContext> tlsContext() {
        return Optional.ofNullable(tlsContext);
    }

}