io.quarkus.tls.runtime.config.PemKeyCertConfig Maven / Gradle / Ivy
Show all versions of quarkus-tls-registry Show documentation
package io.quarkus.tls.runtime.config;
import static io.quarkus.tls.runtime.config.TlsConfigUtils.read;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.smallrye.config.WithParentName;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.net.PemKeyCertOptions;
@ConfigGroup
public interface PemKeyCertConfig {
/**
* List of the PEM key/cert files (Pem format).
*/
@WithParentName
Map keyCerts();
/**
* The order of the key/cert files, based on the names in the `keyCerts` map.
*
* By default, Quarkus sorts the key using a lexicographical order.
* This property allows you to specify the order of the key/cert files.
*/
Optional> order();
default PemKeyCertOptions toOptions() {
PemKeyCertOptions options = new PemKeyCertOptions();
if (keyCerts().isEmpty()) {
throw new IllegalArgumentException("You must specify the key files and certificate files");
}
List orderedListOfPair = new ArrayList<>();
if (order().isPresent()) {
// Check the size of the order list. It must match the size of the keyCerts map.
if (order().get().size() != keyCerts().size()) {
throw new IllegalArgumentException("The size of the `order` list (" + order().get().size() + ") must " +
"match the size of the `keyCerts` map (" + keyCerts().size() + ")");
}
// We use the order specified by the user.
for (String name : order().get()) {
KeyCertConfig keyCert = keyCerts().get(name);
if (keyCert == null) {
throw new IllegalArgumentException("The key/cert pair with the name '" + name
+ "' is not found in the `order` list: " + order().get());
}
orderedListOfPair.add(keyCert);
}
} else {
// Use the lexical order.
orderedListOfPair.addAll(new TreeMap<>(keyCerts()).values());
}
for (KeyCertConfig config : orderedListOfPair) {
options.addCertValue(Buffer.buffer(read(config.cert())));
options.addKeyValue(Buffer.buffer(read(config.key())));
}
return options;
}
interface KeyCertConfig {
/**
* The path to the key file (in PEM format).
*/
Path key();
/**
* The path to the certificate file (in PEM format).
*/
Path cert();
}
}