From 00bdbbb2d8497da0ea7f1ed140d6990eb9d68d16 Mon Sep 17 00:00:00 2001 From: Alexander Rashed Date: Tue, 31 Oct 2023 16:53:26 +0100 Subject: [PATCH 1/2] remove deprecated HTTP endpoints / routes --- localstack/services/cloudwatch/provider.py | 11 ------- localstack/services/infra.py | 5 +-- localstack/services/internal.py | 13 -------- localstack/services/ses/provider.py | 17 +--------- localstack/utils/config_listener.py | 38 +--------------------- tests/integration/test_config_endpoint.py | 3 -- 6 files changed, 3 insertions(+), 84 deletions(-) diff --git a/localstack/services/cloudwatch/provider.py b/localstack/services/cloudwatch/provider.py index 889c6795738922..76aaa292b0bccf 100644 --- a/localstack/services/cloudwatch/provider.py +++ b/localstack/services/cloudwatch/provider.py @@ -28,7 +28,6 @@ ) from localstack.aws.connect import connect_to from localstack.constants import DEFAULT_AWS_ACCOUNT_ID -from localstack.deprecations import deprecated_endpoint from localstack.http import Request from localstack.services import moto from localstack.services.cloudwatch.alarm_scheduler import AlarmScheduler @@ -232,16 +231,6 @@ def __init__(self): def on_after_init(self): ROUTER.add(PATH_GET_RAW_METRICS, self.get_raw_metrics) - # TODO remove with 2.0 - ROUTER.add( - DEPRECATED_PATH_GET_RAW_METRICS, - deprecated_endpoint( - self.get_raw_metrics, - previous_path=DEPRECATED_PATH_GET_RAW_METRICS, - deprecation_version="1.3.0", - new_path=PATH_GET_RAW_METRICS, - ), - ) self.start_alarm_scheduler() def on_before_state_reset(self): diff --git a/localstack/services/infra.py b/localstack/services/infra.py index ecff707735f231..ac2e759ee16fca 100644 --- a/localstack/services/infra.py +++ b/localstack/services/infra.py @@ -25,7 +25,7 @@ from localstack.services import motoserver from localstack.services.generic_proxy import ProxyListener, start_proxy_server from localstack.services.plugins import SERVICE_PLUGINS, ServiceDisabled, wait_for_infra_shutdown -from localstack.utils import config_listener, files, objects +from localstack.utils import files, objects from localstack.utils.analytics import usage from localstack.utils.aws.request_context import patch_moto_request_handling from localstack.utils.bootstrap import is_api_enabled, log_duration, setup_logging @@ -66,9 +66,6 @@ # can be set EXIT_CODE: objects.Value[int] = objects.Value(0) -# Start config update backdoor -config_listener.start_listener() - # --------------- # HELPER METHODS diff --git a/localstack/services/internal.py b/localstack/services/internal.py index ec0125272432a0..7c230d5e894375 100644 --- a/localstack/services/internal.py +++ b/localstack/services/internal.py @@ -325,20 +325,7 @@ def add_default_routes(self): from localstack.services.plugins import SERVICE_PLUGINS health_resource = HealthResource(SERVICE_PLUGINS) - # special route for legacy support (before `/_localstack` was introduced) - self.add( - Resource( - "/health", - DeprecatedResource( - health_resource, - previous_path="/health", - deprecation_version="1.3.0", - new_path="/_localstack/health", - ), - ), - ) self.add(Resource("/_localstack/health", health_resource)) - self.add(Resource("/_localstack/info", InfoResource())) self.add(Resource("/_localstack/plugins", PluginsResource())) self.add(Resource("/_localstack/init", InitScriptsResource())) diff --git a/localstack/services/ses/provider.py b/localstack/services/ses/provider.py index f32d46e96c2c44..041948aee203e1 100644 --- a/localstack/services/ses/provider.py +++ b/localstack/services/ses/provider.py @@ -54,7 +54,6 @@ from localstack.aws.connect import connect_to from localstack.constants import TEST_AWS_SECRET_ACCESS_KEY from localstack.http import Resource, Response -from localstack.services.internal import DeprecatedResource, get_internal_apis from localstack.services.moto import call_moto from localstack.services.plugins import ServiceLifecycleHook from localstack.services.ses.models import SentEmail, SentEmailBody @@ -165,23 +164,9 @@ def register_ses_api_resource(): global _EMAILS_ENDPOINT_REGISTERED if not _EMAILS_ENDPOINT_REGISTERED: - ses_service_api_resource = SesServiceApiResource() - get_internal_apis().add( - Resource( - "/_localstack/ses", - DeprecatedResource( - ses_service_api_resource, - previous_path="/_localstack/ses", - deprecation_version="1.4.0", - new_path="/_aws/ses", - ), - ) - ) - from localstack.services.edge import ROUTER - ROUTER.add(Resource(EMAILS_ENDPOINT, ses_service_api_resource)) - + ROUTER.add(Resource(EMAILS_ENDPOINT, SesServiceApiResource())) _EMAILS_ENDPOINT_REGISTERED = True diff --git a/localstack/utils/config_listener.py b/localstack/utils/config_listener.py index f8b53b445c1a35..c8678baede5aef 100644 --- a/localstack/utils/config_listener.py +++ b/localstack/utils/config_listener.py @@ -5,9 +5,7 @@ from requests.models import Response -from localstack import config, constants -from localstack.deprecations import deprecated_endpoint -from localstack.services.generic_proxy import ProxyListener +from localstack import config LOG = logging.getLogger(__name__) @@ -42,37 +40,3 @@ def _update_config_variable_handler(data): result = {"variable": variable, "value": value} response._content = json.dumps(result) return response - - -class ConfigUpdateProxyListener(ProxyListener): - """Default proxy listener that intercepts requests to retrieve or update config variables.""" - - def __init__(self): - self._handler = deprecated_endpoint( - endpoint=_update_config_variable_handler, - previous_path=constants.CONFIG_UPDATE_PATH, - deprecation_version="1.4.0", - new_path="/_localstack/config", - ) - - def forward_request(self, method, path, data, headers): - if path != constants.CONFIG_UPDATE_PATH or method != "POST": - return True - - return self._handler(data) - - -CONFIG_UPDATE_LISTENER = ConfigUpdateProxyListener() - - -def start_listener(): - if config.ENABLE_CONFIG_UPDATES: - ProxyListener.DEFAULT_LISTENERS.append(CONFIG_UPDATE_LISTENER) - - -def remove_listener(): - if not config.ENABLE_CONFIG_UPDATES: - try: - ProxyListener.DEFAULT_LISTENERS.remove(CONFIG_UPDATE_LISTENER) - except ValueError: - pass diff --git a/tests/integration/test_config_endpoint.py b/tests/integration/test_config_endpoint.py index 5d27ba7b1ff925..f601e8d2479280 100644 --- a/tests/integration/test_config_endpoint.py +++ b/tests/integration/test_config_endpoint.py @@ -15,12 +15,9 @@ def config_endpoint(monkeypatch): router = get_internal_apis() monkeypatch.setattr(config, "ENABLE_CONFIG_UPDATES", True) - # will listen on /?_config_ - config_listener.start_listener() # will listen on /_localstack/config rules = router.add(Resource("/_localstack/config", ConfigResource())) yield - config_listener.remove_listener() router.remove(rules) From f0efc8ed153bbdea343275fc32e907d467575abf Mon Sep 17 00:00:00 2001 From: Alexander Rashed Date: Thu, 2 Nov 2023 11:30:07 +0100 Subject: [PATCH 2/2] fix tests using old (removed) endpoints --- tests/aws/services/ses/test_ses.py | 2 +- tests/integration/test_config_endpoint.py | 12 ------------ tests/unit/services/test_internal.py | 6 ------ 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/tests/aws/services/ses/test_ses.py b/tests/aws/services/ses/test_ses.py index 72a81b9d0ced75..d494db34ea7a95 100644 --- a/tests/aws/services/ses/test_ses.py +++ b/tests/aws/services/ses/test_ses.py @@ -957,7 +957,7 @@ def test_send_templated_email_can_retrospect(self, create_template, aws_client): assert '{"A key": "A value"}' == contents["TemplateData"] assert ["success@example.com"] == contents["Destination"]["ToAddresses"] - api_contents = requests.get("http://localhost:4566/_localstack/ses").json() + api_contents = requests.get("http://localhost:4566/_aws/ses").json() api_contents = {msg["Id"]: msg for msg in api_contents["messages"]} assert message_id in api_contents assert api_contents[message_id] == contents diff --git a/tests/integration/test_config_endpoint.py b/tests/integration/test_config_endpoint.py index f601e8d2479280..afc0ef18aa2207 100644 --- a/tests/integration/test_config_endpoint.py +++ b/tests/integration/test_config_endpoint.py @@ -2,7 +2,6 @@ import requests from localstack import config -from localstack.constants import CONFIG_UPDATE_PATH from localstack.http import Resource from localstack.services.internal import ConfigResource, get_internal_apis from localstack.utils import config_listener @@ -32,17 +31,6 @@ def custom_listener(config_key, config_value): config.FOO = None config_listener.CONFIG_LISTENERS.append(custom_listener) - # test the ProxyListener - body = {"variable": "FOO", "value": "BAR"} - url = f"{config.get_edge_url()}{CONFIG_UPDATE_PATH}" - response = requests.post(url, json=body) - assert 200 == response.status_code - response_body = response.json() - assert body == response_body - assert body["value"] == config.FOO - assert body["variable"] == key - assert body["value"] == value - # test the Route body = {"variable": "FOO", "value": "BAZ"} config_listener.CONFIG_LISTENERS.append(custom_listener) diff --git a/tests/unit/services/test_internal.py b/tests/unit/services/test_internal.py index 039e18c3c5de34..e735cca50724fa 100644 --- a/tests/unit/services/test_internal.py +++ b/tests/unit/services/test_internal.py @@ -83,12 +83,6 @@ def test_get(self): class TestLocalstackResourceHandlerIntegration: def test_health(self, monkeypatch): with proxy_server(LocalstackResourceHandler()) as url: - # legacy endpoint - response = requests.get(f"{url}/health") - assert response.ok - assert "services" in response.json() - - # new internal endpoint response = requests.get(f"{url}/_localstack/health") assert response.ok assert "services" in response.json()