Hello I am using the standalone version and trying...
# help
b
Hello I am using the standalone version and trying to set up a default stub that’ll go through a proxy as follow. Now I have multiple environments and wished for the baseurl to be configured in an env variable in my container. But it seems that there is no such a support from my research. Does anyone have any suggestions please? Sample proxy mapping:
Copy code
{
  "mappings": [
    {
      "priority": 6,
      "request": {
        "method": "ANY",
        "urlPattern": "/sample/.*"
      },
      "response": {
        "transformers": [
          "proxy-template"
        ],
        "proxyBaseUrl": "${env.url}"
      }
    }
  ]
}
1
l
I think there is a couple of issues. Unless you have created your own transformer I think you might be looking for the
response-template
transformer. This will allow you to use the handlebars templating. Then, for the
proxyBaseUrl
you might be able to use the
systemValue
helper. I have never tried this but it should work like any other helper in this instance:
Copy code
{{systemValue type='ENVIRONMENT' key='URL'}}
So you will be looking at a stub like the following:
Copy code
{
  "mappings": [
    {
      "priority": 6,
      "request": {
        "method": "ANY",
        "urlPattern": "/sample/.*"
      },
      "response": {
        "transformers": [
          "response-template"
        ],
        "proxyBaseUrl": "{{systemValue type='ENVIRONMENT' key='URL'}}"
      }
    }
  ]
}
https://wiremock.org/docs/response-templating/#system-property-helper
❤️ 1
b
I’ve tried it but have it resolves to [Error: Acces to URL is denied] any idea why? I’m on windows and my env variable is a user variable not system
l
I think this is to do with the default security settings put in place by WireMock when accessing system properties or env variables
Could you try changing the name of your environment variable to
wiremock.url
and then update your stub accordingly:
Copy code
{
  "mappings": [
    {
      "priority": 6,
      "request": {
        "method": "ANY",
        "urlPattern": "/sample/.*"
      },
      "response": {
        "transformers": [
          "response-template"
        ],
        "proxyBaseUrl": "{{systemValue type='ENVIRONMENT' key='wiremock.url'}}"
      }
    }
  ]
}
👍 1
If you don't want to rename the env variable you should be able to add your own permitted keys using the startup option:
Copy code
--permitted-system-keys: Comma-separated list of regular expressions for names of permitted environment variables and system properties accessible from response templates. Only has any effect when templating is enabled. Defaults to wiremock.*.
👍 1
b
Thanks worked perfectly for both solutions
l
Excellent. Glad you got it working ok.