@@ -0,0 +1,2534 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.%0Apackage com.yahoo.vespa.config.server.tenant;%0A%0Aimport com.fasterxml.jackson.core.type.TypeReference;%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.yahoo.config.provision.ApplicationId;%0Aimport com.yahoo.path.Path;%0A%0Aimport com.yahoo.vespa.curator.Curator;%0Aimport com.yahoo.vespa.curator.transaction.CuratorOperations;%0Aimport com.yahoo.vespa.curator.transaction.CuratorTransaction;%0A%0Aimport java.util.Optional;%0A%0A/**%0A * TLS Secret keys for applications (used to retrieve actual certificate/key from secret store). Persisted in ZooKeeper.%0A *%0A * @author andreer%0A */%0Apublic class TlsSecretsKeys %7B%0A%0A    private final Path path;%0A    private final Curator curator;%0A%0A    public TlsSecretsKeys(Curator curator, Path tenantPath) %7B%0A        this.curator = curator;%0A        this.path = tenantPath.append(%22tlsSecretsKeys/%22);%0A    %7D%0A%0A    public Optional%3CString%3E readTlsSecretsKeyFromZookeeper(ApplicationId application) %7B%0A        try %7B%0A            Optional%3Cbyte%5B%5D%3E data = curator.getData(tlsSecretsKeyOf(application));%0A            if (data.isEmpty() %7C%7C data.get().length == 0) return Optional.empty();%0A            String tlsSecretsKey = new ObjectMapper().readValue(data.get(), new TypeReference%3CString%3E() %7B%7D);%0A            return Optional.of(tlsSecretsKey);%0A        %7D catch (Exception e) %7B%0A            throw new RuntimeException(%22Error reading TLS secret key of %22 + application, e);%0A        %7D%0A    %7D%0A%0A    public void writeTlsSecretsKeyToZooKeeper(ApplicationId application, String tlsSecretsKey) %7B%0A        if (tlsSecretsKey == null) return;%0A        try %7B%0A            byte%5B%5D data = new ObjectMapper().writeValueAsBytes(tlsSecretsKey);%0A            curator.set(tlsSecretsKeyOf(application), data);%0A        %7D catch (Exception e) %7B%0A            throw new RuntimeException(%22Could not write TLS secret key of %22 + application, e);%0A        %7D%0A    %7D%0A%0A    /** Returns a transaction which deletes these tls secrets key if they exist */%0A    public CuratorTransaction delete(ApplicationId application) %7B%0A        if (!curator.exists(tlsSecretsKeyOf(application))) return CuratorTransaction.empty(curator);%0A        return CuratorTransaction.from(CuratorOperations.delete(tlsSecretsKeyOf(application).getAbsolute()), curator);%0A    %7D%0A%0A    /** Returns the path storing the tls secrets key for an application */%0A    private Path tlsSecretsKeyOf(ApplicationId application) %7B%0A        return path.append(application.serializedForm());%0A    %7D%0A%0A%7D%0A

store tls secrets keys in zk