Skip to content

Commit

Permalink
Merge pull request #25561 from ejba/25421
Browse files Browse the repository at this point in the history
Consider secure option in service discovery configuration
  • Loading branch information
michalszynkiewicz authored May 27, 2022
2 parents 94a53ba + 565e2e8 commit b0019c0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ public Uni<HttpClientRequest> createRequest(RestClientRequestContext state) {
.failure(new IllegalArgumentException("Invalid REST Client URL used: '" + uri + "'"));
}
if (uri.getScheme().startsWith(Stork.STORK)) {
boolean isHttps = "storks".equals(uri.getScheme());
String serviceName = uri.getHost();
if (serviceName == null) { // invalid URI
return Uni.createFrom()
Expand All @@ -420,6 +419,9 @@ public RequestOptions apply(ServiceInstance serviceInstance) {
if (serviceInstance.gatherStatistics() && shouldMeasureTime(state)) {
state.setCallStatsCollector(serviceInstance);
}

boolean isHttps = serviceInstance.isSecure() || "storks".equals(uri.getScheme());

return new RequestOptions()
.setHost(serviceInstance.getHost())
.setPort(serviceInstance.getPort())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.vertx.core.Vertx;

@ServiceDiscoveryType("my")
@ServiceDiscoveryAttribute(name = "secure", description = "https")
@ServiceDiscoveryAttribute(name = "address-list", description = "a comma-separated list of addresses")
public class MyServiceDiscoveryProvider implements ServiceDiscoveryProvider<MyConfiguration> {
public static volatile Vertx providedVertx;
Expand All @@ -28,14 +29,16 @@ public ServiceDiscovery createServiceDiscovery(MyConfiguration config, String se
ServiceConfig serviceConfig, StorkInfrastructure storkInfrastructure) {
providedVertx = storkInfrastructure.get(Vertx.class, () -> null);
String addressList = config.getAddressList();
boolean secure = Boolean.parseBoolean(config.getSecure());
Uni<List<ServiceInstance>> instances = Uni.createFrom()
.item(Arrays.stream(addressList.split(",")).map(address -> toServiceInstance(address, serviceName))
.item(Arrays.stream(addressList.split(","))
.map(address -> toServiceInstance(address, serviceName, secure))
.collect(Collectors.toList()));
return () -> instances;
}

private ServiceInstance toServiceInstance(String address, String serviceName) {
private ServiceInstance toServiceInstance(String address, String serviceName, boolean secure) {
HostAndPort hostAndPort = StorkAddressUtils.parseToHostAndPort(address, 80, serviceName);
return new DefaultServiceInstance(ServiceInstanceIds.next(), hostAndPort.host, hostAndPort.port, false);
return new DefaultServiceInstance(ServiceInstanceIds.next(), hostAndPort.host, hostAndPort.port, secure);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ quarkus.stork.hello-service.service-discovery.type=my
quarkus.stork.hello-service.load-balancer.type=least-response-time
hello/mp-rest/url=stork://hello-service/hello
# slow-service and fast-service come from Slow- and FastWiremockServer
quarkus.stork.hello-service.service-discovery.address-list=${slow-service},${fast-service}
quarkus.stork.hello-service.service-discovery.address-list=${slow-service},${fast-service}
quarkus.stork.hello-service.service-discovery.secure=true
quarkus.tls.trust-all=true
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ public class FastWiremockServer extends WiremockBase {
static final String FAST_RESPONSE = "hello, I'm a fast server";

@Override
int port() {
int httpPort() {
return 8766;
}

@Override
int httpsPort() {
return 8443;
}

@Override
protected Map<String, String> initWireMock(WireMockServer server) {
server.stubFor(WireMock.get("/hello")
.willReturn(aResponse().withBody(FAST_RESPONSE).withStatus(200)));
return Map.of("fast-service", "localhost:8766");
return Map.of("fast-service", "localhost:8443");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.quarkus.arc.Arc;
import io.quarkus.it.rest.client.reactive.stork.MyServiceDiscoveryProvider;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.DisabledOnNativeImage;
import io.quarkus.test.junit.DisabledOnIntegrationTest;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import io.vertx.core.Vertx;
Expand All @@ -24,7 +24,7 @@
public class RestClientReactiveStorkTest {

@Test
@DisabledOnNativeImage
@DisabledOnIntegrationTest
void shouldUseQuarkusVertxInstance() {
Vertx providedVertx = MyServiceDiscoveryProvider.providedVertx;
assertThat(providedVertx).isNotNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ public class SlowWiremockServer extends WiremockBase {
static final String SLOW_RESPONSE = "hello, I'm a slow server";

@Override
int port() {
int httpPort() {
return 8767;
}

@Override
int httpsPort() {
return 8444;
}

@Override
protected Map<String, String> initWireMock(WireMockServer server) {
server.stubFor(WireMock.get("/hello")
.willReturn(aResponse().withFixedDelay(1000)
.withBody(SLOW_RESPONSE).withStatus(200)));
return Map.of("slow-service", "localhost:8767");
return Map.of("slow-service", "localhost:8444");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public abstract class WiremockBase implements QuarkusTestResourceLifecycleManage

abstract Map<String, String> initWireMock(WireMockServer server);

abstract int port();
abstract int httpPort();

abstract int httpsPort();

@Override
public Map<String, String> start() {
server = new WireMockServer(options().port(port()));
server = new WireMockServer(options().port(httpPort()).httpsPort(httpsPort()));

var result = initWireMock(server);
server.start();
Expand Down

0 comments on commit b0019c0

Please sign in to comment.