Module astrapy.admin.endpoints

Functions

def api_endpoint_parsing_cdinfo_message(failing_url: str) ‑> str
Expand source code
def api_endpoint_parsing_cdinfo_message(failing_url: str) -> str:
    """
    Format a warning message about a possibly-custom-domain API endpoint.
    """
    return (
        f"An API endpoint was supplied ({failing_url}) that does not conform to the "
        f'standard form ("{api_endpoint_description}"). It will be assumed that this '
        "is intentional, i.e. that the desired API endpoint is a 'Custom Domain'."
    )

Format a warning message about a possibly-custom-domain API endpoint.

def api_endpoint_parsing_error_message(failing_url: str) ‑> str
Expand source code
def api_endpoint_parsing_error_message(failing_url: str) -> str:
    """
    Format an error message with a suggestion for the expected url format.
    """
    return (
        f"Cannot parse the supplied API endpoint ({failing_url}). The endpoint "
        f'must be in the following form: "{api_endpoint_description}".'
    )

Format an error message with a suggestion for the expected url format.

def build_api_endpoint(environment: str, database_id: str, region: str) ‑> str
Expand source code
def build_api_endpoint(environment: str, database_id: str, region: str) -> str:
    """
    Build the API Endpoint full strings from database parameters.

    Args:
        environment: a label, whose value can be Environment.PROD
            or another of Environment.* for which this operation makes sense.
        database_id: e. g. "01234567-89ab-cdef-0123-456789abcdef".
        region: a region ID, such as "us-west1".

    Returns:
        the endpoint string, such as "https://01234567-...-eu-west1.apps.datastax.com"
    """

    return API_ENDPOINT_TEMPLATE_ENV_MAP[environment].format(
        database_id=database_id,
        region=region,
    )

Build the API Endpoint full strings from database parameters.

Args

environment
a label, whose value can be Environment.PROD or another of Environment.* for which this operation makes sense.
database_id
e. g. "01234567-89ab-cdef-0123-456789abcdef".
region
a region ID, such as "us-west1".

Returns

the endpoint string, such as "https://01234567-…-eu-west1.apps.datastax.com"

def generic_api_url_parsing_error_message(failing_url: str) ‑> str
Expand source code
def generic_api_url_parsing_error_message(failing_url: str) -> str:
    """
    Format an error message with a suggestion for the expected url format.
    """
    return (
        f"Cannot parse the supplied API endpoint ({failing_url}). The endpoint "
        f'must be in the following form: "{generic_api_url_descriptor}".'
    )

Format an error message with a suggestion for the expected url format.

def parse_api_endpoint(api_endpoint: str) ‑> ParsedAPIEndpoint | None
Expand source code
def parse_api_endpoint(api_endpoint: str) -> ParsedAPIEndpoint | None:
    """
    Parse an API Endpoint into a ParsedAPIEndpoint structure.

    Args:
        api_endpoint: a full API endpoint for the Data API.

    Returns:
        The parsed ParsedAPIEndpoint. If parsing fails, return None.
    """

    match = api_endpoint_parser.match(api_endpoint)
    if match and match.groups():
        d_id, d_re, d_en_x = match.groups()
        return ParsedAPIEndpoint(
            database_id=d_id,
            region=d_re,
            environment=d_en_x if d_en_x else "prod",
        )
    else:
        return None

Parse an API Endpoint into a ParsedAPIEndpoint structure.

Args

api_endpoint
a full API endpoint for the Data API.

Returns

The parsed ParsedAPIEndpoint. If parsing fails, return None.

def parse_generic_api_url(api_endpoint: str) ‑> str | None
Expand source code
def parse_generic_api_url(api_endpoint: str) -> str | None:
    """
    Validate a generic API Endpoint string,
    such as `http://10.1.1.1:123` or `https://my.domain`.

    Args:
        api_endpoint: a string supposedly expressing a valid API Endpoint
        (not necessarily an Astra DB one).

    Returns:
        a normalized (stripped) version of the endpoint if valid. If invalid,
        return None.
    """
    if api_endpoint and api_endpoint[-1] == "/":
        _api_endpoint = api_endpoint[:-1]
    else:
        _api_endpoint = api_endpoint
    match = generic_api_url_matcher.match(_api_endpoint)
    if match:
        return match[0].rstrip("/")
    else:
        return None

Validate a generic API Endpoint string, such as http://10.1.1.1:123 or https://my.domain.

Args

api_endpoint
a string supposedly expressing a valid API Endpoint

(not necessarily an Astra DB one).

Returns

a normalized (stripped) version of the endpoint if valid. If invalid, return None.

Classes

class ParsedAPIEndpoint (database_id: str, region: str, environment: str)
Expand source code
@dataclass
class ParsedAPIEndpoint:
    """
    The results of successfully parsing an Astra DB API endpoint, for internal
    by database metadata-related functions.

    Attributes:
        database_id: e. g. "01234567-89ab-cdef-0123-456789abcdef".
        region: a region ID, such as "us-west1".
        environment: a label, whose value is one of Environment.PROD,
            Environment.DEV or Environment.TEST.
    """

    database_id: str
    region: str
    environment: str

The results of successfully parsing an Astra DB API endpoint, for internal by database metadata-related functions.

Attributes

database_id
e. g. "01234567-89ab-cdef-0123-456789abcdef".
region
a region ID, such as "us-west1".
environment
a label, whose value is one of Environment.PROD, Environment.DEV or Environment.TEST.

Instance variables

var database_id : str

The type of the None singleton.

var environment : str

The type of the None singleton.

var region : str

The type of the None singleton.