@Test public void outputConfigAndPasswordFiles() throws Exception { MockKeyGeneratorFactory.reset(); final KeyGenerator keyGenerator = MockKeyGeneratorFactory.getMockKeyGenerator(); Path publicKeyPath = Files.createTempFile(UUID.randomUUID().toString(), ""); Path privateKeyPath = Files.createTempFile(UUID.randomUUID().toString(), ""); Files.write(privateKeyPath, Arrays.asList("SOMEDATA")); Files.write(publicKeyPath, Arrays.asList("SOMEDATA")); KeyEncryptor keyEncryptor = mock(KeyEncryptor.class); FilesystemKeyPair keypair = new FilesystemKeyPair(publicKeyPath, privateKeyPath, keyEncryptor); when(keyGenerator.generate(anyString(), eq(null), eq(null))).thenReturn(keypair); Path unixSocketPath = Files.createTempFile(UUID.randomUUID().toString(), ".ipc"); Map<String, Object> params = new HashMap<>(); params.put("unixSocketPath", unixSocketPath.toString()); Path configFile = createAndPopulatePaths(getClass().getResource("/keygen-sample.json")); Path keyOutputPath = configFile.resolveSibling(UUID.randomUUID().toString()); Path configOutputPath = configFile.resolveSibling(UUID.randomUUID().toString() + ".json"); Path pwdOutputPath = configFile.resolveSibling(UUID.randomUUID().toString() + ".pwds"); assertThat(Files.exists(configOutputPath)).isFalse(); assertThat(Files.exists(pwdOutputPath)).isFalse(); CliResult result = cliDelegate.execute( "-keygen", "-filename", keyOutputPath.toString(), "-output", configOutputPath.toString(), "-configfile", configFile.toString(), "--pwdout", pwdOutputPath.toString()); assertThat(result).isNotNull(); assertThat(result.getStatus()).isEqualTo(0); assertThat(result.getConfig()).isNotNull(); assertThat(result.isSuppressStartup()).isTrue(); assertThat(Files.exists(configOutputPath)).isTrue(); configOutputPath.toFile().deleteOnExit(); assertThat(Files.exists(pwdOutputPath)).isTrue(); pwdOutputPath.toFile().deleteOnExit(); verify(keyGenerator).generate(anyString(), eq(null), eq(null)); verifyNoMoreInteractions(keyGenerator); try { cliDelegate.execute( "-keygen", "-filename", UUID.randomUUID().toString(), "-output", configOutputPath.toString(), "-configfile", configFile.toString()); failBecauseExceptionWasNotThrown(Exception.class); } catch (Exception ex) { assertThat(ex).isInstanceOf(UncheckedIOException.class); assertThat(ex.getCause()).isExactlyInstanceOf(FileAlreadyExistsException.class); } }
public CliResult execute(String... args) throws Exception { LOGGER.debug("Execute with args [{}]", String.join(",", args)); final CommandLine commandLine = new CommandLine(TesseraCommand.class); final CLIExceptionCapturer mapper = new CLIExceptionCapturer(); commandLine.addSubcommand(new CommandLine(CommandLine.HelpCommand.class)); commandLine.addSubcommand(new CommandLine(KeyGenCommand.class, new KeyGenCommandFactory())); commandLine.addSubcommand(new CommandLine(KeyUpdateCommand.class, new KeyUpdateCommandFactory())); commandLine .registerConverter(Config.class, new ConfigConverter()) .registerConverter(ArgonOptions.class, new ArgonOptionsConverter()) .setSeparator(" ") .setCaseInsensitiveEnumValuesAllowed(true) .setExecutionExceptionHandler(mapper) .setParameterExceptionHandler(mapper) .setStopAtUnmatched(false); final CommandLine.ParseResult parseResult; try { parseResult = commandLine.parseArgs(args); } catch (CommandLine.ParameterException ex) { try { commandLine.getParameterExceptionHandler().handleParseException(ex, args); throw new CliException(ex.getMessage()); } catch (Exception e) { throw new CliException(ex.getMessage()); } } if (CommandLine.printHelpIfRequested(parseResult)) { return new CliResult(0, true, null); } if (!parseResult.hasSubcommand()) { final Config config; try { config = getConfigFromCLI(parseResult); } catch (NoTesseraCmdArgsException e) { commandLine.execute("help"); return new CliResult(0, true, null); } catch (NoTesseraConfigfileOptionException e) { throw new CliException("Missing required option '--configfile <config>'"); } LOGGER.debug("Executed with args [{}]", String.join(",", args)); LOGGER.trace("Config {}", JaxbUtil.marshalToString(config)); return new CliResult(0, false, config); } if (args.length == 1) { final CommandLine.ParseResult subcommand = parseResult.subcommand(); subcommand.asCommandLineList().get(0).execute("help"); return new CliResult(0, true, null); } commandLine.execute(args); if (mapper.getThrown() != null) { throw mapper.getThrown(); } return new CliResult(0, true, null); }
PicoCliDelegate { public CliResult execute(String... args) throws Exception { LOGGER.debug("Execute with args [{}]", String.join(",", args)); final CommandLine commandLine = new CommandLine(TesseraCommand.class); final CLIExceptionCapturer mapper = new CLIExceptionCapturer(); commandLine.addSubcommand(new CommandLine(CommandLine.HelpCommand.class)); commandLine.addSubcommand(new CommandLine(KeyGenCommand.class, new KeyGenCommandFactory())); commandLine.addSubcommand(new CommandLine(KeyUpdateCommand.class, new KeyUpdateCommandFactory())); commandLine .registerConverter(Config.class, new ConfigConverter()) .registerConverter(ArgonOptions.class, new ArgonOptionsConverter()) .setSeparator(" ") .setCaseInsensitiveEnumValuesAllowed(true) .setExecutionExceptionHandler(mapper) .setParameterExceptionHandler(mapper) .setStopAtUnmatched(false); final CommandLine.ParseResult parseResult; try { parseResult = commandLine.parseArgs(args); } catch (CommandLine.ParameterException ex) { try { commandLine.getParameterExceptionHandler().handleParseException(ex, args); throw new CliException(ex.getMessage()); } catch (Exception e) { throw new CliException(ex.getMessage()); } } if (CommandLine.printHelpIfRequested(parseResult)) { return new CliResult(0, true, null); } if (!parseResult.hasSubcommand()) { final Config config; try { config = getConfigFromCLI(parseResult); } catch (NoTesseraCmdArgsException e) { commandLine.execute("help"); return new CliResult(0, true, null); } catch (NoTesseraConfigfileOptionException e) { throw new CliException("Missing required option '--configfile <config>'"); } LOGGER.debug("Executed with args [{}]", String.join(",", args)); LOGGER.trace("Config {}", JaxbUtil.marshalToString(config)); return new CliResult(0, false, config); } if (args.length == 1) { final CommandLine.ParseResult subcommand = parseResult.subcommand(); subcommand.asCommandLineList().get(0).execute("help"); return new CliResult(0, true, null); } commandLine.execute(args); if (mapper.getThrown() != null) { throw mapper.getThrown(); } return new CliResult(0, true, null); } }
PicoCliDelegate { public CliResult execute(String... args) throws Exception { LOGGER.debug("Execute with args [{}]", String.join(",", args)); final CommandLine commandLine = new CommandLine(TesseraCommand.class); final CLIExceptionCapturer mapper = new CLIExceptionCapturer(); commandLine.addSubcommand(new CommandLine(CommandLine.HelpCommand.class)); commandLine.addSubcommand(new CommandLine(KeyGenCommand.class, new KeyGenCommandFactory())); commandLine.addSubcommand(new CommandLine(KeyUpdateCommand.class, new KeyUpdateCommandFactory())); commandLine .registerConverter(Config.class, new ConfigConverter()) .registerConverter(ArgonOptions.class, new ArgonOptionsConverter()) .setSeparator(" ") .setCaseInsensitiveEnumValuesAllowed(true) .setExecutionExceptionHandler(mapper) .setParameterExceptionHandler(mapper) .setStopAtUnmatched(false); final CommandLine.ParseResult parseResult; try { parseResult = commandLine.parseArgs(args); } catch (CommandLine.ParameterException ex) { try { commandLine.getParameterExceptionHandler().handleParseException(ex, args); throw new CliException(ex.getMessage()); } catch (Exception e) { throw new CliException(ex.getMessage()); } } if (CommandLine.printHelpIfRequested(parseResult)) { return new CliResult(0, true, null); } if (!parseResult.hasSubcommand()) { final Config config; try { config = getConfigFromCLI(parseResult); } catch (NoTesseraCmdArgsException e) { commandLine.execute("help"); return new CliResult(0, true, null); } catch (NoTesseraConfigfileOptionException e) { throw new CliException("Missing required option '--configfile <config>'"); } LOGGER.debug("Executed with args [{}]", String.join(",", args)); LOGGER.trace("Config {}", JaxbUtil.marshalToString(config)); return new CliResult(0, false, config); } if (args.length == 1) { final CommandLine.ParseResult subcommand = parseResult.subcommand(); subcommand.asCommandLineList().get(0).execute("help"); return new CliResult(0, true, null); } commandLine.execute(args); if (mapper.getThrown() != null) { throw mapper.getThrown(); } return new CliResult(0, true, null); } PicoCliDelegate(); private  PicoCliDelegate(final KeyPasswordResolver keyPasswordResolver); }
PicoCliDelegate { public CliResult execute(String... args) throws Exception { LOGGER.debug("Execute with args [{}]", String.join(",", args)); final CommandLine commandLine = new CommandLine(TesseraCommand.class); final CLIExceptionCapturer mapper = new CLIExceptionCapturer(); commandLine.addSubcommand(new CommandLine(CommandLine.HelpCommand.class)); commandLine.addSubcommand(new CommandLine(KeyGenCommand.class, new KeyGenCommandFactory())); commandLine.addSubcommand(new CommandLine(KeyUpdateCommand.class, new KeyUpdateCommandFactory())); commandLine .registerConverter(Config.class, new ConfigConverter()) .registerConverter(ArgonOptions.class, new ArgonOptionsConverter()) .setSeparator(" ") .setCaseInsensitiveEnumValuesAllowed(true) .setExecutionExceptionHandler(mapper) .setParameterExceptionHandler(mapper) .setStopAtUnmatched(false); final CommandLine.ParseResult parseResult; try { parseResult = commandLine.parseArgs(args); } catch (CommandLine.ParameterException ex) { try { commandLine.getParameterExceptionHandler().handleParseException(ex, args); throw new CliException(ex.getMessage()); } catch (Exception e) { throw new CliException(ex.getMessage()); } } if (CommandLine.printHelpIfRequested(parseResult)) { return new CliResult(0, true, null); } if (!parseResult.hasSubcommand()) { final Config config; try { config = getConfigFromCLI(parseResult); } catch (NoTesseraCmdArgsException e) { commandLine.execute("help"); return new CliResult(0, true, null); } catch (NoTesseraConfigfileOptionException e) { throw new CliException("Missing required option '--configfile <config>'"); } LOGGER.debug("Executed with args [{}]", String.join(",", args)); LOGGER.trace("Config {}", JaxbUtil.marshalToString(config)); return new CliResult(0, false, config); } if (args.length == 1) { final CommandLine.ParseResult subcommand = parseResult.subcommand(); subcommand.asCommandLineList().get(0).execute("help"); return new CliResult(0, true, null); } commandLine.execute(args); if (mapper.getThrown() != null) { throw mapper.getThrown(); } return new CliResult(0, true, null); } PicoCliDelegate(); private  PicoCliDelegate(final KeyPasswordResolver keyPasswordResolver); CliResult execute(String... args); }
PicoCliDelegate { public CliResult execute(String... args) throws Exception { LOGGER.debug("Execute with args [{}]", String.join(",", args)); final CommandLine commandLine = new CommandLine(TesseraCommand.class); final CLIExceptionCapturer mapper = new CLIExceptionCapturer(); commandLine.addSubcommand(new CommandLine(CommandLine.HelpCommand.class)); commandLine.addSubcommand(new CommandLine(KeyGenCommand.class, new KeyGenCommandFactory())); commandLine.addSubcommand(new CommandLine(KeyUpdateCommand.class, new KeyUpdateCommandFactory())); commandLine .registerConverter(Config.class, new ConfigConverter()) .registerConverter(ArgonOptions.class, new ArgonOptionsConverter()) .setSeparator(" ") .setCaseInsensitiveEnumValuesAllowed(true) .setExecutionExceptionHandler(mapper) .setParameterExceptionHandler(mapper) .setStopAtUnmatched(false); final CommandLine.ParseResult parseResult; try { parseResult = commandLine.parseArgs(args); } catch (CommandLine.ParameterException ex) { try { commandLine.getParameterExceptionHandler().handleParseException(ex, args); throw new CliException(ex.getMessage()); } catch (Exception e) { throw new CliException(ex.getMessage()); } } if (CommandLine.printHelpIfRequested(parseResult)) { return new CliResult(0, true, null); } if (!parseResult.hasSubcommand()) { final Config config; try { config = getConfigFromCLI(parseResult); } catch (NoTesseraCmdArgsException e) { commandLine.execute("help"); return new CliResult(0, true, null); } catch (NoTesseraConfigfileOptionException e) { throw new CliException("Missing required option '--configfile <config>'"); } LOGGER.debug("Executed with args [{}]", String.join(",", args)); LOGGER.trace("Config {}", JaxbUtil.marshalToString(config)); return new CliResult(0, false, config); } if (args.length == 1) { final CommandLine.ParseResult subcommand = parseResult.subcommand(); subcommand.asCommandLineList().get(0).execute("help"); return new CliResult(0, true, null); } commandLine.execute(args); if (mapper.getThrown() != null) { throw mapper.getThrown(); } return new CliResult(0, true, null); } PicoCliDelegate(); private  PicoCliDelegate(final KeyPasswordResolver keyPasswordResolver); CliResult execute(String... args);  }