@Test public void configureAuthenticationConfig() { byte[] testBytes = new byte[]{0, 1, 2, 3, 4}; CoreV1Api coreV1Api = mock(CoreV1Api.class); KubernetesSecretsTokenAuthProvider kubernetesSecretsTokenAuthProvider = new KubernetesSecretsTokenAuthProvider(); kubernetesSecretsTokenAuthProvider.initialize(coreV1Api, testBytes, (fd) -> "default"); AuthenticationConfig authenticationConfig = AuthenticationConfig.builder().build(); FunctionAuthData functionAuthData = FunctionAuthData.builder().data("foo".getBytes()).build(); kubernetesSecretsTokenAuthProvider.configureAuthenticationConfig(authenticationConfig, Optional.of(functionAuthData)); Assert.assertEquals(authenticationConfig.getClientAuthenticationPlugin(), AuthenticationToken.class.getName()); Assert.assertEquals(authenticationConfig.getClientAuthenticationParameters(), "file: Assert.assertEquals(authenticationConfig.getTlsTrustCertsFilePath(), "/etc/auth/ca.pem"); }
@Override public void configureAuthenticationConfig(AuthenticationConfig authConfig, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { authConfig.setClientAuthenticationPlugin(null); authConfig.setClientAuthenticationParameters(null); } else { authConfig.setClientAuthenticationPlugin(AuthenticationToken.class.getName()); authConfig.setClientAuthenticationParameters(String.format("file: if (this.caBytes != null) { authConfig.setTlsTrustCertsFilePath(String.format("%s/%s", DEFAULT_SECRET_MOUNT_DIR, FUNCTION_CA_CERT)); } } }
KubernetesSecretsTokenAuthProvider implements KubernetesFunctionAuthProvider { @Override public void configureAuthenticationConfig(AuthenticationConfig authConfig, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { authConfig.setClientAuthenticationPlugin(null); authConfig.setClientAuthenticationParameters(null); } else { authConfig.setClientAuthenticationPlugin(AuthenticationToken.class.getName()); authConfig.setClientAuthenticationParameters(String.format("file: if (this.caBytes != null) { authConfig.setTlsTrustCertsFilePath(String.format("%s/%s", DEFAULT_SECRET_MOUNT_DIR, FUNCTION_CA_CERT)); } } } }
KubernetesSecretsTokenAuthProvider implements KubernetesFunctionAuthProvider { @Override public void configureAuthenticationConfig(AuthenticationConfig authConfig, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { authConfig.setClientAuthenticationPlugin(null); authConfig.setClientAuthenticationParameters(null); } else { authConfig.setClientAuthenticationPlugin(AuthenticationToken.class.getName()); authConfig.setClientAuthenticationParameters(String.format("file: if (this.caBytes != null) { authConfig.setTlsTrustCertsFilePath(String.format("%s/%s", DEFAULT_SECRET_MOUNT_DIR, FUNCTION_CA_CERT)); } } }  }
KubernetesSecretsTokenAuthProvider implements KubernetesFunctionAuthProvider { @Override public void configureAuthenticationConfig(AuthenticationConfig authConfig, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { authConfig.setClientAuthenticationPlugin(null); authConfig.setClientAuthenticationParameters(null); } else { authConfig.setClientAuthenticationPlugin(AuthenticationToken.class.getName()); authConfig.setClientAuthenticationParameters(String.format("file: if (this.caBytes != null) { authConfig.setTlsTrustCertsFilePath(String.format("%s/%s", DEFAULT_SECRET_MOUNT_DIR, FUNCTION_CA_CERT)); } } }  @Override void initialize(CoreV1Api coreClient); @Override void setCaBytes(byte[] caBytes); @Override void setNamespaceProviderFunc(java.util.function.Function<Function.FunctionDetails, String> getNamespaceFromDetails); @Override void configureAuthDataStatefulSet(V1StatefulSet statefulSet, Optional<FunctionAuthData> functionAuthData); @Override void configureAuthenticationConfig(AuthenticationConfig authConfig, Optional<FunctionAuthData> functionAuthData); @Override Optional<FunctionAuthData> cacheAuthData(Function.FunctionDetails funcDetails,
                                                    AuthenticationDataSource authenticationDataSource); @Override void cleanUpAuthData(Function.FunctionDetails funcDetails, Optional<FunctionAuthData> functionAuthData); @Override Optional<FunctionAuthData> updateAuthData(Function.FunctionDetails funcDetails,
                                                     Optional<FunctionAuthData> existingFunctionAuthData,
                                                     AuthenticationDataSource authenticationDataSource); }
KubernetesSecretsTokenAuthProvider implements KubernetesFunctionAuthProvider { @Override public void configureAuthenticationConfig(AuthenticationConfig authConfig, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { authConfig.setClientAuthenticationPlugin(null); authConfig.setClientAuthenticationParameters(null); } else { authConfig.setClientAuthenticationPlugin(AuthenticationToken.class.getName()); authConfig.setClientAuthenticationParameters(String.format("file: if (this.caBytes != null) { authConfig.setTlsTrustCertsFilePath(String.format("%s/%s", DEFAULT_SECRET_MOUNT_DIR, FUNCTION_CA_CERT)); } } }  @Override void initialize(CoreV1Api coreClient); @Override void setCaBytes(byte[] caBytes); @Override void setNamespaceProviderFunc(java.util.function.Function<Function.FunctionDetails, String> getNamespaceFromDetails); @Override void configureAuthDataStatefulSet(V1StatefulSet statefulSet, Optional<FunctionAuthData> functionAuthData); @Override void configureAuthenticationConfig(AuthenticationConfig authConfig, Optional<FunctionAuthData> functionAuthData); @Override Optional<FunctionAuthData> cacheAuthData(Function.FunctionDetails funcDetails,
                                                    AuthenticationDataSource authenticationDataSource); @Override void cleanUpAuthData(Function.FunctionDetails funcDetails, Optional<FunctionAuthData> functionAuthData); @Override Optional<FunctionAuthData> updateAuthData(Function.FunctionDetails funcDetails,
                                                     Optional<FunctionAuthData> existingFunctionAuthData,
                                                     AuthenticationDataSource authenticationDataSource);  }