@Test public void testConfigValidation() throws Exception { KubernetesSecretsProviderConfigurator provider = new KubernetesSecretsProviderConfigurator(); try { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("secretname", "randomsecret"); Function.FunctionDetails functionDetails = Function.FunctionDetails.newBuilder().setSecretsMap(new Gson().toJson(map)).build(); provider.doAdmissionChecks(null, null, null, functionDetails); Assert.fail("Non conforming secret object should not validate"); } catch (Exception e) { } try { HashMap<String, Object> map = new HashMap<String, Object>(); HashMap<String, String> map1 = new HashMap<String, String>(); map1.put("secretname", "secretvalue"); map.put("secretname", map1); Function.FunctionDetails functionDetails = Function.FunctionDetails.newBuilder().setSecretsMap(new Gson().toJson(map)).build(); provider.doAdmissionChecks(null, null, null, functionDetails); Assert.fail("Non conforming secret object should not validate"); } catch (Exception e) { } try { HashMap<String, Object> map = new HashMap<String, Object>(); HashMap<String, String> map1 = new HashMap<String, String>(); map1.put("path", "secretvalue"); map1.put("key", "secretvalue"); map.put("secretname", map1); Function.FunctionDetails functionDetails = Function.FunctionDetails.newBuilder().setSecretsMap(new Gson().toJson(map)).build(); provider.doAdmissionChecks(null, null, null, functionDetails); } catch (Exception e) { Assert.fail("Conforming secret object should validate"); } }
@Override public void doAdmissionChecks(AppsV1Api appsV1Api, CoreV1Api coreV1Api, String jobNamespace, Function.FunctionDetails functionDetails) { if (!StringUtils.isEmpty(functionDetails.getSecretsMap())) { Type type = new TypeToken<Map<String, Object>>() { }.getType(); Map<String, Object> secretsMap = new Gson().fromJson(functionDetails.getSecretsMap(), type); for (Object object : secretsMap.values()) { if (object instanceof Map) { Map<String, String> kubernetesSecret = (Map<String, String>) object; if (kubernetesSecret.size() < 2) { throw new IllegalArgumentException("Kubernetes Secret should contain id and key"); } if (!kubernetesSecret.containsKey(ID_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain id information"); } if (!kubernetesSecret.containsKey(KEY_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain key information"); } } else { throw new IllegalArgumentException("Kubernetes Secret should be a Map containing id/key pairs"); } } } }
KubernetesSecretsProviderConfigurator implements SecretsProviderConfigurator { @Override public void doAdmissionChecks(AppsV1Api appsV1Api, CoreV1Api coreV1Api, String jobNamespace, Function.FunctionDetails functionDetails) { if (!StringUtils.isEmpty(functionDetails.getSecretsMap())) { Type type = new TypeToken<Map<String, Object>>() { }.getType(); Map<String, Object> secretsMap = new Gson().fromJson(functionDetails.getSecretsMap(), type); for (Object object : secretsMap.values()) { if (object instanceof Map) { Map<String, String> kubernetesSecret = (Map<String, String>) object; if (kubernetesSecret.size() < 2) { throw new IllegalArgumentException("Kubernetes Secret should contain id and key"); } if (!kubernetesSecret.containsKey(ID_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain id information"); } if (!kubernetesSecret.containsKey(KEY_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain key information"); } } else { throw new IllegalArgumentException("Kubernetes Secret should be a Map containing id/key pairs"); } } } } }
KubernetesSecretsProviderConfigurator implements SecretsProviderConfigurator { @Override public void doAdmissionChecks(AppsV1Api appsV1Api, CoreV1Api coreV1Api, String jobNamespace, Function.FunctionDetails functionDetails) { if (!StringUtils.isEmpty(functionDetails.getSecretsMap())) { Type type = new TypeToken<Map<String, Object>>() { }.getType(); Map<String, Object> secretsMap = new Gson().fromJson(functionDetails.getSecretsMap(), type); for (Object object : secretsMap.values()) { if (object instanceof Map) { Map<String, String> kubernetesSecret = (Map<String, String>) object; if (kubernetesSecret.size() < 2) { throw new IllegalArgumentException("Kubernetes Secret should contain id and key"); } if (!kubernetesSecret.containsKey(ID_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain id information"); } if (!kubernetesSecret.containsKey(KEY_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain key information"); } } else { throw new IllegalArgumentException("Kubernetes Secret should be a Map containing id/key pairs"); } } } }  }
KubernetesSecretsProviderConfigurator implements SecretsProviderConfigurator { @Override public void doAdmissionChecks(AppsV1Api appsV1Api, CoreV1Api coreV1Api, String jobNamespace, Function.FunctionDetails functionDetails) { if (!StringUtils.isEmpty(functionDetails.getSecretsMap())) { Type type = new TypeToken<Map<String, Object>>() { }.getType(); Map<String, Object> secretsMap = new Gson().fromJson(functionDetails.getSecretsMap(), type); for (Object object : secretsMap.values()) { if (object instanceof Map) { Map<String, String> kubernetesSecret = (Map<String, String>) object; if (kubernetesSecret.size() < 2) { throw new IllegalArgumentException("Kubernetes Secret should contain id and key"); } if (!kubernetesSecret.containsKey(ID_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain id information"); } if (!kubernetesSecret.containsKey(KEY_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain key information"); } } else { throw new IllegalArgumentException("Kubernetes Secret should be a Map containing id/key pairs"); } } } }  @Override String getSecretsProviderClassName(Function.FunctionDetails functionDetails); @Override Map<String, String> getSecretsProviderConfig(Function.FunctionDetails functionDetails); @Override void configureKubernetesRuntimeSecretsProvider(V1PodSpec podSpec, String functionsContainerName, Function.FunctionDetails functionDetails); @Override void configureProcessRuntimeSecretsProvider(ProcessBuilder processBuilder, Function.FunctionDetails functionDetails); @Override Type getSecretObjectType(); @Override void doAdmissionChecks(AppsV1Api appsV1Api, CoreV1Api coreV1Api, String jobNamespace, Function.FunctionDetails functionDetails); }
KubernetesSecretsProviderConfigurator implements SecretsProviderConfigurator { @Override public void doAdmissionChecks(AppsV1Api appsV1Api, CoreV1Api coreV1Api, String jobNamespace, Function.FunctionDetails functionDetails) { if (!StringUtils.isEmpty(functionDetails.getSecretsMap())) { Type type = new TypeToken<Map<String, Object>>() { }.getType(); Map<String, Object> secretsMap = new Gson().fromJson(functionDetails.getSecretsMap(), type); for (Object object : secretsMap.values()) { if (object instanceof Map) { Map<String, String> kubernetesSecret = (Map<String, String>) object; if (kubernetesSecret.size() < 2) { throw new IllegalArgumentException("Kubernetes Secret should contain id and key"); } if (!kubernetesSecret.containsKey(ID_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain id information"); } if (!kubernetesSecret.containsKey(KEY_KEY)) { throw new IllegalArgumentException("Kubernetes Secret should contain key information"); } } else { throw new IllegalArgumentException("Kubernetes Secret should be a Map containing id/key pairs"); } } } }  @Override String getSecretsProviderClassName(Function.FunctionDetails functionDetails); @Override Map<String, String> getSecretsProviderConfig(Function.FunctionDetails functionDetails); @Override void configureKubernetesRuntimeSecretsProvider(V1PodSpec podSpec, String functionsContainerName, Function.FunctionDetails functionDetails); @Override void configureProcessRuntimeSecretsProvider(ProcessBuilder processBuilder, Function.FunctionDetails functionDetails); @Override Type getSecretObjectType(); @Override void doAdmissionChecks(AppsV1Api appsV1Api, CoreV1Api coreV1Api, String jobNamespace, Function.FunctionDetails functionDetails);  }