Search in sources :

Example 56 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class KeyGenFileUpdateOptionsTest method configFileAndConfigoutAndPwout.

@Test
public void configFileAndConfigoutAndPwout() throws Exception {
    Config config = mock(Config.class);
    when(converter.convert(anyString())).thenReturn(config);
    CommandLine commandLine = new CommandLine(keyGenFileUpdateOptions);
    CommandLine.ParseResult result = commandLine.registerConverter(Config.class, converter).parseArgs("--configfile=myfile", "--configout=myconfigout", "--pwdout=mypwdout");
    assertThat(result).isNotNull();
    verify(converter).convert("myfile");
    assertThat(keyGenFileUpdateOptions.getConfig()).isSameAs(config);
    assertThat(keyGenFileUpdateOptions.getConfigOut()).isEqualTo(Paths.get("myconfigout"));
    assertThat(keyGenFileUpdateOptions.getPwdOut()).isEqualTo(Paths.get("mypwdout"));
    assertThat(result.unmatched()).isEmpty();
    assertThat(result.matchedArgs()).hasSize(3);
    assertThat(result.hasMatchedOption("--configfile")).isTrue();
    assertThat(result.hasMatchedOption("--configout")).isTrue();
    assertThat(result.hasMatchedOption("--pwdout")).isTrue();
}
Also used : CommandLine(picocli.CommandLine) Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Example 57 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class CliResultTest method getConfig.

@Test
public void getConfig() {
    Config config = new Config();
    CliResult result = new CliResult(1, false, config);
    assertThat(result.getConfig()).isNotEmpty();
    assertThat(result.getConfig().get()).isEqualTo(config);
}
Also used : Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Example 58 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class MigrationTest method beforeTest.

@Before
public void beforeTest() throws IOException {
    Config primaryConfig = new Config();
    primaryConfig.setJdbcConfig(new JdbcConfig());
    primaryConfig.getJdbcConfig().setUsername("junit");
    primaryConfig.getJdbcConfig().setPassword("junit");
    String primaryJdbcUrl = "jdbc:h2:" + workDir.getRoot().toPath().resolve("primary.db").toString();
    primaryConfig.getJdbcConfig().setUrl(primaryJdbcUrl);
    Config secondaryConfig = new Config();
    secondaryConfig.setJdbcConfig(new JdbcConfig());
    secondaryConfig.getJdbcConfig().setUsername("junit");
    secondaryConfig.getJdbcConfig().setPassword("junit");
    String secondaryJdbcUrl = "jdbc:h2:" + workDir.getRoot().toPath().resolve("secondary.db").toString();
    secondaryConfig.getJdbcConfig().setUrl(secondaryJdbcUrl);
    primaryConfigPath = workDir.getRoot().toPath().toAbsolutePath().resolve("primary-confg.json");
    try (OutputStream outputStream = Files.newOutputStream(primaryConfigPath)) {
        JaxbUtil.marshalWithNoValidation(primaryConfig, outputStream);
    }
    secondaryConfigPath = workDir.getRoot().toPath().toAbsolutePath().resolve("secondary-confg.json");
    try (OutputStream outputStream = Files.newOutputStream(secondaryConfigPath)) {
        JaxbUtil.marshalWithNoValidation(secondaryConfig, outputStream);
    }
    args = List.of("--primary", primaryConfigPath.toString(), "--secondary", secondaryConfigPath.toString());
    primaryEntityManagerFactory = Optional.of(primaryConfig).map(Config::getJdbcConfig).map(JdbcConfigUtil::toMap).map(m -> new HashMap(m)).map(p -> {
        p.put("jakarta.persistence.schema-generation.database.action", "drop-and-create");
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("tessera", p);
        emf.createEntityManager();
        return emf;
    }).get();
    secondaryEntityManagerFactory = Optional.of(secondaryConfig).map(Config::getJdbcConfig).map(JdbcConfigUtil::toMap).map(m -> new HashMap(m)).map(p -> {
        p.put("jakarta.persistence.schema-generation.database.action", "create");
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("tessera", p);
        return emf;
    }).get();
    EntityManager secondaryEntityManager = secondaryEntityManagerFactory.createEntityManager();
    secondaryEntityManager.getTransaction().begin();
    IntStream.range(0, encryptedTransactionCount).forEach(i -> {
        EncryptedTransaction encryptedTransaction = generateEncryptedTransaction();
        secondaryEntityManager.persist(encryptedTransaction);
    });
    secondaryEntityManager.getTransaction().commit();
    secondaryEntityManager.getTransaction().begin();
    IntStream.range(0, encryptedRawTransactionCount).forEach(i -> {
        EncryptedRawTransaction encryptedRawTransaction = generateEncryptedRawTransaction();
        secondaryEntityManager.persist(encryptedRawTransaction);
    });
    secondaryEntityManager.getTransaction().commit();
}
Also used : IntStream(java.util.stream.IntStream) PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) PrivacyMode(com.quorum.tessera.enclave.PrivacyMode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) JaxbUtil(com.quorum.tessera.config.util.JaxbUtil) After(org.junit.After) MessageHash(com.quorum.tessera.data.MessageHash) Path(java.nio.file.Path) Parameterized(org.junit.runners.Parameterized) CommandLine(picocli.CommandLine) Before(org.junit.Before) OutputStream(java.io.OutputStream) EncryptedRawTransaction(com.quorum.tessera.data.EncryptedRawTransaction) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Files(java.nio.file.Files) JdbcConfig(com.quorum.tessera.config.JdbcConfig) IOException(java.io.IOException) Test(org.junit.Test) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) Rule(org.junit.Rule) Persistence(jakarta.persistence.Persistence) ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) EntityManager(jakarta.persistence.EntityManager) Config(com.quorum.tessera.config.Config) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) CliType(com.quorum.tessera.cli.CliType) TemporaryFolder(org.junit.rules.TemporaryFolder) EntityManager(jakarta.persistence.EntityManager) JdbcConfig(com.quorum.tessera.config.JdbcConfig) Config(com.quorum.tessera.config.Config) OutputStream(java.io.OutputStream) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) JdbcConfig(com.quorum.tessera.config.JdbcConfig) EncryptedRawTransaction(com.quorum.tessera.data.EncryptedRawTransaction) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Before(org.junit.Before)

Example 59 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class AzureKeyVaultServiceFactory method create.

@Override
public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider) {
    Objects.requireNonNull(config);
    final KeyVaultConfig keyVaultConfig = Optional.ofNullable(config.getKeys()).flatMap(k -> k.getKeyVaultConfig(KeyVaultType.AZURE)).orElseThrow(() -> new ConfigException(new RuntimeException("Trying to create Azure key vault connection but no Azure configuration provided")));
    final String url = keyVaultConfig.getProperty("url").orElseThrow(() -> new ConfigException(new RuntimeException("No Azure Key Vault url provided")));
    final SecretClient secretClient = new SecretClientBuilder().vaultUrl(url).httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)).credential(new DefaultAzureCredentialBuilder().build()).buildClient();
    return new AzureKeyVaultService(secretClient);
}
Also used : KeyVaultType(com.quorum.tessera.config.KeyVaultType) KeyVaultConfig(com.quorum.tessera.config.KeyVaultConfig) DefaultAzureCredentialBuilder(com.azure.identity.DefaultAzureCredentialBuilder) HttpLogOptions(com.azure.core.http.policy.HttpLogOptions) SecretClientBuilder(com.azure.security.keyvault.secrets.SecretClientBuilder) KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) KeyVaultServiceFactory(com.quorum.tessera.key.vault.KeyVaultServiceFactory) Objects(java.util.Objects) ConfigException(com.quorum.tessera.config.ConfigException) Optional(java.util.Optional) SecretClient(com.azure.security.keyvault.secrets.SecretClient) Config(com.quorum.tessera.config.Config) EnvironmentVariableProvider(com.quorum.tessera.config.util.EnvironmentVariableProvider) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) DefaultAzureCredentialBuilder(com.azure.identity.DefaultAzureCredentialBuilder) SecretClientBuilder(com.azure.security.keyvault.secrets.SecretClientBuilder) KeyVaultConfig(com.quorum.tessera.config.KeyVaultConfig) ConfigException(com.quorum.tessera.config.ConfigException) HttpLogOptions(com.azure.core.http.policy.HttpLogOptions) SecretClient(com.azure.security.keyvault.secrets.SecretClient)

Example 60 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class P2pClientProvider method provider.

public static P2pClient provider() {
    Config config = ConfigFactory.create().getConfig();
    SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();
    ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
    Client client = clientFactory.buildFrom(config.getP2PServerConfig());
    return new RestP2pClient(client);
}
Also used : Config(com.quorum.tessera.config.Config) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) ClientSSLContextFactory(com.quorum.tessera.ssl.context.ClientSSLContextFactory) SSLContextFactory(com.quorum.tessera.ssl.context.SSLContextFactory) Client(jakarta.ws.rs.client.Client) P2pClient(com.quorum.tessera.partyinfo.P2pClient)

Aggregations

Config (com.quorum.tessera.config.Config)78 Test (org.junit.Test)54 ServerConfig (com.quorum.tessera.config.ServerConfig)20 ConfigFactory (com.quorum.tessera.config.ConfigFactory)18 Path (java.nio.file.Path)11 Before (org.junit.Before)11 ResidentGroup (com.quorum.tessera.config.ResidentGroup)9 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)9 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)9 Client (jakarta.ws.rs.client.Client)9 JdbcConfig (com.quorum.tessera.config.JdbcConfig)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 After (org.junit.After)7 CommandLine (picocli.CommandLine)7 PrivacyViolationException (com.quorum.tessera.transaction.exception.PrivacyViolationException)6 CliResult (com.quorum.tessera.cli.CliResult)5 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)5 PublicKey (com.quorum.tessera.encryption.PublicKey)5