
    I                        S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr	  SSK
Jr  SSKJr  SS	KJr  SSKJr  SSKJr  SSKJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKr\R8                   " S S\R:                  5      5       r " S S\5      r \RB                  S4S jr"SS jr# SS jr$S r% SS jr&S r'S r(\RB                  SS4S jr)S r*S r+S r,S r-g) z(DNS utilties for Cloud Domains commands.    )absolute_import)division)unicode_literalsN)
exceptions)util)registrations)apis)log)
properties)
console_io)resource_printerc                   ~    \ rS rSrSr\R                  " 5       r\R                  " 5       r\R                  " 5       r	Sr
g)DNSSECUpdate'   zDNSSEC update options. N)__name__
__module____qualname____firstlineno____doc__enumautoENABLEDISABLE	NO_CHANGE__static_attributes__r       2lib/googlecloudsdk/command_lib/domains/dns_util.pyr   r   '   s&    99;&IIK'iik)r   r   c                   *    \ rS rSrSr    SS jrSrg)DnsUpdateMask/   zEClass with information which parts of dns_settings should be updated.c                 4    Xl         X l        X0l        X@l        g N)name_serversglue_recordsgoogle_domains_dnsseccustom_dnssec)selfr$   r%   r&   r'   s        r   __init__DnsUpdateMask.__init__2   s    
 %$!6&r   )r'   r%   r&   r$   N)FFFF)r   r   r   r   r   r)   r   r   r   r   r    r    /   s    M "!%*"	'r   r    c                    [         R                  " U 5      nUb  [        X5      $ Ub  [        UX%Xg5      u  p[        XU
5      $ U(       a  [	        XU5      $ Ub  [        X5      $ Ub  U[        R                  :X  a  [        X5      $ g)a  Parses DNS settings from a flag.

At most one of the arguments (except domain) should be non-empty.

Args:
  api_version: Cloud Domains API version to call.
  name_servers: List of name servers
  cloud_dns_zone: Cloud DNS Zone name
  use_google_domains_dns: Information that Google Domains name servers should
    be used.
  dns_settings_from_file: Path to a yaml file with dns_settings.
  domain: Domain name corresponding to the DNS settings.
  dnssec_update: DNSSECUpdate operation.
  dns_settings: Current DNS settings. Used during Configure DNS only.

Returns:
  A pair: (messages.DnsSettings, DnsUpdateMask) to be updated, or (None, None)
  if all the arguments are empty.
NN)	r   GetMessagesModule_CustomNameServers_GetCloudDnsDetails_GoogleDomainsNameServers_ParseDnsSettingsFromFiler   r   _DisableDnssec)api_versionr$   cloud_dns_zoneuse_google_domains_dnsdns_settings_from_filedomaindnssec_updatedns_settingsdomains_messagesnameservers
ds_recordss              r   ParseDNSSettingsr=   =   s    6 #44[A.==12B2@2?OK .ZHH$  '$%5NN-<3G3G"G*99	r   c                 T   U(       d  / n[        [        [        R                  U5      5      n[	        X5       HE  u  pE[        R
                  " U5      (       a  M"  [        R                  " SR                  U5      5      e   [        SSS9nU R                  U R                  X2S9S9nXv4$ )z?Validates name servers and returns (dns_settings, update_mask).Invalid name server: '{}'.T)r$   r'   )nameServers	dsRecords	customDns)listmapr   NormalizeDomainNamezipValidateDomainNamer   Errorformatr    DnsSettings	CustomDns)r:   r$   r<   normalized_name_serversns
normalizedupdate_maskr9   s           r   r.   r.   k   s    	J T%=%=|!LMLBnb"":..;BB2FGG C 4tD+!-- **- + E . F, 
	""r   c                 r   [        SSS9nU R                  R                  R                  nU[        R
                  :X  a!  U R                  R                  R                  nO:U[        R                  :X  a&  Ub#  UR                  b  UR                  R                  nU R                  U R                  US9S9nX#4$ )zKEnable Google Domains name servers and returns (dns_settings, update_mask).T)r$   r&   dsStategoogleDomainsDns)r    GoogleDomainsDnsDsStateValueValuesEnumDS_RECORDS_UNPUBLISHEDr   r   DS_RECORDS_PUBLISHEDr   rU   rS   rK   )r:   r8   r9   rP   ds_states        r   r0   r0   z   s     4tL+''>>  l)))))@@		  ... L$A$A$M..66h!--'888J . L,		""r   c                 ,   [         R                  " XR                  SR                  U5      5      nU(       d  gSnUR                  b  [        SSSS9nX#4$ UR                  b  [        SSSS9nX#4$ [        R                  " SR                  U5      5      e)zParses dns_settings from a yaml file.

Args:
  domains_messages: Cloud Domains messages module.
  path: YAML file path.

Returns:
  Pair (DnsSettings, DnsUpdateMask) or (None, None) if path is None.
zBDNS settings file '{}' does not contain valid dns_settings messager,   NT)r$   r&   r%   )r$   r'   r%   z5dnsProvider is not present in DNS settings file '{}'.)	r   ParseMessageFromYamlFilerK   rJ   rU   r    rC   r   rI   )r:   pathr9   rP   s       r   r1   r1      s     ..
((Lvd|, 
+"".DJK 
	"" )DBK 
	"" 

AHHNP Pr   c                    Sn[         R                  " SU5      nUR                  n[        R                  " U5      R                  US[        R                  R                  R                  R                  0SS9n UR                  R                  UR                  UR                  UR                  S95      n	US-   nU	R&                  U:w  a0  [(        R*                  " S	R-                  U	R&                  X5      5      eU	R.                  UR0                  R2                  R4                  :w  a%  [(        R*                  " S
R-                  U5      5      eU[6        R8                  :X  a  U	R:                  / 4$ U[6        R<                  :X  a  Ubo  UR>                  bb  [A        UR>                  R:                  5      [A        U	R:                  5      :X  a,  UR>                  R:                  UR>                  RB                  4$ U	R:                  / 4$ URD                  RF                  RH                  nU	RJ                  (       a  U	RJ                  RL                  U:w  a<  [N        RP                  RS                  SR-                  U5      5        U	R:                  / 4$  / nURU                  UR                  UR                  S9n URV                  RY                  U5      nXRV                  -  nURZ                  Ul.        URZ                  (       d  OMN  [_        XW5      nU(       d<  [N        RP                  RS                  SR-                  U5      5        U	R:                  / 4$ U	R:                  U4$ ! [        R                    a  n
["        R$                  " U
5      eSn
A
ff = f! [        R                    a8  n
[N        RP                  RS                  SR-                  X5      5         Sn
A
NSn
A
ff = f)a  Fetches list of name servers from provided Cloud DNS Managed Zone.

Args:
  domains_messages: Cloud Domains messages module.
  cloud_dns_zone: Cloud DNS Zone resource reference.
  domain: Domain name.
  dnssec_update: If ENABLE, try to read DNSSEC information from the Zone.
  dns_settings: Current DNS configuration (or None if resource is not yet
    created).

Returns:
  A pair: List of name servers and a list of Ds records (or [] if e.g. the
  Zone is not signed).
v1dnsprojectzdns.managedZones)params
collection)ra   managedZoneN.z]The dnsName '{}' of specified Cloud DNS zone '{}' does not match the registration domain '{}'z"Cloud DNS Zone '{}' is not public.z;Cloud DNS Zone '{}' is not signed. DNSSEC won't be enabled.zMCannot read DS records from Cloud DNS Zone '{}': {}. DNSSEC won't be enabled.zNNo supported DS records found in Cloud DNS Zone '{}'. DNSSEC won't be enabled.)0r	   GetClientInstanceMESSAGES_MODULEdns_api_utilGetRegistryParser   VALUEScorera   	GetOrFailmanagedZonesGetDnsManagedZonesGetRequestrd   apitools_exceptions	HttpErrorcalliope_exceptionsHttpExceptiondnsNamer   rI   rJ   
visibilityManagedZoneVisibilityValueValuesEnumpublicr   r   r@   r   rC   setrA   ManagedZoneDnsSecConfigStateValueValuesEnumondnssecConfigstater
   statusPrintDnsDnsKeysListRequestdnsKeysListnextPageToken	pageToken_ConvertDnsKeys)r:   r4   r7   r8   r9   dns_api_versionr`   dns_messageszone_refzoneerrordomain_with_dotsigneddns_keysreqrespr<   s                    r   r/   r/      s|   $ /uo6#$$,%%o6<<
Z&&++33== $ = (3..$$(2F2F 	/ 	
D SL/	\\_$


	##)6LL.$
  oo		!	!	;	;	B	BC 

,33NC  l***Rl,,, 	 "".&&223s4;K;K7LL 
 
 
,
,

 
 
*
* 
 R//DDGG&			d//55?JJHOO	 RPH

,
,  (( - *C [[c"d,,h((cm  /xH*	JJ 1171GIR			:	%%w 
	&	& 3

+
+E
223f 
	&	& PJJ 1171NP PPs7   :=M A2N  N N3N		NO%.OOc                 x   / nU GH  nUR                   UR                  R                  R                  :w  a  M4  UR                  (       d  MG   U R
                  R                  [        R                  " UR                  5      R                  5       5      nUR                   H  nU R
                  R                  [        R                  " UR                   5      R                  5       5      nUR                  U R                  UR                  UR                  UUS95        M     GM!     U$ ! [          a     GM3  f = f)zConverts DnsKeys to DsRecords.)keyTagdigest	algorithm
digestType)typeDnsKeyTypeValueValuesEnum
keySigningisActiveDsRecordAlgorithmValueValuesEnumsix	text_typer   upperdigestsDigestTypeValueValuesEnumappendr   r   	TypeError)r:   r   r   r<   keyr   ddigest_types           r   r   r     s    *c
xx<&&::EEE<<"++DD
--
&
,
,
.0i{{!&//IIMM!&&!'')+%%zzxx#&	 & (	)  & 
  s   CD**
D98D9c                    Uc  gUR                   bF  U R                  U R                  U R                  R                  R                  S9S9n[        SS9nX#4$ UR                  b(  U R                  U R                  / S9S9n[        SS9nX#4$ g)	z<Returns DNS settings (and update mask) with DNSSEC disabled.r,   rR   rT   T)r&   )rA   rB   )r'   )rU   rK   rV   rW   rX   r    rC   rL   )r:   r9   updated_dns_settingsrP   s       r   r2   r2   )  s    "".+77)::$55LL## ; % 8 &  d;K 
	** )+77",,r,: 8 <d3K 
	** r   defaultc                 H   [         R                  " U 5      n/ SQnUbR  [        R                  R	                  S5        [
        R                  " X4[        R                  S9  SnSn[        U5      n	OUSS nSnS	nS
n	[        R                  " UUUU	S9n
/ nU
S:X  a  [        U5      S:  a   [        R                  " S5      nU(       d  OQ[        R                  " U5      (       d/  [        R                  R	                  SR                  U5      5        OX/-  nMo  [        U5      S:  a  [        R                  R	                  S5        [        U5      S:  a  M  [        X[5      $ U
S
:X  aB   [        R                   " [        R"                  SSS9n [%        X]XU5      u  p [        X[U5      $ U
S:X  a  [3        XRU5      $ g! [&        R(                  [*        R,                  4 a=  n[        R                  R	                  [.        R0                  " U5      5         SnAOSnAff = fM  )a  Asks the user to provide DNS settings interactively.

Args:
  api_version: Cloud Domains API version to call.
  domain: Domain name corresponding to the DNS settings.
  dnssec_update: DNSSECUpdate operation.
  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.
)zProvide name servers list#Provide Cloud DNS Managed Zone name0Use free name servers provided by Google DomainsNzYour current DNS settings are:)outzYou can provide your DNS settings by specifying name servers, a Cloud DNS Managed Zone name or by choosing free name servers provided by Google DomainsT   z]You can provide your DNS settings by specifying name servers or a Cloud DNS Managed Zone nameF   messageoptionscancel_optionr   r   z%Name server (empty line to finish):  r?   z,You have to provide at least 2 name servers./ Cloud DNS Managed Zone name must not be empty.Cloud DNS Managed Zone name:  	validatorerror_messageprompt_stringr,   )r   r-   r
   r   r   r   sysstderrlenr   PromptChoicePromptResponser   rH   rJ   r.   PromptWithValidatorValidateNonEmptyr/   r   rI   rs   rt   r   r   r0   )r3   r7   r8   r9   print_formatr:   r   r   r   r   indexr$   rN   r   r<   es                   r   PromptForNameServersr   <  s   & #44[A' JJ56<3::F	7 
 M'lGbqkG	+  MG

!
!!	%
 ,
aZ
l
a
&&'NO
&&r**
**

9@@D
E
$
,  
\	Q	

GH l
a
 .==z
%%))I8d
#6F<$
  	.jIIz$    3 A AB +

q)**+ s   F> >$H"3HHc                 &   [         R                  " U 5      n/ SQnSnSnSn[        R                  n[        R
                  " UUUUS9nUS:X  aG   [        R                  " [        R                  SSS	9n	 [        X)X5      u  p ['        UX5      u  pXS4$ US:X  a  [)        X'5      u  pXS4$ g! [        R                  [        R                  4 a=  n[        R                  R!                  ["        R$                  " U5      5         S
nAOS
nAff = fM  )a  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.
)r   r   z0Keep current DNS settings from current registraraL  You can provide your DNS settings in one of several ways:
You can specify a Cloud DNS Managed Zone name. To avoid downtime following transfer, make sure the zone is configured correctly before proceeding.
You can select free name servers provided by Google Domains. This blank-slate option cannot be configured before transfer.
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.Fr   r   r   r   r   r   Nr   )NNT)r   r-   r   r   r   r   r   r   r   r/   r   rI   rs   rt   r
   r   r   r   r   r.   r0   )r3   r7   r:   r   r   r   r   r8   r   r   r$   r<   r   r9   rP   s                  r   PromptForNameServersTransferr     s,    #44[A'

&' -'
 &&-

!
!!	%
 aZ
%%))I8:d#67G7=$N 
 	 23C3?!MLe++z 9!)Le++  3 A AB +

q)**+ s   4B- -$D3D		Dc                 z   U R                   (       a  [        UR                   5      $ U R                  (       a  UR                  (       d  g[        [	        [
        R                  U R                  R                  5      5      n[        [	        [
        R                  UR                  R                  5      5      nX#:H  $ g)z4Checks if dns settings have equivalent name servers.F)rU   boolrC   sortedrE   r   rF   r@   )prev_dns_settingsnew_dns_settingsprev_nsnew_nss       r   NameServersEquivalentr     s    '' 1122  %%D$$&7&A&A&M&MNPGD$$&6&@&@&L&LMOF	r   c                  2    [         R                  " SSSSS9  g )NzThis operation is not safe.FT)r   throw_if_unattendedcancel_on_no)r   PromptContinuer   r   r   PromptForUnsafeDnsUpdater     s    #	r   c                     / nU R                   b  U R                   R                  nU R                  b  U R                  R                  n[        U5      $ r#   )rU   rA   rC   r   )r9   r<   s     r   DnssecEnabledr     sL    *""...88J'''11J	j	r   r#   ).r   
__future__r   r   r   r   r   apitools.base.pyr   rq   googlecloudsdk.api_lib.dnsr   rh   googlecloudsdk.api_lib.domainsr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.calliopers   "googlecloudsdk.command_lib.domainsgooglecloudsdk.corer
   r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   r   uniqueEnumr   objectr    r   r=   r.   r0   r1   r/   r   r2   r   r   r   r   r   r   r   r   <module>r      s    / &  '  
 > ; 8 , E 3 * # * 2 9 
 499  'F '( $0#9#9"&+\#  37#,#@ KO^&B2+* (4'='=&*&/	Tn@F r   