Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Validation utils

Imports

Python modules

import logging
import re

Logger

logger = logging.getLogger("newrelic_sb_sdk")

Constants

USER_KEY_PATTERN

Regular expression pattern that validates New Relic API keys.

USER_KEY_PATTERN: re.Pattern = re.compile("NRAK-[A-Z0-9]{27}")

Functions

validate_user_key

Helper function to systematically validate any incoming New Relic Key against our pre- defined format.

def validate_user_key(user_key: str) -> bool:
    """Validate a New Relic user key against target signatures.

    Args:
        user_key: The string API key.

    Returns:
        True if the format matches standard configurations, False otherwise.
    """

    match: re.Match[str] | None = re.match(USER_KEY_PATTERN, user_key)

    return bool(match)