Skip to content

Commit

Permalink
Make JdbcConfig runtime to not fail during the build when configurati…
Browse files Browse the repository at this point in the history
…on is missing (#173)
  • Loading branch information
radcortez authored Sep 21, 2023
1 parent 416c805 commit 096c6b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* The config itself is loaded using the ConfigSourceContext on the ConfigSourceFactory
*/
@ConfigMapping(prefix = "quarkus.config.source.jdbc")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface JdbcConfigConfig {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
package io.quarkiverse.config.jdbc.runtime;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.eclipse.microprofile.config.spi.ConfigSource;
import org.jboss.logging.Logger;

import io.smallrye.config.ConfigSourceContext;
import io.smallrye.config.ConfigSourceFactory;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.common.MapBackedConfigSource;

public class JdbcConfigSourceFactory implements ConfigSourceFactory.ConfigurableConfigSourceFactory<JdbcConfigConfig> {
public class JdbcConfigSourceFactory implements ConfigSourceFactory {
private static final Logger log = Logger.getLogger(JdbcConfigSourceFactory.class);

// TODO - Cannot use ConfigurableConfigSourceFactory, because profiles are not being propagated. Need a fix in SR Config
@Override
public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context, final JdbcConfigConfig config) {
public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context) {
List<String> profiles = new ArrayList<>(context.getProfiles());
Collections.reverse(profiles);

JdbcConfigConfig config = new SmallRyeConfigBuilder()
.withSources(new ConfigSourceContext.ConfigSourceContextConfigSource(context))
.withProfiles(profiles)
.withMapping(JdbcConfigConfig.class)
.build().getConfigMapping(JdbcConfigConfig.class);

if (!config.enabled()) {
return Collections.emptyList();
}
Expand Down

0 comments on commit 096c6b5

Please sign in to comment.