SecretCertProvider { public Secret createSecret(String namespace, String name, String keyKey, String certKey, File keyFile, File certFile, String storeKey, String storePasswordKey, File storeFile, String storePassword, Map<String, String> labels, Map<String, String> annotations, OwnerReference ownerReference) throws IOException { byte[] key = Files.readAllBytes(keyFile.toPath()); byte[] cert = Files.readAllBytes(certFile.toPath()); byte[] store = null; if (storeFile != null) { store = Files.readAllBytes(storeFile.toPath()); } byte[] password = storePassword != null ? storePassword.getBytes(StandardCharsets.US_ASCII) : null; return createSecret(namespace, name, keyKey, certKey, key, cert, storeKey, storePasswordKey, store, password, labels, annotations, ownerReference); }  Secret createSecret(String namespace, String name,
                               String keyKey, String certKey,
                               File keyFile, File certFile,
                               String storeKey, String storePasswordKey,
                               File storeFile, String storePassword,
                               Map<String, String> labels, Map<String, String> annotations,
                               OwnerReference ownerReference); Secret createSecret(String namespace, String name,
                               String keyKey, String certKey,
                               byte[] key, byte[] cert,
                               String storeKey, String storePasswordKey,
                               byte[] store, byte[] storePassword,
                               Map<String, String> labels, Map<String, String> annotations,
                               OwnerReference ownerReference); Secret createSecret(String namespace, String name, Map<String, String> data,
                               Map<String, String> labels, Map<String, String> annotations, OwnerReference ownerReference); Secret addSecret(Secret secret, String keyKey, String certKey, byte[] key, byte[] cert); Secret addSecret(Secret secret, String keyKey, String certKey, File keyFile, File certFile);  }
@Test public void testKeyAndCertInSecret() throws Exception { Base64.Decoder decoder = Base64.getDecoder(); File key = File.createTempFile("key-", ".key"); File cert = File.createTempFile("crt-", ".crt"); File store = File.createTempFile("crt-", ".str"); ssl.generateSelfSignedCert(key, cert, 365); ssl.addCertToTrustStore(cert, "ca", store, "123456"); Secret secret = secretCertProvider.createSecret("my-namespace", "my-secret", "ca.key", "ca.crt", key, cert, "ca.p12", "ca.password", store, "123456", emptyMap(), emptyMap(), ownerReference); assertThat(secret.getMetadata().getName(), is("my-secret")); assertThat(secret.getMetadata().getNamespace(), is("my-namespace")); assertThat(secret.getMetadata().getOwnerReferences().size(), is(1)); assertThat(secret.getMetadata().getOwnerReferences().get(0), is(ownerReference)); assertThat(secret.getData().size(), is(4)); assertThat(Arrays.equals(Files.readAllBytes(key.toPath()), decoder.decode(secret.getData().get("ca.key"))), is(true)); assertThat(Arrays.equals(Files.readAllBytes(cert.toPath()), decoder.decode(secret.getData().get("ca.crt"))), is(true)); assertThat(Arrays.equals(Files.readAllBytes(store.toPath()), decoder.decode(secret.getData().get("ca.p12"))), is(true)); assertThat(new String(decoder.decode(secret.getData().get("ca.password"))), is("123456")); key.delete(); cert.delete(); store.delete(); }