Skip to content

Commit cadf512

Browse files
committed
Swith to @ConfigMapping for the documentation
1 parent bc6d465 commit cadf512

File tree

4 files changed

+65
-68
lines changed

4 files changed

+65
-68
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ endif::add-copy-button-to-env-var[]
100100
ifndef::add-copy-button-to-env-var[]
101101
Environment variable: `+++QUARKUS_GITHUB_APP_WEBHOOK_URL_PATH+++`
102102
endif::add-copy-button-to-env-var[]
103-
--|string
103+
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]
104+
104105
|`/`
105106

106107

@@ -195,7 +196,8 @@ endif::add-copy-button-to-env-var[]
195196
ifndef::add-copy-button-to-env-var[]
196197
Environment variable: `+++QUARKUS_GITHUB_APP_INSTANCE_ENDPOINT+++`
197198
endif::add-copy-button-to-env-var[]
198-
--|string
199+
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]
200+
199201
|`https://api.github.com`
200202

201203

@@ -214,7 +216,8 @@ endif::add-copy-button-to-env-var[]
214216
ifndef::add-copy-button-to-env-var[]
215217
Environment variable: `+++QUARKUS_GITHUB_APP_REST_API_ENDPOINT+++`
216218
endif::add-copy-button-to-env-var[]
217-
--|string
219+
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]
220+
218221
|`${quarkus.github-app.instance-endpoint}`
219222

220223

@@ -233,7 +236,8 @@ endif::add-copy-button-to-env-var[]
233236
ifndef::add-copy-button-to-env-var[]
234237
Environment variable: `+++QUARKUS_GITHUB_APP_GRAPHQL_API_ENDPOINT+++`
235238
endif::add-copy-button-to-env-var[]
236-
--|string
239+
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]
240+
237241
|`${quarkus.github-app.instance-endpoint}/graphql`
238242

239243

runtime/src/main/java/io/quarkiverse/githubapp/runtime/Routes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public class Routes {
6464
Path tmpDirectory;
6565

6666
public void init(@Observes StartupEvent startupEvent) throws IOException {
67-
if (checkedConfigProvider.debug().payloadDirectory.isPresent()) {
68-
Files.createDirectories(checkedConfigProvider.debug().payloadDirectory.get());
67+
if (checkedConfigProvider.debug().payloadDirectory().isPresent()) {
68+
Files.createDirectories(checkedConfigProvider.debug().payloadDirectory().get());
6969
LOG.warn("Payloads saved to: "
70-
+ checkedConfigProvider.debug().payloadDirectory.get().toAbsolutePath().toString());
70+
+ checkedConfigProvider.debug().payloadDirectory().get().toAbsolutePath().toString());
7171
}
7272
}
7373

@@ -128,10 +128,10 @@ private void handleRequest(RoutingContext routingContext,
128128

129129
String action = payloadObject.getString("action");
130130

131-
if (!isBlank(deliveryId) && checkedConfigProvider.debug().payloadDirectory.isPresent()) {
131+
if (!isBlank(deliveryId) && checkedConfigProvider.debug().payloadDirectory().isPresent()) {
132132
String fileName = DATE_TIME_FORMATTER.format(LocalDateTime.now()) + "-" + event + "-"
133133
+ (!isBlank(action) ? action + "-" : "") + deliveryId + ".json";
134-
Path path = checkedConfigProvider.debug().payloadDirectory.get().resolve(fileName);
134+
Path path = checkedConfigProvider.debug().payloadDirectory().get().resolve(fileName);
135135
try {
136136
Files.write(path, bodyBytes);
137137
} catch (Exception e) {

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ public class CheckedConfigProvider {
4747
if (privateKeyFromCredentials != null && !privateKeyFromCredentials.isBlank()) {
4848
this.privateKey = Optional.of(new PrivateKeyConverter().convert(privateKeyFromCredentials.trim()));
4949
} else {
50-
this.privateKey = gitHubAppRuntimeConfig.privateKey;
50+
this.privateKey = gitHubAppRuntimeConfig.privateKey();
5151
}
5252
String webhookSecretFromCredentials = credentials.get(Credentials.WEBHOOK_SECRET);
5353
if (webhookSecretFromCredentials != null && !webhookSecretFromCredentials.isBlank()) {
5454
this.webhookSecret = Optional.of(webhookSecretFromCredentials.trim());
5555
} else {
56-
this.webhookSecret = gitHubAppRuntimeConfig.webhookSecret;
56+
this.webhookSecret = gitHubAppRuntimeConfig.webhookSecret();
5757
}
58-
this.webhookUrlPath = gitHubAppRuntimeConfig.webhookUrlPath.startsWith("/") ? gitHubAppRuntimeConfig.webhookUrlPath
59-
: "/" + gitHubAppRuntimeConfig.webhookUrlPath;
58+
this.webhookUrlPath = gitHubAppRuntimeConfig.webhookUrlPath().startsWith("/") ? gitHubAppRuntimeConfig.webhookUrlPath()
59+
: "/" + gitHubAppRuntimeConfig.webhookUrlPath();
6060

61-
if (gitHubAppRuntimeConfig.appId.isEmpty()) {
61+
if (gitHubAppRuntimeConfig.appId().isEmpty()) {
6262
missingPropertyKeys.add("quarkus.github-app.app-id (.env: QUARKUS_GITHUB_APP_APP_ID)");
6363
}
6464
if (this.privateKey.isEmpty()) {
@@ -83,11 +83,11 @@ public String appId() {
8383
}
8484

8585
// The optional will never be empty; using orElseThrow instead of get to avoid IDE warnings.
86-
return gitHubAppRuntimeConfig.appId.orElseThrow();
86+
return gitHubAppRuntimeConfig.appId().orElseThrow();
8787
}
8888

8989
public Optional<String> appName() {
90-
return gitHubAppRuntimeConfig.appName;
90+
return gitHubAppRuntimeConfig.appName();
9191
}
9292

9393
public PrivateKey privateKey() {
@@ -104,28 +104,28 @@ public Optional<String> webhookSecret() {
104104
}
105105

106106
public Optional<String> webhookProxyUrl() {
107-
return gitHubAppRuntimeConfig.webhookProxyUrl;
107+
return gitHubAppRuntimeConfig.webhookProxyUrl();
108108
}
109109

110110
public String restApiEndpoint() {
111-
return gitHubAppRuntimeConfig.restApiEndpoint;
111+
return gitHubAppRuntimeConfig.restApiEndpoint();
112112
}
113113

114114
public String webhookUrlPath() {
115115
return webhookUrlPath;
116116
}
117117

118118
public String graphqlApiEndpoint() {
119-
return gitHubAppRuntimeConfig.graphqlApiEndpoint;
119+
return gitHubAppRuntimeConfig.graphqlApiEndpoint();
120120
}
121121

122122
public Debug debug() {
123-
return gitHubAppRuntimeConfig.debug;
123+
return gitHubAppRuntimeConfig.debug();
124124
}
125125

126126
public ConfigFile.Source getEffectiveSource(ConfigFile.Source source) {
127127
if (source == ConfigFile.Source.DEFAULT) {
128-
return gitHubAppRuntimeConfig.readConfigFilesFromSourceRepository ? ConfigFile.Source.SOURCE_REPOSITORY
128+
return gitHubAppRuntimeConfig.readConfigFilesFromSourceRepository() ? ConfigFile.Source.SOURCE_REPOSITORY
129129
: ConfigFile.Source.CURRENT_REPOSITORY;
130130
}
131131
return source;
@@ -155,13 +155,13 @@ public void checkConfig() {
155155
}
156156

157157
private Map<String, String> getCredentials() {
158-
if (gitHubAppRuntimeConfig.credentialsProvider.isEmpty()) {
158+
if (gitHubAppRuntimeConfig.credentialsProvider().isEmpty()) {
159159
return Map.of();
160160
}
161161

162-
String beanName = gitHubAppRuntimeConfig.credentialsProviderName.orElse(null);
162+
String beanName = gitHubAppRuntimeConfig.credentialsProviderName().orElse(null);
163163
CredentialsProvider credentialsProvider = getCredentialsProvider(beanName);
164-
String keyRingName = gitHubAppRuntimeConfig.credentialsProvider.get();
164+
String keyRingName = gitHubAppRuntimeConfig.credentialsProvider().get();
165165

166166
return credentialsProvider.getCredentials(keyRingName);
167167
}

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

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,61 @@
66

77
import io.quarkiverse.githubapp.Credentials;
88
import io.quarkus.runtime.annotations.ConfigGroup;
9-
import io.quarkus.runtime.annotations.ConfigItem;
109
import io.quarkus.runtime.annotations.ConfigPhase;
1110
import io.quarkus.runtime.annotations.ConfigRoot;
12-
import io.quarkus.runtime.annotations.ConvertWith;
1311
import io.quarkus.runtime.configuration.TrimmedStringConverter;
12+
import io.smallrye.config.ConfigMapping;
13+
import io.smallrye.config.WithConverter;
14+
import io.smallrye.config.WithDefault;
1415

15-
@ConfigRoot(name = "github-app", phase = ConfigPhase.RUN_TIME)
16-
public class GitHubAppRuntimeConfig {
16+
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
17+
@ConfigMapping(prefix = "quarkus.github-app")
18+
public interface GitHubAppRuntimeConfig {
1719

1820
/**
1921
* The numeric application id provided by GitHub.
2022
* <p>
2123
* Optional for tests, but mandatory in production and dev mode.
2224
*/
23-
@ConfigItem
24-
@ConvertWith(TrimmedStringConverter.class)
25-
Optional<String> appId;
25+
@WithConverter(TrimmedStringConverter.class)
26+
Optional<String> appId();
2627

2728
/**
2829
* The GitHub name of the application.
2930
* <p>
3031
* Optional, only used for improving the user experience.
3132
*/
32-
@ConfigItem
33-
@ConvertWith(TrimmedStringConverter.class)
34-
Optional<String> appName;
33+
@WithConverter(TrimmedStringConverter.class)
34+
Optional<String> appName();
3535

3636
/**
3737
* Read the configuration files from the source repository in case of a fork.
3838
*/
39-
@ConfigItem(defaultValue = "false")
40-
boolean readConfigFilesFromSourceRepository;
39+
@WithDefault("false")
40+
boolean readConfigFilesFromSourceRepository();
4141

4242
/**
4343
* The RSA private key.
4444
* <p>
4545
* Optional for tests, but mandatory in production and dev mode.
4646
*/
47-
@ConfigItem
48-
@ConvertWith(PrivateKeyConverter.class)
49-
Optional<PrivateKey> privateKey;
47+
@WithConverter(PrivateKeyConverter.class)
48+
Optional<PrivateKey> privateKey();
5049

5150
/**
5251
* The webhook URL path on which the GitHub App route is mounted.
5352
* <p>
5453
* It defaults to the root {@code /} but it can be configured to another path such as {@code /github-events} to enable
5554
* deployment alongside other HTTP routes.
5655
*/
57-
@ConfigItem(defaultValue = "/")
58-
@ConvertWith(TrimmedStringConverter.class)
59-
String webhookUrlPath;
56+
@WithDefault("/")
57+
@WithConverter(TrimmedStringConverter.class)
58+
String webhookUrlPath();
6059

6160
/**
6261
* The webhook secret if defined in the GitHub UI.
6362
*/
64-
@ConfigItem
65-
Optional<String> webhookSecret;
63+
Optional<String> webhookSecret();
6664

6765
/**
6866
* The credentials provider name.
@@ -71,9 +69,8 @@ public class GitHubAppRuntimeConfig {
7169
* <p>
7270
* Key names are defined in {@link Credentials}.
7371
*/
74-
@ConfigItem
75-
@ConvertWith(TrimmedStringConverter.class)
76-
Optional<String> credentialsProvider;
72+
@WithConverter(TrimmedStringConverter.class)
73+
Optional<String> credentialsProvider();
7774

7875
/**
7976
* The credentials provider bean name.
@@ -84,58 +81,54 @@ public class GitHubAppRuntimeConfig {
8481
* <p>
8582
* For Vault, the credentials provider bean name is {@code vault-credentials-provider}.
8683
*/
87-
@ConfigItem
88-
@ConvertWith(TrimmedStringConverter.class)
89-
Optional<String> credentialsProviderName;
84+
@WithConverter(TrimmedStringConverter.class)
85+
Optional<String> credentialsProviderName();
9086

9187
/**
9288
* The Smee.io proxy URL used when testing locally.
9389
*/
94-
@ConfigItem
95-
@ConvertWith(TrimmedStringConverter.class)
96-
Optional<String> webhookProxyUrl;
90+
@WithConverter(TrimmedStringConverter.class)
91+
Optional<String> webhookProxyUrl();
9792

9893
/**
9994
* The GitHub instance endpoint.
10095
* <p>
10196
* Defaults to the public github.com instance.
10297
*/
103-
@ConfigItem(defaultValue = "https://api.github.com")
104-
@ConvertWith(TrimmedStringConverter.class)
105-
String instanceEndpoint;
98+
@WithDefault("https://api.github.com")
99+
@WithConverter(TrimmedStringConverter.class)
100+
String instanceEndpoint();
106101

107102
/**
108103
* The REST API endpoint.
109104
* <p>
110105
* Defaults to the public github.com instance REST API endpoint.
111106
*/
112-
@ConfigItem(defaultValue = "${quarkus.github-app.instance-endpoint}")
113-
@ConvertWith(TrimmedStringConverter.class)
114-
String restApiEndpoint;
107+
@WithDefault("${quarkus.github-app.instance-endpoint}")
108+
@WithConverter(TrimmedStringConverter.class)
109+
String restApiEndpoint();
115110

116111
/**
117112
* The GraphQL API endpoint.
118113
* <p>
119114
* Defaults to the public github.com instance GraphQL endpoint.
120115
*/
121-
@ConfigItem(defaultValue = "${quarkus.github-app.instance-endpoint}/graphql")
122-
@ConvertWith(TrimmedStringConverter.class)
123-
String graphqlApiEndpoint;
116+
@WithDefault("${quarkus.github-app.instance-endpoint}/graphql")
117+
@WithConverter(TrimmedStringConverter.class)
118+
String graphqlApiEndpoint();
124119

125120
/**
126121
* Debug configuration.
127122
*/
128-
@ConfigItem
129-
Debug debug;
123+
Debug debug();
130124

131125
@ConfigGroup
132-
public static class Debug {
126+
public interface Debug {
133127

134128
/**
135129
* A directory in which the payloads are saved.
136130
*/
137-
@ConfigItem
138-
@ConvertWith(TrimmedStringConverter.class)
139-
public Optional<Path> payloadDirectory;
131+
@WithConverter(TrimmedStringConverter.class)
132+
public Optional<Path> payloadDirectory();
140133
}
141134
}

0 commit comments

Comments
 (0)