Search in sources :

Example 1 with CliResult

use of com.quorum.tessera.cli.CliResult 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 CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method updatingPasswordsDoesntProcessOtherOptions.

@Test
public void updatingPasswordsDoesntProcessOtherOptions() throws Exception {
    final InputStream oldIn = System.in;
    final InputStream inputStream = new ByteArrayInputStream((System.lineSeparator() + System.lineSeparator()).getBytes());
    System.setIn(inputStream);
    final KeyDataConfig startingKey = JaxbUtil.unmarshal(getClass().getResourceAsStream("/lockedprivatekey.json"), KeyDataConfig.class);
    final Path key = Files.createTempFile("key", ".key");
    Files.write(key, JaxbUtil.marshalToString(startingKey).getBytes());
    final CliResult result = cliDelegate.execute("-updatepassword", "--keys.keyData.privateKeyPath", key.toString(), "--keys.passwords", "testpassword");
    assertThat(result).isNotNull();
    System.setIn(oldIn);
}
Also used : Path(java.nio.file.Path) KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) CliResult(com.quorum.tessera.cli.CliResult) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 3 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method overrideAlwaysSendTo.

@Test
public void overrideAlwaysSendTo() throws Exception {
    String alwaysSendToKey = "giizjhZQM6peq52O7icVFxdTmTYinQSUsvyhXzgZqkE=";
    Path configFile = Paths.get(getClass().getResource("/sample-config.json").toURI());
    CliResult result = null;
    try {
        result = cliDelegate.execute("-configfile", configFile.toString(), "-o", Strings.join("alwaysSendTo[1]=", alwaysSendToKey).with(""));
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isPresent();
    assertThat(result.getConfig().get().getAlwaysSendTo()).hasSize(2);
    assertThat(result.getConfig().get().getAlwaysSendTo()).containsExactly("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=", alwaysSendToKey);
}
Also used : Path(java.nio.file.Path) CliResult(com.quorum.tessera.cli.CliResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CliException(com.quorum.tessera.cli.CliException) ConstraintViolationException(jakarta.validation.ConstraintViolationException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.Test)

Example 4 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method suppressStartupForKeygenOption.

@Test
public void suppressStartupForKeygenOption() throws Exception {
    when(keyGenerator.generate(anyString(), eq(null), eq(null))).thenReturn(mock(DirectKeyPair.class));
    final CliResult cliResult = cliDelegate.execute("-keygen", "--encryptor.type", "NACL");
    assertThat(cliResult.isSuppressStartup()).isTrue();
    verify(keyGenerator).generate(anyString(), eq(null), eq(null));
}
Also used : CliResult(com.quorum.tessera.cli.CliResult) DirectKeyPair(com.quorum.tessera.config.keypairs.DirectKeyPair) Test(org.junit.Test)

Example 5 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method overridePeers.

@Test
public void overridePeers() throws Exception {
    Path configFile = Paths.get(getClass().getResource("/sample-config.json").toURI());
    CliResult result = cliDelegate.execute("-configfile", configFile.toString(), "-o", "peer[2].url=http://anotherpeer", "--override", "peer[3].url=http://yetanotherpeer");
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isPresent();
    assertThat(result.getConfig().get().getPeers()).hasSize(4);
    assertThat(result.getConfig().get().getPeers().stream().map(Peer::getUrl)).containsExactlyInAnyOrder("http://anotherpeer", "http://yetanotherpeer", "http://bogus1.com", "http://bogus2.com");
}
Also used : Path(java.nio.file.Path) CliResult(com.quorum.tessera.cli.CliResult) Peer(com.quorum.tessera.config.Peer) Test(org.junit.Test)

Aggregations

CliResult (com.quorum.tessera.cli.CliResult)38 Test (org.junit.Test)29 Path (java.nio.file.Path)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 CommandLine (picocli.CommandLine)9 CliException (com.quorum.tessera.cli.CliException)7 ConstraintViolationException (jakarta.validation.ConstraintViolationException)7 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)6 Config (com.quorum.tessera.config.Config)5 ConfigConverter (com.quorum.tessera.cli.parsers.ConfigConverter)4 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)4 KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)3 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)3 ConstraintViolation (jakarta.validation.ConstraintViolation)3 UncheckedIOException (java.io.UncheckedIOException)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 HashMap (java.util.HashMap)3 Enclave (com.quorum.tessera.enclave.Enclave)2 EnclaveCliAdapter (com.quorum.tessera.enclave.server.EnclaveCliAdapter)2 TesseraServer (com.quorum.tessera.server.TesseraServer)2