
    "                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ dd	l	mZ dd
l	mZ ddl	mZ ddlmZ ddlmZ ddlmZ ddlmZ ej,                   G d dej.                               Zy)z0`gcloud domains registrations register` command.    )absolute_import)division)unicode_literals)registrations)base)contacts_util)dns_util)flags)resource_args)util)labels_util)
exceptions)log)
console_ioc                   ,    e Zd ZdZed        Zd Zd Zy)Registera  Register a new domain.

  Create a new Cloud Domains registration resource by registering a new domain.
  The new resource's ID will be equal to the domain name.

  After this command executes, the resource will be in state
  REGISTRATION_PENDING. The registration process should complete in less than 5
  minutes. After that the resource will be in state ACTIVE. In rare
  cases this process can take much longer due, for example, to a downtime of the
  domain registry.

  Also in rare cases, the domain may end up in state REGISTRATION_FAILED. In
  that case, delete the registration resource and try again.

  When using Cloud DNS Zone DNSSEC will be enabled by default whenever the Zone
  is DNSSEC signed. You can choose to not enable DNSSEC by using the
  --disable-dnssec flag.

  ## EXAMPLES

  To register ``example.com'' interactively, run:

    $ {command} example.com

  To register ``example.com'' using contact data from a YAML file
  ``contacts.yaml'', run:

    $ {command} example.com --contact-data-from-file=contacts.yaml

  To register ``example.com'' with interactive prompts disabled, provide
  --contact-data-from-file, --contact-privacy, --yearly-price flags and one of
  the flags for setting authoritative name servers. Sometimes also --notices
  flag is required. For example, run:

    $ {command} example.com --contact-data-from-file=contacts.yaml --contact-privacy=private-contact-data --yearly-price="12.00 USD" --cloud-dns-zone=example-com --quiet
  c                     t        j                  | dd       t        j                  |        t	        j
                  |        t        j                  | d       t        j                  |        y )NzThe domain namezto register)nounverbcreate)r   AddRegistrationResourceArgr
   AddRegisterFlagsToParserr   AddCreateLabelsFlagsAddValidateOnlyFlagToParserAddAsyncFlagToParser)parsers    -lib/surface/domains/registrations/register.pyArgszRegister.ArgsJ   sR    ,,&]<	""6*$$V,	%%fh7	v&    c                     |t        j                  d      dD ]7  }|j                  |      rt        j                  dj                  |             y )NzProviding contacts is required.)registrantContactadminContacttechnicalContactzProviding {} is required.)r   Errorget_assigned_valueformat)selfcontactsfields      r   _ValidateContactszRegister._ValidateContactsS   sP    >??J((/:AA%HII Kr   c                    t        j                  |      }t        j                  |      }|j                          t	        j
                  |j                        }||j                  k7  r:t        j                  dj                  |j                  |      ddd       ||_        |j                  j                  j                         }|j                         }|j                  ||j                        }|j                  j                   j"                  j$                  }|j&                  |k7  r9t)        j*                  dj                  |j                  |j&                              t-        j.                  ||j                  j0                  j2                        }	t4        j6                  j8                  }
|j:                  rt4        j6                  j<                  }
t5        j>                  ||j@                  |jB                  |jD                  d |j                  |
      \  }}tG        jH                  ||jJ                        }|r| jM                  |       tG        jN                  ||jP                        }t	        jR                  ||jT                        }t	        jV                  |jX                        \  }}|6t	        jZ                  |j\                        }|t)        j*                  d      t	        j^                  ||j\                        sUt)        j*                  dj                  t	        j`                  |      t	        j`                  |j\                                    |j                  j                   jb                  jd                  }||jf                  v r8|s6t	        jh                  |jj                        }|t)        j*                  d	      |<t5        jl                  ||j                  |
      \  }}|t)        j*                  d
      |&tG        jn                  |      }| jM                  |       |r|jp                  D cg c]0  }ts        jt                  |j                        jw                  |      2 }}tG        jx                  ||      }|t)        j*                  d      ||_=        |j                  j|                  j~                  j                  }|s<||k(  r7tG        j                  |jj                  |      }|t)        j*                  d	      |j                  ||j                  ||||||	|j                  	      }|j                  r!t        j                  j                  d       |S t	        j                  |||j                        }t        j                  |j                         d|j                  d       |S c c}w )Nz8Domain name '{}' has been normalized to equivalent '{}'.FT)throw_if_unattendedcancel_on_nodefaultz3Domain '{}' is not available for registration: '{}')dnssec_updatez#Accepting yearly price is required.z+Incorrect yearly_price: '{}', expected: {}.zAcceptance is required.z#Providing DNS settings is required.z&Providing Contact Privacy is required.)dns_settingscontact_settingsyearly_pricehsts_notice_acceptedpublic_privacy_acceptedlabelsvalidate_onlyzKThe command will not have any effect because validate-only flag is present.registrationzeNote:
The domain is not yet registered.
Wait until the registration resource changes state to ACTIVE.)details)Kr   GetApiVersionFromArgsRegistrationsClientPrintSQSPAckr   NormalizeResourceNamer7   r   PromptContinuer&   CONCEPTSParseParentRetrieveRegisterParametersregistrationsIdmessagesRegisterParametersAvailabilityValueValuesEnum	AVAILABLEavailabilityr   r$   r   ParseCreateArgsRegistrationLabelsValuer	   DNSSECUpdateENABLEdisable_dnssecDISABLEParseDNSSettingsname_serverscloud_dns_zoneuse_google_domains_dnsr   ParseContactDatacontact_data_from_filer*   ParseContactPrivacycontact_privacyParseYearlyPricer2   ParseRegisterNoticesnoticesPromptForYearlyPriceAckyearlyPrice
EqualPriceTransformMoneyType%DomainNoticesValueListEntryValuesEnumHSTS_PRELOADEDdomainNoticesPromptForHSTSAck
domainNamePromptForNameServersPromptForContactssupportedPrivacyr
   ContactPrivacyEnumMapperGetChoiceForEnumPromptForContactPrivacyprivacyContactSettingsPrivacyValueValuesEnumPUBLIC_CONTACT_DATAPromptForPublicContactsAckr   r6   r   statusPrintWaitForOperationasync_CreatedResourceName)r'   argsapi_versionclient
normalizedregistration_reflocation_refregister_paramsavailable_enumr5   r/   r0   _r(   rV   r2   public_contacts_ackhsts_ack	hsts_enumenumchoicespublic_privacy_enumresponses                          r   RunzRegister.Run[   s"   55d;K..{;F
++D,=,=>JT&&&
H
O
O-# %d}}11779#**,L 77&668O __77SS]]N##~5
C
J
J..0L0LNO O ((foo**668F ))00M++33m//##((#%OL! --k.2.I.IKH
X&#778<8L8LNO((d6G6GHL$($=$=dll$K!11/2M2MNl		DEE??<)D)DE
9
@
@%%l3%%o&A&ABDE E
 22XXggIO111(&&'A'ABh		899 55


*
*%'olA 
	DEE00=h
X& &666d 
(
(
9
J
J4
P6   &==
w o		 GHH&H //99PPdd?6I#I)DD

$
$h0		$899((!!!% 3((  	*H 	jj 8 9 O &&{HdkkJh	



!

++NP OSs   5W
N)__name__
__module____qualname____doc__staticmethodr   r*   r    r   r   r   r   "   s(    #J ' 'J~r   r   N)r   
__future__r   r   r   googlecloudsdk.api_lib.domainsr   googlecloudsdk.callioper   "googlecloudsdk.command_lib.domainsr   r	   r
   r   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   DefaultUniverseOnlyCreateCommandr   r   r   r   <module>r      s^    7 &  ' 8 ( < 7 4 < 3 < * # 2 vt!! v vr   