Skip to content
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

SmallRye Config SecretKeys support #26509

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import io.smallrye.config.ConfigValue;
import io.smallrye.config.Converters;
import io.smallrye.config.EnvConfigSource;
import io.smallrye.config.SecretKeys;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SysPropConfigSource;
Expand Down Expand Up @@ -319,7 +320,7 @@ public List<ConfigClassWithPrefix> getBuildTimeVisibleMappings() {
}

public ReadResult readConfiguration(final SmallRyeConfig config) {
return new ReadOperation(config).run();
return SecretKeys.doUnlocked(() -> new ReadOperation(config).run());
}

final class ReadOperation {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.config;

import java.util.Set;

import io.smallrye.config.ConfigSourceInterceptor;
import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.ConfigSourceInterceptorFactory;
import io.smallrye.config.SecretKeysConfigSourceInterceptor;

public class SecretKeysConfigInterceptorFactory implements ConfigSourceInterceptorFactory {
@Override
public ConfigSourceInterceptor getInterceptor(final ConfigSourceInterceptorContext configSourceInterceptorContext) {
return new SecretKeysConfigSourceInterceptor(Set.of("secrets.my.secret"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkus.config;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import javax.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.SmallRyeConfig;

public class SecretKeysConfigTest {
@RegisterExtension
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClass(SecretKeysConfigInterceptorFactory.class)
.addAsServiceProvider("io.smallrye.config.ConfigSourceInterceptorFactory",
SecretKeysConfigInterceptorFactory.class.getName()))
.overrideConfigKey("secrets.my.secret", "secret");

@Inject
SmallRyeConfig config;
@Inject
@ConfigProperty(name = "secrets.my.secret")
String secret;
@Inject
MappingSecret mappingSecret;

@Test
void secrets() {
assertThrows(SecurityException.class, () -> config.getConfigValue("secrets.my.secret"));

assertEquals("secret", secret);
assertEquals("secret", mappingSecret.secret());
}

@ConfigMapping(prefix = "secrets.my")
interface MappingSecret {
String secret();
}
}