static public String createSecret(KubernetesAccount account, String namespace, String name, List<SecretMountPair> files) { Map<String, String> contentMap = new HashMap<>(); for (SecretMountPair pair: files) { String contents; try { contents = new String(Base64.getEncoder().encode(IOUtils.toByteArray(new FileInputStream(pair.getContents())))); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Failed to read required config file: " + pair.getContents().getAbsolutePath() + ": " + e.getMessage(), e); } contentMap.put(pair.getName(), contents); } name = name + "-" + Math.abs(contentMap.hashCode()); TemplatedResource secret = new JinjaJarResource("/kubernetes/manifests/secret.yml"); Map<String, Object> bindings = new HashMap<>(); bindings.put("files", contentMap); bindings.put("name", name); bindings.put("namespace", namespace); secret.extendBindings(bindings); apply(account, secret.toString()); return name; }
File input = new File(p.getStagedFile(stagingPath)); File output = new File(p.getOutputFile()); return new SecretMountPair(input, output); }) .collect(Collectors.toList()); configSources.add(new ConfigSource() .setId(name) .setMountPath(files.get(0).getContents().getParent()) );
File input = new File(p.getStagedFile(stagingPath)); File output = new File(p.getOutputFile()); return new SecretMountPair(input, output); }) .collect(Collectors.toList()); configSources.add(new ConfigSource() .setId(spec.name) .setMountPath(files.get(0).getContents().getParent()) );
public static SecretSpec createSecretSpec(String namespace, String clusterName, String name, List<SecretMountPair> files) { Map<String, String> contentMap = new HashMap<>(); for (SecretMountPair pair: files) { String contents; try { contents = new String(Base64.getEncoder().encode(IOUtils.toByteArray(new FileInputStream(pair.getContents())))); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Failed to read required config file: " + pair.getContents().getAbsolutePath() + ": " + e.getMessage(), e); } contentMap.put(pair.getName(), contents); } SecretSpec spec = new SecretSpec(); spec.name = name + "-" + Math.abs(contentMap.hashCode()); spec.resource = new JinjaJarResource("/kubernetes/manifests/secret.yml"); Map<String, Object> bindings = new HashMap<>(); bindings.put("files", contentMap); bindings.put("name", spec.name); bindings.put("namespace", namespace); bindings.put("clusterName", clusterName); spec.resource.extendBindings(bindings); return spec; }