Skip to content

Commit

Permalink
Removes deprecated @configroot without @ConfigMapping (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtama authored Aug 26, 2024
1 parent c000785 commit 2932750
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 126 deletions.
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/attributes.adoc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
:quarkus-version: 3.12.0
:quarkus-version: 3.14.0
:quarkus-minio-version: 3.7.5
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static String formatPropertyName(String property, String minoClientName)
}

private MinioDevServiceCfg getConfiguration(MinioBuildTimeConfig cfg) {
MinioDevServicesBuildTimeConfig devServicesConfig = cfg.devservices;
MinioDevServicesBuildTimeConfig devServicesConfig = cfg.devservices();
return new MinioDevServiceCfg(devServicesConfig);
}

Expand All @@ -275,14 +275,14 @@ private static final class MinioDevServiceCfg {
private final Map<String, String> containerEnv;

public MinioDevServiceCfg(MinioDevServicesBuildTimeConfig config) {
this.devServicesEnabled = config.enabled.orElse(true);
this.imageName = config.imageName;
this.fixedExposedPort = config.port.orElse(0);
this.shared = config.shared;
this.serviceName = config.serviceName;
this.accessKey = config.accessKey;
this.secretKey = config.secretKey;
this.containerEnv = config.containerEnv;
this.devServicesEnabled = config.enabled();
this.imageName = config.imageName();
this.fixedExposedPort = config.port();
this.shared = config.shared();
this.serviceName = config.serviceName();
this.accessKey = config.accessKey();
this.secretKey = config.secretKey();
this.containerEnv = config.containerEnv();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.quarkiverse.minio.client.deployment.devservices;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(name = "minio", phase = ConfigPhase.BUILD_TIME)
public class MinioBuildTimeConfig {
@ConfigMapping(prefix = "quarkus.minio")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface MinioBuildTimeConfig {

/**
* Configuration for DevServices. DevServices allows Quarkus to automatically start Minio in dev and test mode.
*/
@ConfigItem
public MinioDevServicesBuildTimeConfig devservices;
MinioDevServicesBuildTimeConfig devservices();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithDefault;

@ConfigGroup
public class MinioDevServicesBuildTimeConfig {
public interface MinioDevServicesBuildTimeConfig {

/**
* Enable or disable Dev Services explicitly. Dev Services are automatically enabled unless {@code quarkus.minio.url} is
* set.
*/
@ConfigItem
public Optional<Boolean> enabled = Optional.empty();
@WithDefault("true")
Boolean enabled();

/**
* Optional fixed port the dev service will listen to.
* <p>
* If not defined, the port will be chosen randomly.
*/
@ConfigItem
public Optional<Integer> port;
@WithDefault("0")
Integer port();

/**
* The Minio container image to use.
*/
@ConfigItem(defaultValue = "minio/minio:RELEASE.2022-10-08T20-11-00Z")
public String imageName;
@WithDefault("minio/minio:RELEASE.2022-10-08T20-11-00Z")
String imageName();

/**
* Indicates if the Minio server managed by Quarkus Dev Services is shared.
Expand All @@ -42,8 +42,8 @@ public class MinioDevServicesBuildTimeConfig {
* <p>
* Container sharing is only used in dev mode.
*/
@ConfigItem(defaultValue = "true")
public boolean shared;
@WithDefault("true")
boolean shared();

/**
* The value of the {@code quarkus-dev-service-minio} label attached to the started container.
Expand All @@ -55,25 +55,24 @@ public class MinioDevServicesBuildTimeConfig {
* <p>
* This property is used when you need multiple shared Minio servers.
*/
@ConfigItem(defaultValue = "minio")
public String serviceName;
@WithDefault("minio")
String serviceName();

/**
* Minio root username access key.
*/
@ConfigItem(defaultValue = "minioaccess")
public String accessKey;
@WithDefault("minioaccess")
String accessKey();

/**
* Minio root username secret key.
*/
@ConfigItem(defaultValue = "miniosecret")
public String secretKey;
@WithDefault("miniosecret")
String secretKey();

/**
* Extra environment variables that will be passed to the devservice.
*/
@ConfigItem
@ConfigDocMapKey("environment-variable-name")
public Map<String, String> containerEnv;
Map<String, String> containerEnv();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void createCard(BuildProducer<CardPageBuildItem> cardProducer, MinioBuildTimeCon

final CardPageBuildItem card = new CardPageBuildItem();

card.addBuildTimeData("enabled", devServiceConfig.devservices.enabled.orElse(true));
card.addBuildTimeData("enabled", devServiceConfig.devservices().enabled());

card.addPage(Page.externalPageBuilder("Min.io console")
.icon("font-awesome-solid:signs-post")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.quarkiverse.minio.client;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithDefault;

@ConfigGroup
public class MinioBuildTimeConfiguration {
public interface MinioBuildTimeConfiguration {

/**
* Should the extension provide a `MinioClient`.
* If set to `false`, you will have to create the clients yourself,
* but will still benefit the native compatibility work.
*/
@ConfigItem(defaultValue = "true")
public boolean enabled;
@WithDefault("true")
boolean enabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ public MinioClient createMinioClient(String minioClientName) {
MinioRuntimeConfiguration configuration = getAndVerifyConfiguration(minioClientName);

MinioClient.Builder builder = MinioClient.builder();
configuration.getPort()
configuration.port()
.ifPresentOrElse(
port -> builder.endpoint(configuration.getUrl(), port, configuration.isTls()),
port -> builder.endpoint(configuration.url(), port, configuration.secure()),
() -> builder.endpoint(
HttpUtils.getBaseUrl(configuration.getUrl()).newBuilder()
.scheme(configuration.isTls() ? "https" : "http").build()));
HttpUtils.getBaseUrl(configuration.url()).newBuilder()
.scheme(configuration.secure() ? "https" : "http").build()));

builder.credentials(configuration.getAccessKey(), configuration.getSecretKey());
configuration.region.ifPresent(builder::region);
if (miniosRuntimeConfiguration.produceMetrics) {
builder.credentials(configuration.accessKey(), configuration.secretKey());
configuration.region().ifPresent(builder::region);
if (miniosRuntimeConfiguration.produceMetrics()) {
httpClientProducer.apply(minioClientName).ifPresent(builder::httpClient);
}
return builder.build();
Expand All @@ -99,16 +99,16 @@ public MinioAsyncClient createMinioAsyncClient(String minioClientName) {
MinioRuntimeConfiguration configuration = getAndVerifyConfiguration(minioClientName);

MinioAsyncClient.Builder builder = MinioAsyncClient.builder();
configuration.getPort()
configuration.port()
.ifPresentOrElse(
port -> builder.endpoint(configuration.getUrl(), port, configuration.isTls()),
port -> builder.endpoint(configuration.url(), port, configuration.secure()),
() -> builder.endpoint(
HttpUtils.getBaseUrl(configuration.getUrl()).newBuilder()
.scheme(configuration.isTls() ? "https" : "http").build()));
HttpUtils.getBaseUrl(configuration.url()).newBuilder()
.scheme(configuration.secure() ? "https" : "http").build()));

builder.credentials(configuration.getAccessKey(), configuration.getSecretKey());
configuration.region.ifPresent(builder::region);
if (miniosRuntimeConfiguration.produceMetrics) {
builder.credentials(configuration.accessKey(), configuration.secretKey());
configuration.region().ifPresent(builder::region);
if (miniosRuntimeConfiguration.produceMetrics()) {
httpClientProducer.apply(minioClientName).ifPresent(builder::httpClient);
}
return builder.build();
Expand All @@ -121,13 +121,12 @@ private MinioRuntimeConfiguration getAndVerifyConfiguration(String minioClientNa

MinioRuntimeConfiguration configuration;
if (MiniosBuildTimeConfiguration.isDefault(minioClientName)) {
configuration = miniosRuntimeConfiguration.minio();
configuration = miniosRuntimeConfiguration.minio().get();
} else {
configuration = miniosRuntimeConfiguration.namedMinioClients().getOrDefault(minioClientName,
new MinioRuntimeConfiguration());
configuration = miniosRuntimeConfiguration.namedMinioClients().get(minioClientName);
}

if (IS_URL_SET.test(configuration.getUrl())) {
if (configuration == null || IS_URL_SET.test(configuration.url())) {
String errorMessage;
if (MiniosBuildTimeConfiguration.isDefault(minioClientName)) {
errorMessage = "\"quarkus.minio.url\" is mandatory and must be a valid url";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import java.util.Optional;

import org.eclipse.microprofile.config.spi.Converter;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.Converters;
import io.smallrye.config.WithConverter;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.minio")
@ConfigGroup
public class MinioRuntimeConfiguration {
public interface MinioRuntimeConfiguration {

/**
* The minio server URL.
Expand All @@ -20,68 +26,56 @@ public class MinioRuntimeConfiguration {
*
* @asciidoclet
*/
@ConfigItem
Optional<String> url = Optional.empty();
@WithConverter(EmptyConverter.class)
String url();

/**
* The minio server access key
*
* @asciidoclet
*/
@ConfigItem
Optional<String> accessKey = Optional.empty();
@WithConverter(EmptyConverter.class)
String accessKey();

/**
* The minio server secret key
*
* @asciidoclet
*/
@ConfigItem
Optional<String> secretKey = Optional.empty();
@WithConverter(EmptyConverter.class)
String secretKey();

/**
* An optional bucket region
*
* @asciidoclet
*/
@ConfigItem
Optional<String> region = Optional.empty();
Optional<String> region();

/**
* An optional port number.
* Specifically usefull if you want to access bucket that doesn't use standard port (i.e. *80* for HTTP and *443* for HTTPS)
*
* @asciidoclet
*/
Optional<Integer> port = Optional.empty();
Optional<Integer> port();

/**
* An optional boolean to enable secure connection.
* Defaults to `true`
*
* @asciidoclet
*/
@ConfigItem(defaultValue = "true")
boolean secure;

public String getUrl() {
return url.orElse("");
}

String getAccessKey() {
return accessKey.orElse("");
}
@WithDefault("true")
boolean secure();

String getSecretKey() {
return secretKey.orElse("");
}
class EmptyConverter implements org.eclipse.microprofile.config.spi.Converter<String> {

Optional<Integer> getPort() {
return port;
}
Converter<String> delegate = Converters.newEmptyValueConverter(value -> value, "");

Boolean isTls() {
return secure;
@Override
public String convert(String s) throws IllegalArgumentException, NullPointerException {
return delegate.convert(s);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,41 @@
import java.util.Map;
import java.util.stream.Collectors;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithParentName;

@ConfigRoot(name = "minio", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public class MiniosBuildTimeConfiguration {
@ConfigMapping(prefix = "quarkus.minio")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public interface MiniosBuildTimeConfiguration {

public static final String DEFAULT_MINIOCLIENT_NAME = "<default>";
String DEFAULT_MINIOCLIENT_NAME = "<default>";

/**
* The default client
*/
@ConfigItem(name = ConfigItem.PARENT)
public MinioBuildTimeConfiguration minio;
@WithParentName()
MinioBuildTimeConfiguration minio();

/**
* Additional named client
*/
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, MinioBuildTimeConfiguration> namedMinioClients;
@WithParentName()
Map<String, MinioBuildTimeConfiguration> namedMinioClients();

public Map<String, MinioBuildTimeConfiguration> getMinioClients() {
default Map<String, MinioBuildTimeConfiguration> getMinioClients() {
var minioClients = new HashMap<String, MinioBuildTimeConfiguration>();
if (minio == null) {
minio = new MinioBuildTimeConfiguration();
if (minio() != null && minio().enabled()) {
minioClients.put(DEFAULT_MINIOCLIENT_NAME, minio());
}
if (minio.enabled) {
minioClients.put(DEFAULT_MINIOCLIENT_NAME, minio);
}
minioClients.putAll(namedMinioClients.entrySet().stream()
.filter(entry -> entry.getValue().enabled)
minioClients.putAll(namedMinioClients().entrySet().stream()
.filter(entry -> entry.getValue().enabled())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
return minioClients;
}

public static boolean isDefault(String minioClientName) {
static boolean isDefault(String minioClientName) {
return MiniosBuildTimeConfiguration.DEFAULT_MINIOCLIENT_NAME.equals(minioClientName);
}
}
Loading

0 comments on commit 2932750

Please sign in to comment.