Beispiel #1
0
def _PromptForSingleContact(unused_current_contact=None):
    """Asks a user for a single contact data."""
    messages = registrations.GetMessagesModule()

    contact = messages.Contact()
    contact.postalAddress = messages.PostalAddress()

    # TODO(b/166210862): Use defaults from current_contact.
    #                      But then: How to clear a value?
    # TODO(b/166210862): Better validation: Call validate_only after each prompt.
    contact.postalAddress.recipients.append(
        util.PromptWithValidator(validator=util.ValidateNonEmpty,
                                 error_message=' Name must not be empty.',
                                 prompt_string='Full name:  '))
    contact.postalAddress.organization = console_io.PromptResponse(
        'Organization (if applicable):  ')
    contact.email = util.PromptWithValidator(
        validator=util.ValidateEmail,
        error_message=' Invalid email address.',
        prompt_string='Email',
        default=properties.VALUES.core.account.Get())
    contact.phoneNumber = util.PromptWithValidator(
        validator=util.ValidateNonEmpty,
        error_message=' Phone number must not be empty.',
        prompt_string='Phone number:  ',
        message='Enter phone number with country code, e.g. "+1.8005550123".')
    contact.faxNumber = util.Prompt(
        prompt_string='Fax number (if applicable):  ',
        message='Enter fax number with country code, e.g. "+1.8005550123".')
    contact.postalAddress.regionCode = util.PromptWithValidator(
        validator=util.ValidateRegionCode,
        error_message=
        (' Country code must be in ISO 3166-1 format, e.g. "US" or "PL".\n'
         ' See https://support.google.com/business/answer/6270107 for a list '
         'of valid choices.'),
        prompt_string='Country code:  ',
        message='Enter two-letter country code, e.g. "US" or "PL".')
    contact.postalAddress.postalCode = console_io.PromptResponse(
        'Postal code/zipcode:  ')
    contact.postalAddress.administrativeArea = console_io.PromptResponse(
        'State (if applicable):  ')
    contact.postalAddress.locality = console_io.PromptResponse('City:  ')
    contact.postalAddress.addressLines.append(
        console_io.PromptResponse('Street address (incl. building, apt):  '))
    return contact
Beispiel #2
0
def PromptForNameServers(domain,
                         enable_dnssec=None,
                         dns_settings=None,
                         print_format='default'):
    """Asks the user to provide DNS settings interactively.

  Args:
    domain: Domain name corresponding to the DNS settings.
    enable_dnssec: Should the DNSSEC be enabled.
    dns_settings: Current DNS configuration (or None if resource is not yet
      created).
    print_format: Print format to use when showing current dns_settings.

  Returns:
    A pair: (messages.DnsSettings, DnsUpdateMask) to be updated, or (None, None)
    if the user cancelled.
  """
    options = [
        'Provide name servers list', 'Provide Cloud DNS Managed Zone name',
        'Use free name servers provided by Google Domains'
    ]
    if dns_settings is not None:
        log.status.Print('Your current DNS settings are:')
        resource_printer.Print(dns_settings, print_format, out=sys.stderr)

        cancel_option = True
        default = len(options)  # Additional 'cancel' option.
    else:
        cancel_option = False
        default = 1  # Cloud DNS Zone.

    message = ('You can provide your DNS settings by specifying name servers, '
               'Cloud DNS Managed Zone name or by choosing '
               'free name servers provided by Google Domains')
    index = console_io.PromptChoice(message=message,
                                    options=options,
                                    cancel_option=cancel_option,
                                    default=default)
    name_servers = []
    if index == 0:  # name servers.
        while len(name_servers) < 2:
            while True:
                ns = console_io.PromptResponse(
                    'Name server (empty line to finish):  ')
                if not ns:
                    break
                if not util.ValidateDomainName(ns):
                    log.status.Print('Invalid name server: \'{}\'.'.format(ns))
                else:
                    name_servers += [ns]
            if len(name_servers) < 2:
                log.status.Print(
                    'You have to provide at least 2 name servers.')
        return _CustomNameServers(name_servers)
    elif index == 1:  # Cloud DNS.
        while True:
            zone = util.PromptWithValidator(
                validator=util.ValidateNonEmpty,
                error_message=' Cloud DNS Managed Zone name must not be empty.',
                prompt_string='Cloud DNS Managed Zone name:  ')
            try:
                name_servers, ds_records = _GetCloudDnsDetails(
                    zone, domain, enable_dnssec)
            except (exceptions.Error, calliope_exceptions.HttpException) as e:
                log.status.Print(six.text_type(e))
            else:
                break
        return _CustomNameServers(name_servers, ds_records)
    elif index == 2:  # Google Domains name servers.
        return _GoogleDomainsNameServers(enable_dnssec)
    else:
        return None, None  # Cancel.
def _PromptForSingleContact(domains_messages, unused_current_contact=None):
    """Asks a user for a single contact data."""
    contact = domains_messages.Contact()
    contact.postalAddress = domains_messages.PostalAddress()

    # TODO(b/166210862): Use defaults from current_contact.
    #                      But then: How to clear a value?
    # TODO(b/166210862): Better validation: Call validate_only after each prompt.
    contact.postalAddress.recipients.append(
        util.PromptWithValidator(validator=util.ValidateNonEmpty,
                                 error_message=' Name must not be empty.',
                                 prompt_string='Full name:  '))
    contact.postalAddress.organization = console_io.PromptResponse(
        'Organization (if applicable):  ')
    contact.email = util.PromptWithValidator(
        validator=util.ValidateEmail,
        error_message=' Invalid email address.',
        prompt_string='Email',
        default=properties.VALUES.core.account.Get())
    contact.phoneNumber = util.PromptWithValidator(
        validator=util.ValidateNonEmpty,
        error_message=' Phone number must not be empty.',
        prompt_string='Phone number:  ',
        message='Enter phone number with country code, e.g. "+1.8005550123".')
    contact.faxNumber = util.Prompt(
        prompt_string='Fax number (if applicable):  ',
        message='Enter fax number with country code, e.g. "+1.8005550123".')
    contact.postalAddress.regionCode = util.PromptWithValidator(
        validator=util.ValidateRegionCode,
        error_message=
        (' Country / Region code must be in ISO 3166-1 format, e.g. "US" or '
         '"PL".\n See https://support.google.com/business/answer/6270107 for a'
         ' list of valid choices.'),
        prompt_string='Country / Region code:  ',
        message='Enter two-letter Country / Region code, e.g. "US" or "PL".')
    if contact.postalAddress.regionCode != 'US':
        log.status.Print('Refer to the guidelines for entering address field '
                         'information at '
                         'https://support.google.com/business/answer/6397478.')
    contact.postalAddress.postalCode = console_io.PromptResponse(
        'Postal / ZIP code:  ')
    contact.postalAddress.administrativeArea = console_io.PromptResponse(
        'State / Administrative area (if applicable):  ')
    contact.postalAddress.locality = console_io.PromptResponse(
        'City / Locality:  ')
    contact.postalAddress.addressLines.append(
        util.PromptWithValidator(
            validator=util.ValidateNonEmpty,
            error_message=' Address Line 1 must not be empty.',
            prompt_string='Address Line 1:  '))

    optional_address_lines = []
    address_line_num = 2
    while len(optional_address_lines) < 4:
        address_line_num = 2 + len(optional_address_lines)
        address_line = console_io.PromptResponse(
            'Address Line {} (if applicable):  '.format(address_line_num))
        if not address_line:
            break
        optional_address_lines += [address_line]

    if optional_address_lines:
        contact.postalAddress.addressLines.extend(optional_address_lines)
    return contact
def PromptForNameServersTransfer(api_version, domain):
    """Asks the user to provide DNS settings interactively for Transfers.

  Args:
    api_version: Cloud Domains API version to call.
    domain: Domain name corresponding to the DNS settings.

  Returns:
    A triple: (messages.DnsSettings, DnsUpdateMask, _) to be updated, or
    (None, None, _) if the user cancelled. The third value returns true when
    keeping the current DNS settings during Transfer.
  """
    domains_messages = registrations.GetMessagesModule(api_version)
    options = [
        'Provide Cloud DNS Managed Zone name',
        'Use free name servers provided by Google Domains',
        'Keep current DNS settings from current registrar'
    ]
    message = (
        'You can provide your DNS settings in one of several ways:\n'
        'You can specify a Cloud DNS Managed Zone name. To avoid '
        'downtime following transfer, make sure the zone is configured '
        'correctly before proceeding.\n'
        'You can select free name servers provided by Google Domains. '
        'This blank-slate option cannot be configured before transfer.\n'
        'You can also choose to keep the domain\'s DNS settings '
        'from its current registrar. Use this option only if you are '
        'sure that the domain\'s current DNS service will not cease upon '
        'transfer, as is often the case for DNS services provided for '
        'free by the registrar.')

    cancel_option = False
    default = 2  # Keep current DNS settings.
    enable_dnssec = False

    index = console_io.PromptChoice(message=message,
                                    options=options,
                                    cancel_option=cancel_option,
                                    default=default)
    if index == 0:  # Cloud DNS.
        while True:
            zone = util.PromptWithValidator(
                validator=util.ValidateNonEmpty,
                error_message=' Cloud DNS Managed Zone name must not be empty.',
                prompt_string='Cloud DNS Managed Zone name:  ')
            try:
                name_servers, ds_records = _GetCloudDnsDetails(
                    domains_messages, zone, domain, enable_dnssec)
            except (exceptions.Error, calliope_exceptions.HttpException) as e:
                log.status.Print(six.text_type(e))
            else:
                break
        dns_settings, update_mask = _CustomNameServers(domains_messages,
                                                       name_servers,
                                                       ds_records)
        return dns_settings, update_mask, False
    elif index == 1:  # Google Domains name servers.
        dns_settings, update_mask = _GoogleDomainsNameServers(
            domains_messages, enable_dnssec)
        return dns_settings, update_mask, False
    else:  # Keep current DNS settings (Transfer).
        return None, None, True