Skip to content

Commit

Permalink
Consistent configuration names
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Mar 20, 2023
1 parent 97a3111 commit 1332096
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 18 deletions.
14 changes: 7 additions & 7 deletions documentation/src/main/docs/config-sources/keystore.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ The following dependency is required in the classpath to use the KeyStore Config

| Configuration Property | Type | Default |
|---------------------------------------------------------------------------------------------------------------------|--- |----|
| `io.smallrye.config.source.keystore."name".path`<br>The KeyStore path. | String | |
| `io.smallrye.config.source.keystore."name".password`<br>The KeyStore password. | String | |
| `io.smallrye.config.source.keystore."name".type`<br>The KeyStore type. | String | `PKCS12` |
| `io.smallrye.config.source.keystore."name".handler`<br>An Optional secret keys handler. | String | |
| `io.smallrye.config.source.keystore."name".aliases."key".name`<br>An Optional aliases key name. | String | |
| `io.smallrye.config.source.keystore."name".aliases."key".password`<br>An Optional aliases key password. | String | |
| `io.smallrye.config.source.keystore."name".aliases."key".handler`<br>An Optional aliases key secret keys handler. | String | |
| `smallrye.config.source.keystore."name".path`<br>The KeyStore path. | String | |
| `smallrye.config.source.keystore."name".password`<br>The KeyStore password. | String | |
| `smallrye.config.source.keystore."name".type`<br>The KeyStore type. | String | `PKCS12` |
| `smallrye.config.source.keystore."name".handler`<br>An Optional secret keys handler. | String | |
| `smallrye.config.source.keystore."name".aliases."key".name`<br>An Optional aliases key name. | String | |
| `smallrye.config.source.keystore."name".aliases."key".password`<br>An Optional aliases key password. | String | |
| `smallrye.config.source.keystore."name".aliases."key".handler`<br>An Optional aliases key secret keys handler. | String | |
18 changes: 18 additions & 0 deletions sources/keystore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,22 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.smallrye</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>${version.org.jboss.jandex}</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithParentName;

@ConfigMapping(prefix = "io.smallrye.config.source.keystore")
@ConfigMapping(prefix = "smallrye.config.source.keystore")
public interface KeyStoreConfig {
@WithParentName
Map<String, KeyStore> keystores();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class KeyStoreConfigSourceTest {
void keystore() {
// keytool -importpass -alias my.secret -keystore keystore -storepass secret -storetype PKCS12 -v
Map<String, String> properties = Map.of(
"io.smallrye.config.source.keystore.test.path", "keystore",
"io.smallrye.config.source.keystore.test.password", "secret");
"smallrye.config.source.keystore.test.path", "keystore",
"smallrye.config.source.keystore.test.password", "secret");

SmallRyeConfig config = new SmallRyeConfigBuilder()
.withProfile("prod")
Expand All @@ -39,8 +39,8 @@ void keyStoreNotFound() {
.addDefaultInterceptors()
.addDiscoveredSources()
.withSources(new PropertiesConfigSource(Map.of(
"io.smallrye.config.source.keystore.test.path", "not.found",
"io.smallrye.config.source.keystore.test.password", "secret"), "", 0))
"smallrye.config.source.keystore.test.path", "not.found",
"smallrye.config.source.keystore.test.password", "secret"), "", 0))
.build();

ConfigValue secret = config.getConfigValue("my.secret");
Expand All @@ -49,8 +49,8 @@ void keyStoreNotFound() {
assertThrows(IllegalArgumentException.class, () -> new SmallRyeConfigBuilder()
.addDiscoveredSources()
.withSources(new PropertiesConfigSource(Map.of(
"io.smallrye.config.source.keystore.test.path", "file:/not.found",
"io.smallrye.config.source.keystore.test.password", "secret"), "", 0))
"smallrye.config.source.keystore.test.path", "file:/not.found",
"smallrye.config.source.keystore.test.password", "secret"), "", 0))
.build());
}
}
10 changes: 10 additions & 0 deletions testsuite/extra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
<artifactId>smallrye-config-source-yaml</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-crypto</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-jasypt</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.smallrye.config.test.secrets;

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

import java.util.Map;

import org.junit.jupiter.api.Test;

import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;

class MultipleSecretHandlersTest {
@Test
void multipleHandlers() {
Map<String, String> properties = Map.of(
"smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key", "somearbitrarycrazystringthatdoesnotmatter",
"aes-gcm-nopadding.secret", "${aes-gcm-nopadding::DJNrZ6LfpupFv6QbXyXhvzD8eVDnDa_kTliQBpuzTobDZxlg}",
"smallrye.config.secret-handler.jasypt.password", "jasypt",
"smallrye.config.secret-handler.jasypt.algorithm", "PBEWithHMACSHA512AndAES_256",
"jasypt.secret", "${jasypt::ENC(wqp8zDeiCQ5JaFvwDtoAcr2WMLdlD0rjwvo8Rh0thG5qyTQVGxwJjBIiW26y0dtU)}");

SmallRyeConfig config = new SmallRyeConfigBuilder()
.addDefaultInterceptors()
.addDiscoveredSecretKeysHandlers()
.withSources(new PropertiesConfigSource(properties, "", 0))
.build();

assertEquals("decoded", config.getRawValue("aes-gcm-nopadding.secret"));
assertEquals("12345678", config.getRawValue("jasypt.secret"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import org.eclipse.microprofile.config.spi.ConfigSource;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import io.smallrye.config.ConfigSourceContext;
import io.smallrye.config.ConfigSourceFactory;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.SmallRyeConfig;
Expand Down Expand Up @@ -38,9 +43,9 @@ void handler() {
void keystore() {
Map<String, String> properties = Map.of(
"smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key", "somearbitrarycrazystringthatdoesnotmatter",
"io.smallrye.config.source.keystore.test.path", "keystore",
"io.smallrye.config.source.keystore.test.password", "secret",
"io.smallrye.config.source.keystore.test.handler", "aes-gcm-nopadding");
"smallrye.config.source.keystore.test.path", "keystore",
"smallrye.config.source.keystore.test.password", "secret",
"smallrye.config.source.keystore.test.handler", "aes-gcm-nopadding");

SmallRyeConfig config = new SmallRyeConfigBuilder()
.addDefaultInterceptors()
Expand Down Expand Up @@ -68,4 +73,32 @@ void noEncriptionKey() {
.build();
assertTrue(true);
}

@Test
@Disabled
void configurableSource() {
Map<String, String> properties = Map.of(
"smallrye.config.source.keystore.test.path", "keystore",
"smallrye.config.source.keystore.test.password", "secret",
"smallrye.config.source.keystore.test.handler", "aes-gcm-nopadding");

SmallRyeConfig config = new SmallRyeConfigBuilder()
.addDefaultInterceptors()
.addDiscoveredSources()
.addDiscoveredSecretKeysHandlers()
.withSources(new PropertiesConfigSource(properties, "", 0))
.withSources(new ConfigSourceFactory() {
@Override
public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context) {
return List.of(new PropertiesConfigSource(
Map.of("smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key",
"somearbitrarycrazystringthatdoesnotmatter"),
"", 0));
}
})
.build();

ConfigValue secret = config.getConfigValue("my.secret");
assertEquals("decoded", secret.getValue());
}
}
6 changes: 5 additions & 1 deletion utils/jasypt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

<name>SmallRye Config: Jasypt</name>

<properties>
<version.jasypt>1.9.3</version.jasypt>
</properties>

<dependencies>
<dependency>
<groupId>io.smallrye.config</groupId>
Expand All @@ -20,7 +24,7 @@
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.3</version>
<version>${version.jasypt}</version>
</dependency>

<!-- Test -->
Expand Down

0 comments on commit 1332096

Please sign in to comment.