Skip to content

Commit 6a47f01

Browse files
committed
have wiremock api key passed to the extension
1 parent de4eb5d commit 6a47f01

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

wiremock/localstack_wiremock/extension.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@ class WireMockExtension(ProxiedDockerContainerExtension):
2525
def __init__(self):
2626
env_vars = {}
2727
image_name = self.DOCKER_IMAGE
28-
kwargs = {}
28+
volumes = None
2929
if api_token := os.getenv(ENV_WIREMOCK_API_TOKEN):
3030
env_vars["WMC_ADMIN_PORT"] = str(PORT)
31-
# TODO remove?
32-
# env_vars["WMC_DEFAULT_MODE"] = "record-many"
3331
env_vars["WMC_API_TOKEN"] = api_token
3432
env_vars["WMC_RUNNER_ENABLED"] = "true"
3533
image_name = self.DOCKER_IMAGE_RUNNER
3634
settings_file = Util.mountable_tmp_file()
3735
# TODO: set configs in YAML file
38-
kwargs["volumes"] = ([(settings_file, "/work/.wiremock/wiremock.yaml")],)
36+
volumes = [(settings_file, "/work/.wiremock/wiremock.yaml")]
3937
super().__init__(
4038
image_name=image_name,
4139
container_ports=[PORT],
4240
container_name=self.CONTAINER_NAME,
4341
host=self.HOST,
44-
**kwargs,
42+
volumes=volumes,
43+
env_vars=env_vars if env_vars else None,
4544
)

wiremock/localstack_wiremock/utils/docker.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ class ProxiedDockerContainerExtension(Extension):
4747
http2_ports: list[int] | None
4848
"""List of ports for which HTTP2 proxy forwarding into the container should be enabled."""
4949

50-
volumes: list[SimpleVolumeBind] | None = (None,)
50+
volumes: list[SimpleVolumeBind] | None = None
5151
"""Optional volumes to mount into the container host."""
5252

53+
env_vars: dict[str, str] | None = None
54+
"""Optional environment variables to pass to the container."""
55+
5356
def __init__(
5457
self,
5558
image_name: str,
@@ -61,6 +64,7 @@ def __init__(
6164
request_to_port_router: Callable[[Request], int] | None = None,
6265
http2_ports: list[int] | None = None,
6366
volumes: list[SimpleVolumeBind] | None = None,
67+
env_vars: dict[str, str] | None = None,
6468
):
6569
self.image_name = image_name
6670
self.container_ports = container_ports
@@ -71,6 +75,7 @@ def __init__(
7175
self.request_to_port_router = request_to_port_router
7276
self.http2_ports = http2_ports
7377
self.volumes = volumes
78+
self.env_vars = env_vars
7479

7580
def update_gateway_routes(self, router: http.Router[http.RouteHandler]):
7681
if self.path:
@@ -106,6 +111,8 @@ def start_container(self) -> None:
106111
kwargs = {}
107112
if self.command:
108113
kwargs["command"] = self.command
114+
if self.env_vars:
115+
kwargs["env_vars"] = self.env_vars
109116

110117
try:
111118
DOCKER_CLIENT.run_container(

wiremock/sample-app/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resource "null_resource" "package_lambda" {
3434
rm -rf "${path.module}/build"
3535
mkdir -p "${path.module}/build"
3636
cp "${path.module}/src/handler.py" "${path.module}/build/"
37-
pip install -r "${path.module}/src/requirements.txt" -t "${path.module}/build"
37+
pip3 install -r "${path.module}/src/requirements.txt" -t "${path.module}/build"
3838
EOT
3939
interpreter = ["/bin/bash", "-c"]
4040
}

0 commit comments

Comments
 (0)