8000 Remove legacy internal call detection helper by viren-nadkarni · Pull Request #9616 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Remove legacy internal call detection helper #9616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions localstack/aws/handlers/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
ServiceRequestAggregator,
ServiceRequestInfo,
)
from localstack.utils.aws.aws_stack import is_internal_call_context

LOG = logging.getLogger(__name__)

Expand All @@ -29,7 +28,7 @@ def __call__(self, chain: HandlerChain, context: RequestContext, response: Respo
return
if config.DISABLE_EVENTS:
return
if is_internal_call_context(context.request.headers):
if context.is_internal_call:
# don't count internal requests
return

Expand Down
6 changes: 1 addition & 5 deletions localstack/aws/handlers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from localstack.http.request import restore_payload
from localstack.logging.format import AwsTraceLoggingFormatter, TraceLoggingFormatter
from localstack.logging.setup import create_default_handler
from localstack.utils.aws.aws_stack import is_internal_call_context

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -82,10 +81,7 @@ def _prepare_logger(self, logger: logging.Logger, formatter: Type):
def _log(self, context: RequestContext, response: Response):
aws_logger = self.aws_logger
http_logger = self.http_logger
is_internal_call = (
is_internal_call_context(context.request.headers) or context.is_internal_call
)
if is_internal_call:
if context.is_internal_call:
aws_logger = self.internal_aws_logger
http_logger = self.internal_http_logger
if context.operation:
Expand Down
4 changes: 1 addition & 3 deletions localstack/aws/handlers/metric_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from localstack.aws.api import RequestContext
from localstack.aws.chain import HandlerChain
from localstack.http import Response
from localstack.utils.aws.aws_stack import is_internal_call_context

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -175,7 +174,6 @@ def update_metric_collection(
if not config.is_collect_metrics_mode() or not context.service_operation:
return

is_internal = is_internal_call_context(context.request.headers)
item = self._get_metric_handler_item_for_context(context)

# parameters might get changed when dispatched to the service - we use the params stored in
Expand All @@ -193,7 +191,7 @@ def update_metric_collection(
exception=context.service_exception.__class__.__name__
if context.service_exception
else "",
origin="internal" if is_internal else "external",
origin="internal" if context.is_internal_call else "external",
)
# refrain from adding duplicates
if metric not in MetricHandler.metric_data:
Expand Down
5 changes: 1 addition & 4 deletions localstack/aws/handlers/partition_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from localstack.http.proxy import forward
from localstack.http.request import Request, get_full_raw_path, get_raw_path, restore_payload
from localstack.utils.aws.aws_responses import calculate_crc32
from localstack.utils.aws.aws_stack import is_internal_call_context
from localstack.utils.aws.request_context import extract_region_from_headers
from localstack.utils.run import to_str
from localstack.utils.strings import to_bytes
Expand Down Expand Up @@ -88,9 +87,7 @@ def __call__(self, chain: HandlerChain, context: RequestContext, response: Respo
# get arn rewriting mode from header
# not yet used but would allow manual override (e.g. for testing)
rewrite_mode = request.headers.pop("LS-INTERNAL-REWRITE-MODE", None)
if rewrite_mode is None and (
context.is_internal_call or is_internal_call_context(request.headers)
):
if rewrite_mode is None and context.is_internal_call:
# default internal mode
rewrite_mode = "internal-guard"
else:
Expand Down
15 changes: 0 additions & 15 deletions localstack/utils/aws/aws_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
AWS_REGION_US_EAST_1,
ENV_DEV,
HEADER_LOCALSTACK_ACCOUNT_ID,
INTERNAL_AWS_ACCESS_KEY_ID,
LOCALHOST,
REGION_LOCAL,
)
Expand Down Expand Up @@ -163,20 +162,6 @@ def get_boto3_region() -> str:
return boto3.session.Session().region_name


# TODO: remove this and use the `is_internal_call` property of RequestContext
def is_internal_call_context(headers) -> bool:
"""Return whether we are executing in the context of an internal API call, i.e.,
the case where one API uses a boto3 client to call another API internally."""
if HEADER_LOCALSTACK_ACCOUNT_ID in headers.keys():
# TODO: Used by the old client, marked for removal
return True

if INTERNAL_AWS_ACCESS_KEY_ID in headers.get("Authorization", ""):
return True

return False


def get_local_service_url(service_name_or_port: Union[str, int]) -> str:
"""Return the local service URL for the given service name or port."""
if isinstance(service_name_or_port, int):
Expand Down
0