From 091b93e7c7c016a666151db66bf61947ed3aaf14 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Thu, 25 Nov 2021 17:02:41 +0100 Subject: [PATCH] re-add ConfigSourceFactory from 64d0d5f to be replaced, once there is an official way to access higher-order config (see eclipse/microprofile-config#470) --- .../org/cryptomator/hub/config/HubConfig.java | 6 ++---- .../hub/config/HubConfigSourceFactory.java | 19 +++++++++++++++++++ .../io.smallrye.config.ConfigSourceFactory | 1 + ...lipse.microprofile.config.spi.ConfigSource | 1 - .../src/main/resources/application.properties | 3 +++ 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 backend/src/main/java/org/cryptomator/hub/config/HubConfigSourceFactory.java create mode 100644 backend/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory delete mode 100644 backend/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource diff --git a/backend/src/main/java/org/cryptomator/hub/config/HubConfig.java b/backend/src/main/java/org/cryptomator/hub/config/HubConfig.java index 971859e3..f3e53899 100644 --- a/backend/src/main/java/org/cryptomator/hub/config/HubConfig.java +++ b/backend/src/main/java/org/cryptomator/hub/config/HubConfig.java @@ -16,15 +16,13 @@ public class HubConfig implements ConfigSource { private static final Logger LOG = Logger.getLogger(HubConfig.class); private static final String HUB_CONFIGSOURCE_NAME = "HubConfig"; - private static final String HUB_CONFIGPATH_PROPERTY_KEY = "hub.config.path"; private final HubConfigPersistence persistence; private final Properties config; - public HubConfig() { - var configPath = System.getProperty(HUB_CONFIGPATH_PROPERTY_KEY); + public HubConfig(String configPath) { if (configPath == null) { - throw new IllegalStateException("Property " + HUB_CONFIGPATH_PROPERTY_KEY + " not set."); + throw new IllegalStateException("Hub config path not set."); } LOG.info("Hub config persists to " + configPath); diff --git a/backend/src/main/java/org/cryptomator/hub/config/HubConfigSourceFactory.java b/backend/src/main/java/org/cryptomator/hub/config/HubConfigSourceFactory.java new file mode 100644 index 00000000..917e1058 --- /dev/null +++ b/backend/src/main/java/org/cryptomator/hub/config/HubConfigSourceFactory.java @@ -0,0 +1,19 @@ +package org.cryptomator.hub.config; + +import io.smallrye.config.ConfigSourceContext; +import io.smallrye.config.ConfigSourceFactory; +import org.eclipse.microprofile.config.spi.ConfigSource; + +import java.util.List; + +public class HubConfigSourceFactory implements ConfigSourceFactory { + + private static final String HUBCONFIG_PROPERTY_KEY = "hub.config.path"; + + @Override + public Iterable getConfigSources(ConfigSourceContext configSourceContext) { + var configPath = configSourceContext.getValue(HUBCONFIG_PROPERTY_KEY); + var hubConfig = new HubConfig(configPath.getValue()); + return List.of(hubConfig); + } +} diff --git a/backend/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory b/backend/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory new file mode 100644 index 00000000..5c77e234 --- /dev/null +++ b/backend/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory @@ -0,0 +1 @@ +org.cryptomator.hub.config.HubConfigSourceFactory \ No newline at end of file diff --git a/backend/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource b/backend/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource deleted file mode 100644 index fd571d73..00000000 --- a/backend/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource +++ /dev/null @@ -1 +0,0 @@ -org.cryptomator.hub.config.HubConfig \ No newline at end of file diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 41d24ac7..7b8e56cf 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -8,6 +8,9 @@ quarkus.http.port=9090 quarkus.oidc.application-type=service quarkus.oidc.client-id=cryptomator-hub +hub.config.path=hub.properties +%test.hub.config.path=target/hub-test.properties + # Keycloak dev service %dev.quarkus.keycloak.devservices.enabled=true %dev.quarkus.keycloak.devservices.create-realm=false