Skip to content

Commit

Permalink
feat: refactor API key validation logic; use class variable for regex…
Browse files Browse the repository at this point in the history
… pattern matching
  • Loading branch information
Hiran committed Jan 2, 2025
1 parent ae85ed5 commit e6e96f0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions log_redactor/redactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Redactor:
)

# API key pattern - matches key/value pairs like apikey=xyz, token=abc, key=123
API_KEY_PATTERN: ClassVar[Pattern] = compile(
API_KEY_PATTERN: ClassVar[Pattern] = re.compile(
r"\b(?:apikey|token|key|apitoken)=\w+\b",
IGNORECASE
)
Expand Down Expand Up @@ -349,9 +349,9 @@ def is_valid_phone(phone: str) -> bool:
return any(pattern.match(phone) for pattern in Redactor.VALID_PHONE_PATTERNS)

@staticmethod
def is_valid_api_key(self, key: str) -> bool:
def is_valid_api_key(key: str) -> bool:
"""Validate API key using precompiled patterns."""
return any(pattern.match(key) for pattern in self.API_KEY_PATTERNS)
return Redactor.API_KEY_PATTERN.match(key) is not None

def _generate_unique_email(self) -> str:
"""Generate a unique redacted email address."""
Expand Down

0 comments on commit e6e96f0

Please sign in to comment.