8000 Remove legacy internal call detection helper (#9616) · codeperl/localstack@e18c518 · GitHub
[go: up one dir, main page]

Skip to content

Commit e18c518

Browse files
Remove legacy internal call detection helper (localstack#9616)
1 parent 218e855 commit e18c518

File tree

5 files changed

+4
-29
lines changed

5 files changed

+4
-29
lines changed

localstack/aws/handlers/analytics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
ServiceRequestAggregator,
1212
ServiceRequestInfo,
1313
)
14-
from localstack.utils.aws.aws_stack import is_internal_call_context
1514

1615
LOG = logging.getLogger(__name__)
1716

@@ -29,7 +28,7 @@ def __call__(self, chain: HandlerChain, context: RequestContext, response: Respo
2928
return
3029
if config.DISABLE_EVENTS:
3130
return
32-
if is_internal_call_context(context.request.headers):
31+
if context.is_internal_call:
3332
# don't count internal requests
3433
return
3534

localstack/aws/handlers/logging.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from localstack.http.request import restore_payload
1010
from localstack.logging.format import AwsTraceLoggingFormatter, TraceLoggingFormatter
1111
from localstack.logging.setup import create_default_handler
12-
from localstack.utils.aws.aws_stack import is_internal_call_context
1312

1413
LOG = logging.getLogger(__name__)
1514

@@ -82,10 +81,7 @@ def _prepare_logger(self, logger: logging.Logger, formatter: Type):
8281
def _log(self, context: RequestContext, response: Response):
8382
aws_logger = self.aws_logger
8483
http_logger = self.http_logger
85-
is_internal_call = (
86-
is_internal_call_context(context.request.headers) or context.is_internal_call
87-
)
88-
if is_internal_call:
84+
if context.is_internal_call:
8985
aws_logger = self.internal_aws_logger
9086
http_logger = self.internal_http_logger
9187
if context.operation:

localstack/aws/handlers/metric_handler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from localstack.aws.api import RequestContext
66
from localstack.aws.chain import HandlerChain
77
from localstack.http import Response
8-
from localstack.utils.aws.aws_stack import is_internal_call_context
98

109
LOG = logging.getLogger(__name__)
1110

@@ -175,7 +174,6 @@ def update_metric_collection(
175174
if not config.is_collect_metrics_mode() or not context.service_operation:
176175
return
177176

178-
is_internal = is_internal_call_context(context.request.headers)
179177
item = self._get_metric_handler_item_for_context(context)
180178

181179
# parameters might get changed when dispatched to the service - we use the params stored in
@@ -193,7 +191,7 @@ def update_metric_collection(
193191
exception=context.service_exception.__class__.__name__
194192
if context.service_exception
195193
else "",
196-
origin="internal" if is_internal else "external",
194+
origin="internal" if context.is_internal_call else "external",
197195
)
198196
# refrain from adding duplicates
199197
if metric not in MetricHandler.metric_data:

localstack/aws/handlers/partition_rewriter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from localstack.http.proxy import forward
1414
from localstack.http.request import Request, get_full_raw_path, get_raw_path, restore_payload
1515
from localstack.utils.aws.aws_responses import calculate_crc32
16-
from localstack.utils.aws.aws_stack import is_internal_call_context
1716
from localstack.utils.aws.request_context import extract_region_from_headers
1817
from localstack.utils.run import to_str
1918
from localstack.utils.strings import to_bytes
@@ -88,9 +87,7 @@ def __call__(self, chain: HandlerChain, context: RequestContext, response: Respo
8887
# get arn rewriting mode from header
8988
# not yet used but would allow manual override (e.g. for testing)
9089
rewrite_mode = request.headers.pop("LS-INTERNAL-REWRITE-MODE", None)
91-
if rewrite_mode is None and (
92-
context.is_internal_call or is_internal_call_context(request.headers)
93-
):
90+
if rewrite_mode is None and context.is_internal_call:
9491
# default internal mode
9592
rewrite_mode = "internal-guard"
9693
else:

localstack/utils/aws/aws_stack.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
AWS_REGION_US_EAST_1,
1919
ENV_DEV,
2020
HEADER_LOCALSTACK_ACCOUNT_ID,
21-
INTERNAL_AWS_ACCESS_KEY_ID,
2221
LOCALHOST,
2322
REGION_LOCAL,
2423
)
@@ -163,20 +162,6 @@ def get_boto3_region() -> str:
163162
return boto3.session.Session().region_name
164163

165164

166-
# TODO: remove this and use the `is_internal_call` property of RequestContext
167-
def is_internal_call_context(headers) -> bool:
168-
"""Return whether we are executing in the context of an internal API call, i.e.,
169-
the case where one API uses a boto3 client to call another API internally."""
170-
if HEADER_LOCALSTACK_ACCOUNT_ID in headers.keys():
171-
# TODO: Used by the old client, marked for removal
172-
return True
173-
174-
if INTERNAL_AWS_ACCESS_KEY_ID in headers.get("Authorization", ""):
175-
return True
176-
177-
return False
178-
179-
180165
def get_local_service_url(service_name_or_port: Union[str, int]) -> str:
181166
"""Return the local service URL for the given service name or port."""
182167
if isinstance(service_name_or_port, int):

0 commit comments

Comments
 (0)
0