Skip to content

Commit 35173a9

Browse files
authored
Merge pull request #768 from gsmet/avoid-loading-private-key-srcfg
Avoid loading the private key with SmallRye Config
2 parents 7bf128a + 564389e commit 35173a9

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

docs/modules/ROOT/pages/includes/quarkus-github-app.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ifndef::add-copy-button-to-env-var[]
9494
Environment variable: `+++QUARKUS_GITHUB_APP_PRIVATE_KEY+++`
9595
endif::add-copy-button-to-env-var[]
9696
--
97-
|link:https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/security/PrivateKey.html[PrivateKey]
97+
|string
9898
|
9999

100100
a| [[quarkus-github-app_quarkus-github-app-webhook-url-path]] [.property-path]##link:#quarkus-github-app_quarkus-github-app-webhook-url-path[`quarkus.github-app.webhook-url-path`]##

docs/modules/ROOT/pages/includes/quarkus-github-app_quarkus.github-app.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ifndef::add-copy-button-to-env-var[]
9494
Environment variable: `+++QUARKUS_GITHUB_APP_PRIVATE_KEY+++`
9595
endif::add-copy-button-to-env-var[]
9696
--
97-
|link:https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/security/PrivateKey.html[PrivateKey]
97+
|string
9898
|
9999

100100
a| [[quarkus-github-app_quarkus-github-app-webhook-url-path]] [.property-path]##link:#quarkus-github-app_quarkus-github-app-webhook-url-path[`quarkus.github-app.webhook-url-path`]##

runtime/src/main/java/io/quarkiverse/githubapp/runtime/config/CheckedConfigProvider.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ public class CheckedConfigProvider {
4343
this.launchMode = launchMode;
4444

4545
Map<String, String> credentials = getCredentials();
46-
String privateKeyFromCredentials = credentials.get(Credentials.PRIVATE_KEY);
47-
if (privateKeyFromCredentials != null && !privateKeyFromCredentials.isBlank()) {
48-
this.privateKey = Optional.of(new PrivateKeyConverter().convert(privateKeyFromCredentials.trim()));
49-
} else {
50-
this.privateKey = gitHubAppRuntimeConfig.privateKey();
46+
47+
String privateKey = credentials.get(Credentials.PRIVATE_KEY);
48+
if (privateKey == null || privateKey.isBlank()) {
49+
privateKey = gitHubAppRuntimeConfig.privateKey().orElse(null);
5150
}
51+
this.privateKey = privateKey != null ? Optional.of(new PrivateKeyConverter().convert(privateKey.trim()))
52+
: Optional.empty();
53+
5254
String webhookSecretFromCredentials = credentials.get(Credentials.WEBHOOK_SECRET);
5355
if (webhookSecretFromCredentials != null && !webhookSecretFromCredentials.isBlank()) {
5456
this.webhookSecret = Optional.of(webhookSecretFromCredentials.trim());

runtime/src/main/java/io/quarkiverse/githubapp/runtime/config/GitHubAppRuntimeConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.quarkiverse.githubapp.runtime.config;
22

33
import java.nio.file.Path;
4-
import java.security.PrivateKey;
54
import java.util.Optional;
65

76
import io.quarkiverse.githubapp.Credentials;
@@ -45,8 +44,7 @@ public interface GitHubAppRuntimeConfig {
4544
* <p>
4645
* Optional for tests, but mandatory in production and dev mode.
4746
*/
48-
@WithConverter(PrivateKeyConverter.class)
49-
Optional<PrivateKey> privateKey();
47+
Optional<String> privateKey();
5048

5149
/**
5250
* The webhook URL path on which the GitHub App route is mounted.

runtime/src/main/java/io/quarkiverse/githubapp/runtime/config/PrivateKeyConverter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static io.quarkus.runtime.configuration.ConverterSupport.DEFAULT_QUARKUS_CONVERTER_PRIORITY;
44

55
import java.io.Serializable;
6-
import java.security.GeneralSecurityException;
76
import java.security.PrivateKey;
87

98
import jakarta.annotation.Priority;
@@ -29,7 +28,7 @@ public PrivateKey convert(final String value) {
2928

3029
try {
3130
return PrivateKeyUtil.loadKey(privateKeyValue);
32-
} catch (GeneralSecurityException e) {
31+
} catch (Exception e) {
3332
throw new ConfigurationException("Unable to interpret the provided private key", e);
3433
}
3534
}

0 commit comments

Comments
 (0)