Skip to content
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
16 changes: 14 additions & 2 deletions ddtrace/appsec/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,26 @@ def __init__(
self.location = location.replace(APPSEC.SECURITY_RESPONSE_ID, security_response_id)
self.content_type: str = "application/json"

def get(self, method_name: str, default: Any = None) -> Any:
def get(self, key: str, default: Any = None) -> Union[str, int]:
"""
Dictionary-like get method for backward compatibility with Lambda integration.

Returns the attribute value if it exists, otherwise returns the default value.
This allows Block_config to be used in contexts that expect dictionary-like access.
"""
return getattr(self, method_name, default)
if key == "content-type":
key = "content_type"
return getattr(self, key, default)

def __getitem__(self, key: str) -> Optional[Union[str, int]]:
if key == "content-type":
key = "content_type"
return getattr(self, key, None)

def __contains__(self, key: str) -> bool:
if key == "content-type":
key = "content_type"
return bool(getattr(self, key, None))


class Telemetry_result:
Expand Down
6 changes: 6 additions & 0 deletions ddtrace/internal/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class Block_config(Protocol):
location: str
content_type: str

def get(self, key: str, default: Any = None) -> Union[str, int]: ...

def __getitem__(self, key: str) -> Optional[Union[str, int]]: ...

def __contains__(self, key: str) -> bool: ...


def get_blocked() -> Optional[Block_config]:
# local import to avoid circular dependency
Expand Down
Loading