-
-
Notifications
You must be signed in to change notification settings - Fork 16
Add updatable config source #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7649111
first working impl (without CDI)
infeo 3610ce8
simplify config writer
infeo ab96fb0
use user home dir as default hub config location
infeo e07110e
add static method to get instance of HubConfig for persistence
infeo 3ed78e7
fix minor bugs
infeo a5d3839
make hub config persistence synchronously
infeo 06fdb2e
prevent that hub config file overwrites quarkus properites file
infeo 9ce57d3
clean up
infeo 6a1af09
rename persistence for hub config
infeo c545195
change visibility of HubConfigPersistence constructor
infeo 8718e35
do the wiring inside the configSourceFactory
infeo 585a71c
rename HubConfigPersistence::read to load
infeo 6519757
small fixes
infeo 5d10b1f
remove default hub config path and choke when not set
infeo ed61794
throw uncheckedIo exception when unable to persist config
infeo 64d0d5f
simplify
infeo e7b8b0d
* correctly use jboss logging
infeo ae82ae0
rework hub config:
infeo 31d8c17
small changes:
infeo 9f6b58e
use default implementation for `getProperties()`
overheadhunter 95cab8d
increase ordinal, giving HubConfig higher priority than Quarkus' appl…
overheadhunter 7a04616
formatted
overheadhunter 0f5b3f2
Qualifier no longer required when injecting HubConfig
overheadhunter 816ddcf
document `-Dhub.config.path`
overheadhunter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| hub.properties | ||
|
|
||
| #Maven | ||
| target/ | ||
| pom.xml.tag | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
spi/src/main/java/org/cryptomator/hub/config/HubConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package org.cryptomator.hub.config; | ||
|
|
||
| import org.eclipse.microprofile.config.spi.ConfigSource; | ||
| import org.jboss.logging.Logger; | ||
|
|
||
| import javax.enterprise.inject.Vetoed; | ||
| import java.nio.file.Path; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
|
|
||
| @Vetoed | ||
| 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); | ||
| if (configPath == null) { | ||
| throw new IllegalStateException("Property " + HUB_CONFIGPATH_PROPERTY_KEY + " not set."); | ||
| } | ||
|
|
||
| LOG.info("Hub config persists to " + configPath); | ||
| this.config = new Properties(); | ||
| this.persistence = new HubConfigPersistence(Path.of(configPath)); | ||
|
|
||
| persistence.load(config); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> getPropertyNames() { | ||
| return config.stringPropertyNames(); | ||
| } | ||
|
|
||
| @Override | ||
| // for default sources and their precedence see https://quarkus.io/guides/config-reference#configuration-sources | ||
| public int getOrdinal() { | ||
| return 270; | ||
| } | ||
|
|
||
| @Override | ||
| public String getValue(String key) { | ||
| return config.getProperty(key); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return HUB_CONFIGSOURCE_NAME; | ||
| } | ||
|
|
||
| public synchronized void setProperty(Key key, String value) { | ||
| String oldVal = (String) config.setProperty(key.toString(), value); | ||
| if (oldVal == null || !oldVal.equals(value)) { | ||
| persistence.persist(config); | ||
| } | ||
| } | ||
|
|
||
| public enum Key { | ||
|
|
||
| //TODO: replace by real property key | ||
| DUMMY_VALUE("dummy.value"); | ||
|
|
||
| private final String actualKeyString; | ||
|
|
||
| Key(String actualKeyString) { | ||
| this.actualKeyString = actualKeyString; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return actualKeyString; | ||
| } | ||
| } | ||
|
|
||
| } |
43 changes: 43 additions & 0 deletions
43
spi/src/main/java/org/cryptomator/hub/config/HubConfigPersistence.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.cryptomator.hub.config; | ||
|
|
||
| import org.jboss.logging.Logger; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.NoSuchFileException; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardOpenOption; | ||
| import java.util.Properties; | ||
|
|
||
| class HubConfigPersistence { | ||
|
|
||
| private static final Logger LOG = Logger.getLogger(HubConfigPersistence.class); | ||
| private static final String HUB_CONFIG_DESCRIPTION = "Cryptomator Hub configuration persistence file"; | ||
|
|
||
| private final Path configPath; | ||
|
|
||
| HubConfigPersistence(Path configPath) { | ||
| this.configPath = configPath; | ||
| } | ||
|
|
||
| synchronized void persist(Properties properties) { | ||
| try (var out = Files.newOutputStream(configPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { | ||
| properties.store(out, HUB_CONFIG_DESCRIPTION); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("Unable to persist Hub config to " + configPath, e); | ||
| } | ||
| } | ||
|
|
||
| synchronized void load(Properties prop) { | ||
| try (var in = Files.newInputStream(configPath, StandardOpenOption.READ)) { | ||
| prop.load(in); | ||
| } catch (NoSuchFileException e) { | ||
| LOG.debugf("No hub config file found at %s.", configPath); | ||
| } catch (IOException e) { | ||
| LOG.warn(String.format("Unable to read hub config from %s, creating empty.", configPath), e); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
20 changes: 20 additions & 0 deletions
20
spi/src/main/java/org/cryptomator/hub/config/HubConfigProducer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.cryptomator.hub.config; | ||
|
|
||
| import org.eclipse.microprofile.config.ConfigProvider; | ||
|
|
||
| import javax.enterprise.context.ApplicationScoped; | ||
| import javax.enterprise.inject.Produces; | ||
| import java.util.stream.StreamSupport; | ||
|
|
||
| public class HubConfigProducer { | ||
|
|
||
| @Produces | ||
| @ApplicationScoped | ||
| public static HubConfig getInstance() { | ||
| return (HubConfig) StreamSupport.stream(ConfigProvider.getConfig().getConfigSources().spliterator(), false) | ||
| .filter(s -> s instanceof HubConfig) | ||
| .findFirst() | ||
| .get(); | ||
| } | ||
|
|
||
| } |
1 change: 1 addition & 0 deletions
1
spi/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| org.cryptomator.hub.config.HubConfig |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.