Search in sources :

Example 16 with SmallRyeConfig

use of io.smallrye.config.SmallRyeConfig in project keycloak by keycloak.

the class ConfigurationTest method testSetDbUrlOverridesDefaultDataSource.

@Test
public void testSetDbUrlOverridesDefaultDataSource() {
    System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url=jdbc:mariadb://localhost/keycloak");
    SmallRyeConfig config = createConfig();
    assertEquals("org.hibernate.dialect.MariaDBDialect", config.getConfigValue("quarkus.hibernate-orm.dialect").getValue());
    assertEquals("jdbc:mariadb://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
    assertEquals("mariadb", config.getConfigValue("quarkus.datasource.db-kind").getValue());
}
Also used : SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Test(org.junit.Test)

Example 17 with SmallRyeConfig

use of io.smallrye.config.SmallRyeConfig in project keycloak by keycloak.

the class ConfigurationTest method testDatabaseDriverSetExplicitly.

@Test
public void testDatabaseDriverSetExplicitly() {
    System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--db-url=jdbc:sqlserver://localhost/keycloak");
    System.setProperty("kc.db-driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
    System.setProperty("kc.transaction-xa-enabled", "false");
    assertTrue(System.getProperty(CLI_ARGS, "").contains("mssql"));
    SmallRyeConfig config = createConfig();
    assertEquals("jdbc:sqlserver://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
    assertEquals("mssql", config.getConfigValue("quarkus.datasource.db-kind").getValue());
    assertEquals("com.microsoft.sqlserver.jdbc.SQLServerDriver", config.getConfigValue("quarkus.datasource.jdbc.driver").getValue());
    assertEquals("enabled", config.getConfigValue("quarkus.datasource.jdbc.transactions").getValue());
}
Also used : SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Test(org.junit.Test)

Example 18 with SmallRyeConfig

use of io.smallrye.config.SmallRyeConfig in project camel-quarkus by apache.

the class AzureStorageTestResource method start.

@Override
public Map<String, String> start() {
    final SmallRyeConfig config = ConfigUtils.configBuilder(true, LaunchMode.NORMAL).build();
    final String realAzureStorageAccountName = System.getenv("AZURE_STORAGE_ACCOUNT_NAME");
    final boolean realCredentialsProvided = realAzureStorageAccountName != null && System.getenv("AZURE_STORAGE_ACCOUNT_KEY") != null;
    final String azureBlobContainername = "camel-quarkus-" + UUID.randomUUID().toString();
    final String azureStorageAccountName = config.getValue("azure.storage.account-name", String.class);
    final boolean startMockBackend = MockBackendUtils.startMockBackend(false);
    final Map<String, String> result = new LinkedHashMap<>();
    if (startMockBackend && !realCredentialsProvided) {
        MockBackendUtils.logMockBackendUsed();
        try {
            container = new GenericContainer<>(AZURITE_IMAGE).withExposedPorts(Service.getAzuritePorts()).withLogConsumer(new Slf4jLogConsumer(LOGGER)).waitingFor(Wait.forListeningPort());
            container.start();
            result.put("azure.blob.container.name", azureBlobContainername);
            Stream.of(Service.values()).forEach(s -> {
                result.put("azure." + s.name() + ".service.url", "http://" + container.getContainerIpAddress() + ":" + (s.azuritePort >= 0 ? container.getMappedPort(s.azuritePort) : s.azuritePort) + "/" + azureStorageAccountName);
            });
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        if (!startMockBackend && !realCredentialsProvided) {
            throw new IllegalStateException("Set AZURE_STORAGE_ACCOUNT_NAME and AZURE_STORAGE_ACCOUNT_KEY env vars if you set CAMEL_QUARKUS_START_MOCK_BACKEND=false");
        }
        MockBackendUtils.logRealBackendUsed();
        result.put("azure.blob.container.name", azureBlobContainername);
        Stream.of(Service.values()).forEach(s -> {
            result.put("azure." + s.name() + ".service.url", "https://" + realAzureStorageAccountName + "." + s.getAzureServiceCode() + ".core.windows.net");
        });
    }
    return result;
}
Also used : SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer) GenericContainer(org.testcontainers.containers.GenericContainer) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with SmallRyeConfig

use of io.smallrye.config.SmallRyeConfig in project quarkus-logging-logback by quarkiverse.

the class LogbackRecorder method init.

public void init(List<SaxEvent> originalEvents, Set<String> delayedStartClasses, ShutdownContext context, Map<String, String> buildSystemProps) {
    EventSubstitution substitution = new EventSubstitution();
    if (defaultLoggerContext == null) {
        SmallRyeConfig config = (SmallRyeConfig) SmallRyeConfigProviderResolver.instance().getConfig();
        List<SaxEvent> configEvents = new ArrayList<>();
        for (SaxEvent i : originalEvents) {
            if (i instanceof StartEvent) {
                AttributesImpl impl = (AttributesImpl) ((StartEvent) i).attributes;
                int index = impl.getIndex("class");
                if (index > -1) {
                    String val = impl.getValue(index);
                    if (delayedStartClasses.contains(val)) {
                        impl.setValue(index, val + DELAYED);
                    }
                }
                for (int j = 1; j <= impl.getLength(); ++j) {
                    String val = impl.getValue(index);
                    if (val != null && val.contains("${")) {
                        final String expanded = doExpand(config, val, buildSystemProps);
                        impl.setValue(j, expanded);
                    }
                }
                configEvents.add(i);
            } else if (i instanceof BodyEvent) {
                String val = ((BodyEvent) i).getText();
                if (val.contains("${")) {
                    final String expanded = doExpand(config, val, buildSystemProps);
                    configEvents.add(substitution.deserialize(new BodySub(i.getNamespaceURI(), i.getLocalName(), i.getQName(), i.getLocator(), expanded)));
                } else {
                    configEvents.add(i);
                }
            } else {
                configEvents.add(i);
            }
        }
        defaultLoggerContext = new LoggerContext();
        try {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(defaultLoggerContext);
            configurator.doConfigure(configEvents);
            // logback-292
            if (!StatusUtil.contextHasStatusListener(defaultLoggerContext)) {
                StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
            }
        } catch (Exception t) {
            // see LOGBACK-1159
            Util.report("Failed to instantiate [" + LoggerContext.class.getName() + "]", t);
        }
        context.addLastShutdownTask(new Runnable() {

            @Override
            public void run() {
                defaultLoggerContext.stop();
                defaultLoggerContext = null;
                started = false;
            }
        });
    }
}
Also used : BodySub(io.quarkiverse.logback.runtime.events.BodySub) ArrayList(java.util.ArrayList) BodyEvent(ch.qos.logback.core.joran.event.BodyEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) AttributesImpl(org.xml.sax.helpers.AttributesImpl) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) SaxEvent(ch.qos.logback.core.joran.event.SaxEvent) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) StartEvent(ch.qos.logback.core.joran.event.StartEvent) EventSubstitution(io.quarkiverse.logback.runtime.events.EventSubstitution)

Aggregations

SmallRyeConfig (io.smallrye.config.SmallRyeConfig)19 Test (org.junit.Test)12 SmallRyeConfigBuilder (io.smallrye.config.SmallRyeConfigBuilder)4 MariaDBDialect (org.hibernate.dialect.MariaDBDialect)3 QuarkusH2Dialect (io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect)2 ConfigSource (org.eclipse.microprofile.config.spi.ConfigSource)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 BodyEvent (ch.qos.logback.core.joran.event.BodyEvent)1 SaxEvent (ch.qos.logback.core.joran.event.SaxEvent)1 StartEvent (ch.qos.logback.core.joran.event.StartEvent)1 Configuration (com.buschmais.jqassistant.core.configuration.api.Configuration)1 BodySub (io.quarkiverse.logback.runtime.events.BodySub)1 EventSubstitution (io.quarkiverse.logback.runtime.events.EventSubstitution)1 QuarkusPostgreSQL10Dialect (io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect)1 PropertiesConfigSource (io.smallrye.config.PropertiesConfigSource)1 YamlConfigSource (io.smallrye.config.source.yaml.YamlConfigSource)1 OpenApiConfigImpl (io.smallrye.openapi.api.OpenApiConfigImpl)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1