Search in sources :

Example 1 with ConfigConverter

use of com.quorum.tessera.cli.parsers.ConfigConverter in project tessera by ConsenSys.

the class Main method main.

public static void main(String... args) {
    try {
        final CommandLine commandLine = new CommandLine(new MigrationCliAdapter());
        commandLine.registerConverter(Config.class, new ConfigConverter()).setSeparator(" ").setCaseInsensitiveEnumValuesAllowed(true);
        commandLine.execute(args);
        final CliResult cliResult = commandLine.getExecutionResult();
        System.exit(cliResult.getStatus());
    } catch (final Exception ex) {
        System.err.println(ex.toString());
        System.exit(1);
    }
}
Also used : ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) CommandLine(picocli.CommandLine) CliResult(com.quorum.tessera.cli.CliResult)

Example 2 with ConfigConverter

use of com.quorum.tessera.cli.parsers.ConfigConverter in project tessera by ConsenSys.

the class PicoCliDelegate method execute.

public CliResult execute(String... args) throws Exception {
    LOGGER.debug("Execute with args [{}]", String.join(",", args));
    final CommandLine commandLine = new CommandLine(TesseraCommand.class);
    final CLIExceptionCapturer exceptionCapturer = new CLIExceptionCapturer();
    commandLine.addSubcommand(new CommandLine(CommandLine.HelpCommand.class));
    commandLine.addSubcommand(new CommandLine(VersionCommand.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(exceptionCapturer).setParameterExceptionHandler(exceptionCapturer).setStopAtUnmatched(false);
    try {
        // parse the args so that we can print usage help if no cmd args were provided
        final CommandLine.ParseResult parseResult = commandLine.parseArgs(args);
        final List<CommandLine> l = parseResult.asCommandLineList();
        final CommandLine lastCmd = l.get(l.size() - 1);
        // print help if no args were provided
        if (lastCmd.getParseResult().matchedArgs().size() == 0 && !"help".equals(lastCmd.getCommandName()) && !"version".equals(lastCmd.getCommandName())) {
            lastCmd.usage(lastCmd.getOut());
        } else {
            commandLine.execute(args);
        }
    } catch (CommandLine.ParameterException ex) {
        exceptionCapturer.handleParseException(ex, args);
    }
    // if an exception occurred, throw it to to the upper levels where it gets handled
    if (exceptionCapturer.getThrown() != null) {
        throw exceptionCapturer.getThrown();
    }
    return (CliResult) Optional.ofNullable(commandLine.getExecutionResult()).orElse(new CliResult(0, true, null));
}
Also used : ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) ArgonOptions(com.quorum.tessera.config.ArgonOptions) CommandLine(picocli.CommandLine) CLIExceptionCapturer(com.quorum.tessera.cli.CLIExceptionCapturer) CliResult(com.quorum.tessera.cli.CliResult)

Example 3 with ConfigConverter

use of com.quorum.tessera.cli.parsers.ConfigConverter in project tessera by ConsenSys.

the class Main method main.

public static void main(String... args) throws Exception {
    Security.addProvider(new BouncyCastleProvider());
    final CommandLine commandLine = new CommandLine(new EnclaveCliAdapter());
    commandLine.registerConverter(Config.class, new ConfigConverter()).setSeparator(" ").setCaseInsensitiveEnumValuesAllowed(true);
    commandLine.execute(args);
    final CliResult cliResult = commandLine.getExecutionResult();
    if (cliResult == null) {
        System.exit(1);
    }
    if (!cliResult.getConfig().isPresent()) {
        System.exit(cliResult.getStatus());
    }
    final TesseraServerFactory restServerFactory = TesseraServerFactory.create(CommunicationType.REST);
    final Config config = cliResult.getConfig().get();
    ConfigFactory.create().store(config);
    final ServerConfig serverConfig = config.getServerConfigs().stream().findFirst().get();
    Enclave enclave = EnclaveServer.create();
    LOGGER.debug("Created enclave {}", enclave);
    final TesseraServer server = restServerFactory.createServer(serverConfig, Set.of(new EnclaveApplication(enclave)));
    server.start();
    CountDownLatch latch = new CountDownLatch(1);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        try {
            server.stop();
        } catch (Exception ex) {
            LOGGER.error(null, ex);
        } finally {
        }
    }));
    latch.await();
}
Also used : ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) TesseraServerFactory(com.quorum.tessera.server.TesseraServerFactory) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) ServerConfig(com.quorum.tessera.config.ServerConfig) TesseraServer(com.quorum.tessera.server.TesseraServer) CommandLine(picocli.CommandLine) CliResult(com.quorum.tessera.cli.CliResult) EnclaveCliAdapter(com.quorum.tessera.enclave.server.EnclaveCliAdapter) Enclave(com.quorum.tessera.enclave.Enclave) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 4 with ConfigConverter

use of com.quorum.tessera.cli.parsers.ConfigConverter in project tessera by ConsenSys.

the class EnclaveRestIT method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty(CliType.CLI_TYPE_KEY, CliType.ENCLAVE.name());
    URL url = EnclaveRestIT.class.getResource("/sample-config.json");
    final CommandLine commandLine = new CommandLine(new EnclaveCliAdapter());
    commandLine.registerConverter(Config.class, new ConfigConverter()).setSeparator(" ").setCaseInsensitiveEnumValuesAllowed(true);
    commandLine.execute("-configfile", url.getFile());
    CliResult cliResult = commandLine.getExecutionResult();
    Config config = cliResult.getConfig().get();
    ConfigFactory.create().store(config);
    this.enclave = Enclave.create();
    jersey = Util.create(enclave);
    jersey.setUp();
    enclaveClient = new RestfulEnclaveClient(jersey.client(), jersey.target().getUri());
}
Also used : ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) CommandLine(picocli.CommandLine) CliResult(com.quorum.tessera.cli.CliResult) EnclaveCliAdapter(com.quorum.tessera.enclave.server.EnclaveCliAdapter) Config(com.quorum.tessera.config.Config) URL(java.net.URL) Before(org.junit.Before)

Example 5 with ConfigConverter

use of com.quorum.tessera.cli.parsers.ConfigConverter in project tessera by ConsenSys.

the class EnclaveCliAdapterTest method onSetUp.

@Before
public void onSetUp() {
    System.setProperty(CliType.CLI_TYPE_KEY, CliType.ENCLAVE.name());
    this.systemErrOutput.clearLog();
    commandLine = new CommandLine(new EnclaveCliAdapter());
    commandLine.registerConverter(Config.class, new ConfigConverter()).setSeparator(" ").setCaseInsensitiveEnumValuesAllowed(true);
}
Also used : ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) CommandLine(picocli.CommandLine) Before(org.junit.Before)

Aggregations

ConfigConverter (com.quorum.tessera.cli.parsers.ConfigConverter)6 CommandLine (picocli.CommandLine)6 CliResult (com.quorum.tessera.cli.CliResult)4 Config (com.quorum.tessera.config.Config)2 EnclaveCliAdapter (com.quorum.tessera.enclave.server.EnclaveCliAdapter)2 Before (org.junit.Before)2 CLIExceptionCapturer (com.quorum.tessera.cli.CLIExceptionCapturer)1 ArgonOptions (com.quorum.tessera.config.ArgonOptions)1 ServerConfig (com.quorum.tessera.config.ServerConfig)1 EncryptedRawTransaction (com.quorum.tessera.data.EncryptedRawTransaction)1 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)1 Enclave (com.quorum.tessera.enclave.Enclave)1 TesseraServer (com.quorum.tessera.server.TesseraServer)1 TesseraServerFactory (com.quorum.tessera.server.TesseraServerFactory)1 EntityManager (jakarta.persistence.EntityManager)1 URL (java.net.URL)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 Test (org.junit.Test)1