Skip to content

Commit

Permalink
Enable extension in development mode only
Browse files Browse the repository at this point in the history
  • Loading branch information
hpehl committed Mar 8, 2019
1 parent 5f1f214 commit 0747a20
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Quarkus Config Extension

Adds a servlet to a [Quarkus](https://quarkus.io) application which lists the configured values for [MicroProfile Configuration](https://microprofile.io/project/eclipse/microprofile-config). The servlet is registered using the path `/config` by default and lists all properties of all config sources. The config sources are sorted descending by ordinal, the properties by name. If no config is defined an empty JSON object is returned.
Adds a servlet to a [Quarkus](https://quarkus.io) application running in dev mode which lists the configured values for [MicroProfile Configuration](https://microprofile.io/project/eclipse/microprofile-config). The servlet is registered using the path `/config` by default and lists all properties of all config sources. The config sources are sorted descending by ordinal, the properties by name. If no config is defined an empty JSON object is returned.

A typical output might look like:
```json
Expand Down Expand Up @@ -44,3 +44,5 @@ To use the extension in your Quarkus app, add the following dependency to your p
<scope>provided</scope>
</dependency>
```

Please note that the extension is only available in development mode by default. To use it in normal mode as well set `quarkus.config.dev-mode-only = false` in your configuration.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package io.quarkus.config.deployment;

import static java.util.Arrays.asList;

import java.util.List;
import java.util.logging.Logger;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.config.runtime.ConfigServlet;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.undertow.deployment.ServletBuildItem;
Expand All @@ -32,37 +32,57 @@
*
* @author Harald Pehl
*/
class ConfigProcessor {
public class ConfigProcessor {

private static final Logger log = Logger.getLogger("io.quarkus.config");

/**
* The configuration for config extension.
*/
ConfigConfig config;


@ConfigRoot(name = "config")
static final class ConfigConfig {

/**
* The path of the config servlet.
*/
@ConfigItem(defaultValue = "/config")
String path;
}

@BuildStep
ServletBuildItem produceServlet() {
ServletBuildItem servletBuildItem = ServletBuildItem.builder("config", ConfigServlet.class.getName())
.addMapping(config.path)
.build();
return servletBuildItem;
/**
* Whether the servlet is configured in dev mode only.
*/
@ConfigItem(defaultValue = "true")
boolean devModeOnly;
}

@BuildStep
List<AdditionalBeanBuildItem> additionalBeans() {
return asList(new AdditionalBeanBuildItem(ConfigServlet.class));
}
public void build(LaunchModeBuildItem launchMode,
BuildProducer<AdditionalBeanBuildItem> beans,
BuildProducer<ServletBuildItem> servlets,
BuildProducer<FeatureBuildItem> feature) {

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem("config");
boolean useExtension;
if (launchMode.getLaunchMode().isDevOrTest()) {
useExtension = true;
} else {
useExtension = !config.devModeOnly;
if (useExtension) {
log.warning("Config extension was enabled in normal mode! " +
"All configuration will be visible at the /" + config.path + " endpoint. " +
"If that's not what you want, remove 'quarkus.config.dev-mode-only = false' " +
"from your configuration.");
}
}

if (useExtension) {
beans.produce(new AdditionalBeanBuildItem(ConfigServlet.class));
servlets.produce(ServletBuildItem.builder("config", ConfigServlet.class.getName())
.addMapping(config.path)
.build());
feature.produce(new FeatureBuildItem("config"));
}
}
}

0 comments on commit 0747a20

Please sign in to comment.