From 1d92209fc2e31db06d29385c4dfdc545fb6e1736 Mon Sep 17 00:00:00 2001 From: Martin Vogel <martin.vogel@sinc.de> Date: Thu, 29 Jun 2023 08:11:39 +0200 Subject: [PATCH] refactor(#664): improve readability --- .../fitconnect/cli/keygen/KeyWriter.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) 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 84fca0762..2869b6b20 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,25 +63,13 @@ 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(); - final Yaml yaml = new Yaml(options); - yaml.dump(data, writer); + new Yaml(options).dump(getConfigMap(dir), writer); writer.flush(); writeFile(Path.of(dir, "config.yml"), writer.toString()); @@ -89,6 +77,20 @@ 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); -- GitLab