Skip to content

Commit 4504510

Browse files
committed
revert port logic for eager loading
1 parent be3157b commit 4504510

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

localstack/utils/bootstrap.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,17 @@ def get_enabled_apis() -> Set[str]:
233233
services = SERVICE_PLUGINS.list_available()
234234

235235
if services_env and is_env_true("STRICT_SERVICE_LOADING"):
236-
from localstack.services.plugins import SERVICE_PLUGINS
237-
238236
# SERVICES and STRICT_SERVICE_LOADING are set
239237
# we filter the result of SERVICE_PLUGINS.list_available() to cross the user-provided list with
240238
# the available ones
241-
services = [service for service in services_env.split(",") if service in services]
239+
enabled_services = []
240+
for service_port in re.split(r"\s*,\s*", services_env):
241+
# Only extract the service name, discard the port
242+
parts = re.split(r"[:=]", service_port)
243+
service = parts[0]
244+
enabled_services.append(service)
245+
246+
services = [service for service in enabled_services if service in services]
242247
# TODO: log a message if a service was not supported? see with pro loading
243248

244249
return resolve_apis(services)
@@ -263,7 +268,12 @@ def get_preloaded_services() -> Set[str]:
263268
if services_env and is_env_true("EAGER_SERVICE_LOADING"):
264269
# SERVICES and EAGER_SERVICE_LOADING are set
265270
# SERVICES env var might contain ports, but we do not support these anymore
266-
services = [service for service in services_env.split(",")]
271+
services = []
272+
for service_port in re.split(r"\s*,\s*", services_env):
273+
# Only extract the service name, discard the port
274+
parts = re.split(r"[:=]", service_port)
275+
service = parts[0]
276+
services.append(service)
267277

268278
if not services:
269279
from localstack.services.plugins import SERVICE_PLUGINS
@@ -274,7 +284,16 @@ def get_preloaded_services() -> Set[str]:
274284

275285

276286
def should_eager_load_api(api: str) -> bool:
277-
return api in get_preloaded_services()
287+
apis = get_preloaded_services()
288+
289+
if api in apis:
290+
return True
291+
292+
for enabled_api in apis:
293+
if api.startswith(f"{enabled_api}:"):
294+
return True
295+
296+
return False
278297

279298

280299
def start_infra_locally():

tests/unit/utils/test_bootstrap.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,14 @@ def test_custom_service_without_port(self):
6161
assert "foobar" in result
6262

6363
def test_custom_port_mapping_in_services_env(self):
64-
"""
65-
We do not support custom port mapping anymore, assert that it goes through but will not load the service
66-
"""
67-
6864
with temporary_env({"SERVICES": "foobar:1235", "EAGER_SERVICE_LOADING": "1"}):
6965
result = get_preloaded_services()
7066

7167
assert len(result) == 1
72-
assert "foobar:1235" in result
73-
assert "foobar" not in result
68+
assert "foobar" in result
7469

7570
def test_resolve_meta(self):
76-
with temporary_env({"SERVICES": "es,cognito", "EAGER_SERVICE_LOADING": "1"}):
71+
with temporary_env({"SERVICES": "es,cognito:1337", "EAGER_SERVICE_LOADING": "1"}):
7772
result = get_preloaded_services()
7873

7974
assert len(result) == 4
@@ -121,19 +116,26 @@ def test_custom_service_not_supported(self):
121116

122117
assert not result
123118

124-
def test_custom_service_and_supported_service(self):
119+
def test_custom_service_with_supported_service(self):
125120
with temporary_env({"SERVICES": "foobar,s3", "STRICT_SERVICE_LOADING": "1"}):
126121
result = get_enabled_apis()
127122

128123
assert len(result) == 1
129124
assert "s3" in result
130125

131-
def test_custom_port_mapping_in_services_env_not_supported(self):
126+
def test_custom_service_and_port_mapping_in_services_env_not_supported(self):
132127
with temporary_env({"SERVICES": "foobar:1235", "STRICT_SERVICE_LOADING": "1"}):
133128
result = get_enabled_apis()
134129

135130
assert not result
136131

132+
def test_custom_port_mapping_with_supported_service(self):
133+
with temporary_env({"SERVICES": "s3:1234", "STRICT_SERVICE_LOADING": "1"}):
134+
result = get_enabled_apis()
135+
136+
assert len(result) == 1
137+
assert "s3" in result
138+
137139
def test_resolve_meta(self):
138140
with temporary_env({"SERVICES": "es,lambda", "STRICT_SERVICE_LOADING": "1"}):
139141
result = get_enabled_apis()

0 commit comments

Comments
 (0)