Skip to content

Commit

Permalink
Merge pull request #108 from sberyozkin/runtime_config_mapping
Browse files Browse the repository at this point in the history
Use ConfigMapping in the run time config
  • Loading branch information
sberyozkin authored Sep 19, 2024
2 parents 51b92bd + 658d2f6 commit 7b76c13
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

import java.util.Map;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.credentials.CredentialsProvider;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigRoot(name = "file.vault", phase = ConfigPhase.RUN_TIME)
public class FileVaultConfig {
@ConfigMapping(prefix = "quarkus.file.vault")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface FileVaultConfig {

/**
* Java KeyStore configuration for a specific provider such as a database.
*/
@ConfigItem
public Map<String, Map<String, String>> provider;
Map<String, Map<String, String>> provider();

/**
* Set the alias which is used to extract a secret from the key store as a 'user' property.
Expand All @@ -25,6 +27,6 @@ public class FileVaultConfig {
* Disable this property if you'd like to use a property such as 'quarkus.datasource.username' to configure a username,
* when the username and keystore alias values are different.
*/
@ConfigItem(defaultValue = "true")
public boolean setAliasAsUser;
@WithDefault("true")
boolean setAliasAsUser();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FileVaultCredentialsProvider implements CredentialsProvider {
private boolean setAliasAsUser;

public FileVaultCredentialsProvider(FileVaultConfig config) {
for (Map.Entry<String, Map<String, String>> store : config.provider.entrySet()) {
for (Map.Entry<String, Map<String, String>> store : config.provider().entrySet()) {
Map<String, String> keyStoreProps = store.getValue();
String keyStoreFile = keyStoreProps.getOrDefault("path", DEFAULT_KEY_STORE_FILE);
String keyStoreSecret = keyStoreProps.get("secret");
Expand All @@ -38,7 +38,7 @@ public FileVaultCredentialsProvider(FileVaultConfig config) {
defaultAliases.put(store.getKey(), store.getValue().get("alias"));
}
}
this.setAliasAsUser = config.setAliasAsUser;
this.setAliasAsUser = config.setAliasAsUser();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,19 @@ private CredentialsProvider createCredentialsProvider(boolean includeAlias, bool

private CredentialsProvider createCredentialsProvider(boolean includeAlias, boolean setAliasAsUser, boolean isSecretMasked,
String secret) {
FileVaultConfig config = new FileVaultConfig();
config.provider = Map.of(PROVIDER_NAME, createKeystoreProps(includeAlias, isSecretMasked, secret));
config.setAliasAsUser = setAliasAsUser;
FileVaultConfig config = new FileVaultConfig() {

@Override
public Map<String, Map<String, String>> provider() {
return Map.of(PROVIDER_NAME, createKeystoreProps(includeAlias, isSecretMasked, secret));
}

@Override
public boolean setAliasAsUser() {
return setAliasAsUser;
}

};
return new FileVaultCredentialsProvider(config);
}

Expand Down

0 comments on commit 7b76c13

Please sign in to comment.