Ejemplo n.º 1
0
def create_hosted_zone(session: boto3.Session, domain_name: str) -> str:
    """
    Given a domain name, tries to create a hosted zone
    for that domain. Returns the hosted zone id
    """
    client = session.client("route53")

    zone_id = find_hosted_zone(session, domain_name)
    if zone_id is None:

        res = client.create_hosted_zone(
            Name=domain_name,
            CallerReference=str(time.time()),
            HostedZoneConfig={
                "Comment": "Mephisto hosted zone",
            },
        )
        nameservers = res["DelegationSet"]["NameServers"]
        BOLD_WHITE_ON_BLUE = "\x1b[1;37;44m"
        RESET = "\x1b[0m"
        print(f"{BOLD_WHITE_ON_BLUE}"
              "Registered new hosted zone! You should ensure your domain "
              "name is registered to delegate to the following nameservers: "
              f"\n{nameservers}"
              f"{RESET}")
        zone_id = res["HostedZone"]["Id"]
    else:
        logger.debug(f"This hosted zone already exists! Returning {zone_id}")

    return zone_id
Ejemplo n.º 2
0
def get_or_create_hosted_zone(client, zone_name):
    """Get the Id of an existing zone, or create it.

    Args:
        client (:class:`botocore.client.Route53`): The connection used to
            interact with Route53's API.
        zone_name (string): The name of the DNS hosted zone to create.

    Returns:
        string: The Id of the Hosted Zone.
    """
    zone_id = get_hosted_zone_by_name(client, zone_name)
    if zone_id:
        return zone_id

    logger.debug("Zone %s does not exist, creating.", zone_name)

    reference = uuid.uuid4().hex

    response = client.create_hosted_zone(Name=zone_name,
                                         CallerReference=reference)

    return parse_zone_id(response["HostedZone"]["Id"])
Ejemplo n.º 3
0
def get_or_create_hosted_zone(client, zone_name):
    """Get the Id of an existing zone, or create it.

    Args:
        client (:class:`botocore.client.Route53`): The connection used to
            interact with Route53's API.
        zone_name (string): The name of the DNS hosted zone to create.

    Returns:
        string: The Id of the Hosted Zone.
    """
    zone_id = get_hosted_zone_by_name(client, zone_name)
    if zone_id:
        return zone_id

    logger.debug("Zone %s does not exist, creating.", zone_name)

    reference = uuid.uuid4().hex

    response = client.create_hosted_zone(Name=zone_name,
                                         CallerReference=reference)

    return parse_zone_id(response["HostedZone"]["Id"])
Ejemplo n.º 4
0
def get_or_create_hosted_zone(client: Route53Client, zone_name: str) -> str:
    """Get the Id of an existing zone, or create it.

    Args:
        client: The connection used to interact with Route53's API.
        zone_name: The name of the DNS hosted zone to create.

    Returns:
        The Id of the Hosted Zone.

    """
    zone_id = get_hosted_zone_by_name(client, zone_name)
    if zone_id:
        return zone_id

    LOGGER.debug("zone %s does not exist; creating", zone_name)

    reference = uuid.uuid4().hex

    response = client.create_hosted_zone(Name=zone_name,
                                         CallerReference=reference)

    return parse_zone_id(response["HostedZone"]["Id"])