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

Switch to @ConfigMapping for the documentation #645

Merged
merged 1 commit into from
Aug 7, 2024
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
12 changes: 8 additions & 4 deletions docs/modules/ROOT/pages/includes/quarkus-github-app.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GITHUB_APP_WEBHOOK_URL_PATH+++`
endif::add-copy-button-to-env-var[]
--|string
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]

|`/`


Expand Down Expand Up @@ -195,7 +196,8 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GITHUB_APP_INSTANCE_ENDPOINT+++`
endif::add-copy-button-to-env-var[]
--|string
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]

|`https://api.github.com`


Expand All @@ -214,7 +216,8 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GITHUB_APP_REST_API_ENDPOINT+++`
endif::add-copy-button-to-env-var[]
--|string
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]

|`${quarkus.github-app.instance-endpoint}`


Expand All @@ -233,7 +236,8 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GITHUB_APP_GRAPHQL_API_ENDPOINT+++`
endif::add-copy-button-to-env-var[]
--|string
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]

|`${quarkus.github-app.instance-endpoint}/graphql`


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public class Routes {
Path tmpDirectory;

public void init(@Observes StartupEvent startupEvent) throws IOException {
if (checkedConfigProvider.debug().payloadDirectory.isPresent()) {
Files.createDirectories(checkedConfigProvider.debug().payloadDirectory.get());
if (checkedConfigProvider.debug().payloadDirectory().isPresent()) {
Files.createDirectories(checkedConfigProvider.debug().payloadDirectory().get());
LOG.warn("Payloads saved to: "
+ checkedConfigProvider.debug().payloadDirectory.get().toAbsolutePath().toString());
+ checkedConfigProvider.debug().payloadDirectory().get().toAbsolutePath().toString());
}
}

Expand Down Expand Up @@ -128,10 +128,10 @@ private void handleRequest(RoutingContext routingContext,

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

if (!isBlank(deliveryId) && checkedConfigProvider.debug().payloadDirectory.isPresent()) {
if (!isBlank(deliveryId) && checkedConfigProvider.debug().payloadDirectory().isPresent()) {
String fileName = DATE_TIME_FORMATTER.format(LocalDateTime.now()) + "-" + event + "-"
+ (!isBlank(action) ? action + "-" : "") + deliveryId + ".json";
Path path = checkedConfigProvider.debug().payloadDirectory.get().resolve(fileName);
Path path = checkedConfigProvider.debug().payloadDirectory().get().resolve(fileName);
try {
Files.write(path, bodyBytes);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ public class CheckedConfigProvider {
if (privateKeyFromCredentials != null && !privateKeyFromCredentials.isBlank()) {
this.privateKey = Optional.of(new PrivateKeyConverter().convert(privateKeyFromCredentials.trim()));
} else {
this.privateKey = gitHubAppRuntimeConfig.privateKey;
this.privateKey = gitHubAppRuntimeConfig.privateKey();
}
String webhookSecretFromCredentials = credentials.get(Credentials.WEBHOOK_SECRET);
if (webhookSecretFromCredentials != null && !webhookSecretFromCredentials.isBlank()) {
this.webhookSecret = Optional.of(webhookSecretFromCredentials.trim());
} else {
this.webhookSecret = gitHubAppRuntimeConfig.webhookSecret;
this.webhookSecret = gitHubAppRuntimeConfig.webhookSecret();
}
this.webhookUrlPath = gitHubAppRuntimeConfig.webhookUrlPath.startsWith("/") ? gitHubAppRuntimeConfig.webhookUrlPath
: "/" + gitHubAppRuntimeConfig.webhookUrlPath;
this.webhookUrlPath = gitHubAppRuntimeConfig.webhookUrlPath().startsWith("/") ? gitHubAppRuntimeConfig.webhookUrlPath()
: "/" + gitHubAppRuntimeConfig.webhookUrlPath();

if (gitHubAppRuntimeConfig.appId.isEmpty()) {
if (gitHubAppRuntimeConfig.appId().isEmpty()) {
missingPropertyKeys.add("quarkus.github-app.app-id (.env: QUARKUS_GITHUB_APP_APP_ID)");
}
if (this.privateKey.isEmpty()) {
Expand All @@ -83,11 +83,11 @@ public String appId() {
}

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

public Optional<String> appName() {
return gitHubAppRuntimeConfig.appName;
return gitHubAppRuntimeConfig.appName();
}

public PrivateKey privateKey() {
Expand All @@ -104,28 +104,28 @@ public Optional<String> webhookSecret() {
}

public Optional<String> webhookProxyUrl() {
return gitHubAppRuntimeConfig.webhookProxyUrl;
return gitHubAppRuntimeConfig.webhookProxyUrl();
}

public String restApiEndpoint() {
return gitHubAppRuntimeConfig.restApiEndpoint;
return gitHubAppRuntimeConfig.restApiEndpoint();
}

public String webhookUrlPath() {
return webhookUrlPath;
}

public String graphqlApiEndpoint() {
return gitHubAppRuntimeConfig.graphqlApiEndpoint;
return gitHubAppRuntimeConfig.graphqlApiEndpoint();
}

public Debug debug() {
return gitHubAppRuntimeConfig.debug;
return gitHubAppRuntimeConfig.debug();
}

public ConfigFile.Source getEffectiveSource(ConfigFile.Source source) {
if (source == ConfigFile.Source.DEFAULT) {
return gitHubAppRuntimeConfig.readConfigFilesFromSourceRepository ? ConfigFile.Source.SOURCE_REPOSITORY
return gitHubAppRuntimeConfig.readConfigFilesFromSourceRepository() ? ConfigFile.Source.SOURCE_REPOSITORY
: ConfigFile.Source.CURRENT_REPOSITORY;
}
return source;
Expand Down Expand Up @@ -155,13 +155,13 @@ public void checkConfig() {
}

private Map<String, String> getCredentials() {
if (gitHubAppRuntimeConfig.credentialsProvider.isEmpty()) {
if (gitHubAppRuntimeConfig.credentialsProvider().isEmpty()) {
return Map.of();
}

String beanName = gitHubAppRuntimeConfig.credentialsProviderName.orElse(null);
String beanName = gitHubAppRuntimeConfig.credentialsProviderName().orElse(null);
CredentialsProvider credentialsProvider = getCredentialsProvider(beanName);
String keyRingName = gitHubAppRuntimeConfig.credentialsProvider.get();
String keyRingName = gitHubAppRuntimeConfig.credentialsProvider().get();

return credentialsProvider.getCredentials(keyRingName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,61 @@

import io.quarkiverse.githubapp.Credentials;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.annotations.ConvertWith;
import io.quarkus.runtime.configuration.TrimmedStringConverter;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithConverter;
import io.smallrye.config.WithDefault;

@ConfigRoot(name = "github-app", phase = ConfigPhase.RUN_TIME)
public class GitHubAppRuntimeConfig {
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
@ConfigMapping(prefix = "quarkus.github-app")
public interface GitHubAppRuntimeConfig {

/**
* The numeric application id provided by GitHub.
* <p>
* Optional for tests, but mandatory in production and dev mode.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
Optional<String> appId;
@WithConverter(TrimmedStringConverter.class)
Optional<String> appId();

/**
* The GitHub name of the application.
* <p>
* Optional, only used for improving the user experience.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
Optional<String> appName;
@WithConverter(TrimmedStringConverter.class)
Optional<String> appName();

/**
* Read the configuration files from the source repository in case of a fork.
*/
@ConfigItem(defaultValue = "false")
boolean readConfigFilesFromSourceRepository;
@WithDefault("false")
boolean readConfigFilesFromSourceRepository();

/**
* The RSA private key.
* <p>
* Optional for tests, but mandatory in production and dev mode.
*/
@ConfigItem
@ConvertWith(PrivateKeyConverter.class)
Optional<PrivateKey> privateKey;
@WithConverter(PrivateKeyConverter.class)
Optional<PrivateKey> privateKey();

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

/**
* The webhook secret if defined in the GitHub UI.
*/
@ConfigItem
Optional<String> webhookSecret;
Optional<String> webhookSecret();

/**
* The credentials provider name.
Expand All @@ -71,9 +69,8 @@ public class GitHubAppRuntimeConfig {
* <p>
* Key names are defined in {@link Credentials}.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
Optional<String> credentialsProvider;
@WithConverter(TrimmedStringConverter.class)
Optional<String> credentialsProvider();

/**
* The credentials provider bean name.
Expand All @@ -84,58 +81,54 @@ public class GitHubAppRuntimeConfig {
* <p>
* For Vault, the credentials provider bean name is {@code vault-credentials-provider}.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
Optional<String> credentialsProviderName;
@WithConverter(TrimmedStringConverter.class)
Optional<String> credentialsProviderName();

/**
* The Smee.io proxy URL used when testing locally.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
Optional<String> webhookProxyUrl;
@WithConverter(TrimmedStringConverter.class)
Optional<String> webhookProxyUrl();

/**
* The GitHub instance endpoint.
* <p>
* Defaults to the public github.com instance.
*/
@ConfigItem(defaultValue = "https://api.github.com")
@ConvertWith(TrimmedStringConverter.class)
String instanceEndpoint;
@WithDefault("https://api.github.com")
@WithConverter(TrimmedStringConverter.class)
String instanceEndpoint();

/**
* The REST API endpoint.
* <p>
* Defaults to the public github.com instance REST API endpoint.
*/
@ConfigItem(defaultValue = "${quarkus.github-app.instance-endpoint}")
@ConvertWith(TrimmedStringConverter.class)
String restApiEndpoint;
@WithDefault("${quarkus.github-app.instance-endpoint}")
@WithConverter(TrimmedStringConverter.class)
String restApiEndpoint();

/**
* The GraphQL API endpoint.
* <p>
* Defaults to the public github.com instance GraphQL endpoint.
*/
@ConfigItem(defaultValue = "${quarkus.github-app.instance-endpoint}/graphql")
@ConvertWith(TrimmedStringConverter.class)
String graphqlApiEndpoint;
@WithDefault("${quarkus.github-app.instance-endpoint}/graphql")
@WithConverter(TrimmedStringConverter.class)
String graphqlApiEndpoint();

/**
* Debug configuration.
*/
@ConfigItem
Debug debug;
Debug debug();

@ConfigGroup
public static class Debug {
public interface Debug {

/**
* A directory in which the payloads are saved.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
public Optional<Path> payloadDirectory;
@WithConverter(TrimmedStringConverter.class)
public Optional<Path> payloadDirectory();
}
}
Loading