Skip to content
Merged
Show file tree
Hide file tree
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 Oct 22, 2021
3610ce8
simplify config writer
infeo Oct 22, 2021
ab96fb0
use user home dir as default hub config location
infeo Oct 22, 2021
e07110e
add static method to get instance of HubConfig for persistence
infeo Oct 22, 2021
3ed78e7
fix minor bugs
infeo Oct 25, 2021
a5d3839
make hub config persistence synchronously
infeo Oct 25, 2021
06fdb2e
prevent that hub config file overwrites quarkus properites file
infeo Oct 25, 2021
9ce57d3
clean up
infeo Oct 25, 2021
6a1af09
rename persistence for hub config
infeo Oct 25, 2021
c545195
change visibility of HubConfigPersistence constructor
infeo Oct 25, 2021
8718e35
do the wiring inside the configSourceFactory
infeo Oct 25, 2021
585a71c
rename HubConfigPersistence::read to load
infeo Oct 25, 2021
6519757
small fixes
infeo Oct 25, 2021
5d10b1f
remove default hub config path and choke when not set
infeo Oct 26, 2021
ed61794
throw uncheckedIo exception when unable to persist config
infeo Oct 26, 2021
64d0d5f
simplify
infeo Oct 26, 2021
e7b8b0d
* correctly use jboss logging
infeo Oct 26, 2021
ae82ae0
rework hub config:
infeo Oct 28, 2021
31d8c17
small changes:
infeo Oct 28, 2021
9f6b58e
use default implementation for `getProperties()`
overheadhunter Oct 28, 2021
95cab8d
increase ordinal, giving HubConfig higher priority than Quarkus' appl…
overheadhunter Oct 28, 2021
7a04616
formatted
overheadhunter Oct 28, 2021
0f5b3f2
Qualifier no longer required when injecting HubConfig
overheadhunter Oct 29, 2021
816ddcf
document `-Dhub.config.path`
overheadhunter Oct 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spi/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
hub.properties

#Maven
target/
pom.xml.tag
Expand Down
2 changes: 1 addition & 1 deletion spi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ If you want to learn more about Quarkus, please visit its website: https://quark

You can run your application in dev mode that enables live coding using:
```shell script
mvn compile quarkus:dev
mvn compile quarkus:dev -Dhub.config.path=hub.properties
```

> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
Expand Down
79 changes: 79 additions & 0 deletions spi/src/main/java/org/cryptomator/hub/config/HubConfig.java
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;
}
}

}
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);
}
}


}
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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.cryptomator.hub.config.HubConfig