diff --git a/cli/src/main/java/dev/fitko/fitconnect/cli/keygen/KeyWriter.java b/cli/src/main/java/dev/fitko/fitconnect/cli/keygen/KeyWriter.java index 2869b6b2042b5fe954513ba169a7f540d995a6d4..84fca07628638ef5a1ab7e1ac1fbc152797cad44 100644 --- a/cli/src/main/java/dev/fitko/fitconnect/cli/keygen/KeyWriter.java +++ b/cli/src/main/java/dev/fitko/fitconnect/cli/keygen/KeyWriter.java @@ -63,13 +63,25 @@ public final class KeyWriter { private void writeConfigYamlToFile(final String dir) { + final Map<String, Object> data = new LinkedHashMap<>(); + data.put("senderConfig", + Map.of("clientSecret", "", + "clientId", "")); + data.put("subscriberConfig", + Map.of("clientSecret", "", + "clientId", "", + "privateDecryptionKeyPaths", List.of(Path.of(dir, PRIVATE_DECRYPTION_KEY_NAME).toAbsolutePath().toString()), + "privateSigningKeyPath", Path.of(dir,PRIVATE_SIGNING_KEY_NAME).toAbsolutePath().toString())); + data.put("activeEnvironment", DefaultEnvironments.TEST.getEnvironmentName().getName()); + final DumperOptions options = new DumperOptions(); options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setPrettyFlow(true); final StringWriter writer = new StringWriter(); - new Yaml(options).dump(getConfigMap(dir), writer); + final Yaml yaml = new Yaml(options); + yaml.dump(data, writer); writer.flush(); writeFile(Path.of(dir, "config.yml"), writer.toString()); @@ -77,20 +89,6 @@ public final class KeyWriter { LOGGER.info("Wrote config.yml"); } - private static Map<String, Object> getConfigMap(final String dir) { - final Map<String, Object> data = new LinkedHashMap<>(); - data.put("senderConfig", - Map.of("clientSecret", "", - "clientId", "")); - data.put("subscriberConfig", - Map.of("clientSecret", "", - "clientId", "", - "privateDecryptionKeyPaths", List.of(Path.of(dir, PRIVATE_DECRYPTION_KEY_NAME).toAbsolutePath().toString()), - "privateSigningKeyPath", Path.of(dir,PRIVATE_SIGNING_KEY_NAME).toAbsolutePath().toString())); - data.put("activeEnvironment", DefaultEnvironments.TEST.getEnvironmentName().getName()); - return data; - } - private void writeKeyToFile(final String dir, final String filename, final String desc, final JWK jwk) { writeFile(Path.of(dir, filename), jwk.toJSONString()); LOGGER.info("Wrote {} as {}", desc, filename);