spring-cloud-contract icon indicating copy to clipboard operation
spring-cloud-contract copied to clipboard

Enable users to configure Wiremock server via environment variables

Open Sic4Parvis9Magna opened this issue 4 years ago • 5 comments

Description: There were some discussions related to the subject of that issue. See here: issue#1 issue#2 It seems like there is a request for such functionality.

Possible approach From my perspective, it can be solved by introducing a bean of com.github.tomakehurst.wiremock.core.Options type via a class annotated with @ConfigurationProperties(prefix="wiremock.embedded")

Sic4Parvis9Magna avatar Nov 25 '19 19:11 Sic4Parvis9Magna

It seems like there is a request for such functionality.

Currently there are 2 people ;)

I'll think about this. Thanks for filing the issue.

marcingrzejszczak avatar Nov 25 '19 19:11 marcingrzejszczak

It seems like there is a request for such functionality.

Currently there are 2 people ;)

I'll think about this. Thanks for filing the issue.

Yep, that's not many people requested that functionality so far. It will make the docker image more flexible for using as a base image and so on. If my guess is correct implementation would not take a lot of effort.

Thanks for considering it as a possible feature.

Sic4Parvis9Magna avatar Nov 25 '19 20:11 Sic4Parvis9Magna

I have use case similar to #711. I want to proxy requests that does not match the stubs to the real API. proxyBaseUrl option from standalone Wiremock application just adds catch all mapping that proxies the request. It is easy to add this additional mapping as Wiremock by default looks into src/test/resources/mappings. I am using the Docker image to run the stubs. Mounting the additional mapping into src/test/resources/mappings works but src/test/resources seems to be a bit random outside of Maven/Gradle project.

To configure this path is quite easy. I've implemented HttpServerStubConfigurer<WireMockConfiguration> that sets wireMockConfiguration.withRootDirectory() to the desired value. Then I've set the STUBRUNNER_HTTP_SERVER_STUB_CONFIGURER environment variable to my HttpServerStubConfigurer implementation.

While this works the downside is that I need to build my own stub runner and Docker image just to configure wireMockConfiguration. At the same time there is WireMockHttpServerStubConfigurer that is intended (or not?) to do just that. I wonder why the current implementation is no-op. Maybe StubRunnerOptions can be extended with httpServerStubConfigurerOptions in addition to httpServerStubConfigurer so the HttpServerStubConfigurer can use it to configure the HTTP Server stub. And then WireMockHttpServerStubConfigurer can use it to configure Wiremock. Does that makes sense?

If this is implemented then my use case (and the other mentioned here) are just a matter of setting environment variable (or two) and would not require implementing custom HttpServerStubConfigurer.

plamentotev avatar Mar 03 '21 18:03 plamentotev

Hello @marcingrzejszczak, this is useful for anyone using wiremock e.g. in a docker-compose setup where wiremock is started standalone to mock away other services not needed in a local environment. So with me, there are at least 3 people having a demand (and probably more). Kind Regards

protux avatar Nov 22 '21 09:11 protux

Sure, there's already some work in progress in this PR https://github.com/spring-cloud/spring-cloud-contract/pull/1687 but it's not yet ready for review. If you want to help out, please be my guest

marcingrzejszczak avatar Nov 22 '21 09:11 marcingrzejszczak