|
12 | 12 | import java.util.Optional; |
13 | 13 | import java.util.Set; |
14 | 14 |
|
| 15 | +import org.eclipse.microprofile.config.Config; |
| 16 | +import org.eclipse.microprofile.config.ConfigProvider; |
15 | 17 | import org.jboss.logging.Logger; |
16 | 18 |
|
17 | 19 | import io.smallrye.stork.api.config.ServiceConfig; |
|
20 | 22 | public class StorkConfigUtil { |
21 | 23 |
|
22 | 24 | private static final Logger LOGGER = Logger.getLogger(StorkConfigUtil.class.getName()); |
| 25 | + public static final String HTTPS = "https://"; |
| 26 | + public static final String QUARKUS_HTTP_HOST = "quarkus.http.host"; |
23 | 27 |
|
24 | 28 | public static List<ServiceConfig> toStorkServiceConfig(StorkConfiguration storkConfiguration) { |
25 | 29 | List<ServiceConfig> storkServicesConfigs = new ArrayList<>(); |
@@ -48,10 +52,14 @@ public static List<ServiceConfig> toStorkServiceConfig(StorkConfiguration storkC |
48 | 52 | return storkServicesConfigs; |
49 | 53 | } |
50 | 54 |
|
51 | | - public static ServiceConfiguration buildDefaultRegistrarConfiguration(String serviceRegistrarType, String healthCheckUrl) { |
| 55 | + public static ServiceConfiguration buildDefaultRegistrarConfiguration(String serviceRegistrarType, String healthCheckPath) { |
52 | 56 | Map<String, String> parameters = new HashMap<>(); |
53 | | - if (healthCheckUrl != null && !healthCheckUrl.isBlank()) { |
54 | | - parameters.put("health-check-url", healthCheckUrl); |
| 57 | + Config quarkusConfig = ConfigProvider.getConfig(); |
| 58 | + String defaultHost = quarkusConfig.getValue(QUARKUS_HTTP_HOST, String.class); |
| 59 | + if (healthCheckPath != null && !healthCheckPath.isBlank()) { |
| 60 | + healthCheckPath = HTTPS + getOrDefaultHost(parameters, quarkusConfig) + ":" |
| 61 | + + getOrDefaultPort(parameters, quarkusConfig) + healthCheckPath; |
| 62 | + parameters.put("health-check-url", healthCheckPath); |
55 | 63 | } |
56 | 64 | return buildServiceConfigurationWithRegistrar(serviceRegistrarType, parameters); |
57 | 65 | } |
@@ -106,6 +114,22 @@ public Map<String, String> parameters() { |
106 | 114 | }; |
107 | 115 | } |
108 | 116 |
|
| 117 | + public static String getOrDefaultHost(Map<String, String> parameters, Config quarkusConfig) { |
| 118 | + String customHost = parameters.containsKey("ip-address") ? parameters.get("ip-address") |
| 119 | + : null; |
| 120 | + String defaultHost = quarkusConfig.getValue("quarkus.http.host", String.class); |
| 121 | + if (customHost == null || customHost.isEmpty()) { |
| 122 | + InetAddress inetAddress = StorkConfigUtil.detectAddress(); |
| 123 | + customHost = inetAddress != null ? inetAddress.getHostAddress() : defaultHost; |
| 124 | + } |
| 125 | + return customHost; |
| 126 | + } |
| 127 | + |
| 128 | + public static int getOrDefaultPort(Map<String, String> parameters, Config quarkusConfig) { |
| 129 | + String customPort = parameters.getOrDefault("port", quarkusConfig.getValue("quarkus.http.port", String.class)); |
| 130 | + return Integer.parseInt(customPort); |
| 131 | + } |
| 132 | + |
109 | 133 | public static InetAddress detectAddress() { |
110 | 134 | InetAddress result = null; |
111 | 135 | try { |
|
0 commit comments