src/pds_doi_service/api/__main__.py
def _check_referrer():
    """
    Checks the referrer header field of the current request to ensure it was
    sent by a valid endpoint. The list of valid referrers is defined by the
    DOI service INI config. If not valid referrers are defined by the config,
    this function will allow all requests through.

    Raises
    ------
    InvalidReferrer
        If no referrer is provided with the request, or the referrer is not
        within the list of valid hosts.

    Returns
    -------
    None if the referrer is valid (meaning the request should continue).

    """
    logger = logging.getLogger(__name__)
    config = DOIConfigUtil().get_config()

    referrer = connexion.request.referrer
    logger.debug("Referrer: %s", referrer)

    valid_referrers = config.get("OTHER", "api_valid_referrers", fallback=None)

    # if no valid referrers are configured, just return None to allow
    # request to go forward
    if not valid_referrers:
        return None

    valid_referrers = list(map(str.strip, valid_referrers.split(",")))
    logger.debug("Valid referrers: %s", valid_referrers)

    if not referrer:
        raise InvalidReferrer("No referrer specified from request")

    parsed_referrer = urlparse(referrer)

    if parsed_referrer.hostname not in valid_referrers and referrer not in valid_referrers:
        raise InvalidReferrer("Request referrer is not allowed access to the API", status_code=403)

    Checks the referrer header field of the current request to ensure it was
    sent by a valid endpoint. The list of valid referrers is defined by the
    DOI service INI config. If not valid referrers are defined by the config,
    this function will allow all requests through.

    Raises
    ------
    InvalidReferrer
        If no referrer is provided with the request, or the referrer is not
        within the list of valid hosts.

    Returns
    -------
    None if the referrer is valid (meaning the request should continue).

    
Checks the referrer header field of the current request to ensure it was
sent by a valid endpoint. The list of valid referrers is defined by the
DOI service INI config. If not valid referrers are defined by the config,
this function will allow all requests through.

Raises

InvalidReferrer
If no referrer is provided with the request, or the referrer is not
within the list of valid hosts.

Returns

None if the referrer is valid (meaning the request should continue).
Checks the referrer header field of the current request to ensure it was sent by a valid endpoint . The list of valid referrers is defined by the DOI service INI config . If not valid referrers are defined by the config this function will allow all requests through . Raises InvalidReferrer If no referrer is provided with the request or the referrer is not within the list of valid hosts . Returns None if the referrer is valid ( meaning the request should continue ) .
def _check_referrer():
    logger = logging.getLogger(__name__)
    config = DOIConfigUtil().get_config()
    referrer = connexion.request.referrer
    logger.debug("Referrer: %s", referrer)
    valid_referrers = config.get("OTHER", "api_valid_referrers", fallback=None)
    if not valid_referrers:
        return None
    valid_referrers = list(map(str.strip, valid_referrers.split(",")))
    logger.debug("Valid referrers: %s", valid_referrers)
    if not referrer:
        raise InvalidReferrer("No referrer specified from request")
    parsed_referrer = urlparse(referrer)
    if parsed_referrer.hostname not in valid_referrers and referrer not in valid_referrers:
        raise InvalidReferrer("Request referrer is not allowed access to the API", status_code=403)
def _check_referrer ( ) : logger = logging . getLogger ( __name__ ) config = DOIConfigUtil ( ) . get_config ( ) referrer = connexion . request . referrer logger . debug ( "Referrer: %s" , referrer ) valid_referrers = config . get ( "OTHER" , "api_valid_referrers" , fallback = None ) if not valid_referrers : return None valid_referrers = list ( map ( str . strip , valid_referrers . split ( "," ) ) ) logger . debug ( "Valid referrers: %s" , valid_referrers ) if not referrer : raise InvalidReferrer ( "No referrer specified from request" ) parsed_referrer = urlparse ( referrer ) if parsed_referrer . hostname not in valid_referrers and referrer not in valid_referrers : raise InvalidReferrer ( "Request referrer is not allowed access to the API" , status_code = 403 )
Checks the referrer header field of the current request to ensure it was
sent by a valid endpoint.
Checks the referrer header field of the current request to ensure it was sent by a valid endpoint .
"""
    Checks the referrer header field of the current request to ensure it was
    sent by a valid endpoint. The list of valid referrers is defined by the
    DOI service INI config. If not valid referrers are defined by the config,
    this function will allow all requests through.

    Raises
    ------
    InvalidReferrer
        If no referrer is provided with the request, or the referrer is not
        within the list of valid hosts.

    Returns
    -------
    None if the referrer is valid (meaning the request should continue).

    """ # if no valid referrers are configured, just return None to allow # request to go forward