EndpointCertificateMetadataStore { public Optional<EndpointCertificateMetadata> readEndpointCertificateMetadata(ApplicationId application) { try { Optional<byte[]> data = curator.getData(endpointCertificateMetadataPathOf(application)); if (data.isEmpty() || data.get().length == 0) return Optional.empty(); Slime slime = SlimeUtils.jsonToSlime(data.get()); EndpointCertificateMetadata endpointCertificateMetadata = EndpointCertificateMetadataSerializer.fromSlime(slime.get()); return Optional.of(endpointCertificateMetadata); } catch (Exception e) { throw new RuntimeException("Error reading TLS secret key of " + application, e); } } EndpointCertificateMetadataStore(Curator curator, Path tenantPath); Optional<EndpointCertificateMetadata> readEndpointCertificateMetadata(ApplicationId application); void writeEndpointCertificateMetadata(ApplicationId application, EndpointCertificateMetadata endpointCertificateMetadata); CuratorTransaction delete(ApplicationId application);  }
@Test public void reads_string_format() { curator.set(endpointCertificateMetadataPath, ("\"vespa.tlskeys.tenant1--app1\"").getBytes()); var endpointCertificateSecrets = endpointCertificateMetadataStore.readEndpointCertificateMetadata(applicationId) .flatMap(endpointCertificateRetriever::readEndpointCertificateSecrets); assertTrue(endpointCertificateSecrets.isPresent()); assertTrue(endpointCertificateSecrets.get().key().startsWith("-----BEGIN EC PRIVATE KEY")); assertTrue(endpointCertificateSecrets.get().certificate().startsWith("-----BEGIN CERTIFICATE")); }
@Test public void reads_object_format() { curator.set(endpointCertificateMetadataPath, "{\"keyName\": \"vespa.tlskeys.tenant1--app1-key\", \"certName\":\"vespa.tlskeys.tenant1--app1-cert\", \"version\": 0}" .getBytes()); var secrets = endpointCertificateMetadataStore.readEndpointCertificateMetadata(applicationId) .flatMap(endpointCertificateRetriever::readEndpointCertificateSecrets); assertTrue(secrets.isPresent()); assertTrue(secrets.get().key().startsWith("-----BEGIN EC PRIVATE KEY")); assertTrue(secrets.get().certificate().startsWith("-----BEGIN CERTIFICATE")); }