
    C                         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	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zy)z2Utility for updating Managed Microsoft AD domains.    )absolute_import)division)unicode_literals)
exceptions)util)labels_util)
console_ioc                 b    g d}t        fd|D              r|S t        j                  d      )z;Check that update command has one of these flags specified.)clear_labelsremove_labelsupdate_labels
add_regionremove_regionadd_authorized_networksremove_authorized_networksenable_audit_logsc              3   @   K   | ]  }j                  |        y w)N)IsSpecified).0
update_argargss     Flib/googlecloudsdk/command_lib/active_directory/domains_update_util.py	<genexpr>z'CheckFieldsSpecified.<locals>.<genexpr>'   s     D*		*	%s   z6Must specify at least one field to update. Try --help.)anyr   ActiveDirectoryError)unused_domain_refr   patch_requestupdate_argss    `  r   CheckFieldsSpecifiedr      s8    	+ 	DDD''>	@ @    c                     t        j                  |       }t        j                  |       }|j                  | j	                               }|j
                  j                  |      S )zFetch existing AD domain.)name)r   GetClientForResourceGetMessagesForResource9ManagedidentitiesProjectsLocationsGlobalDomainsGetRequestRelativeName!projects_locations_global_domainsGet)
domain_refclientmessagesget_reqs       r   GetExistingDomainr-   -   s[    $$Z0&((4(NN""$ O &'		1	1	5	5g	>>r    c                 &    t        |       |_        |S )z?Fetch existing AD domain to update and add it to Patch request.)r-   domain)r)   unused_argsr   s      r   UpdatePatchRequestr1   6   s    *:6-	r    c                 v    |j                   }|r#|j                  |       dk(  r|dz   | z   |_         |S | |_         |S )z"Adds name of field to update mask.r   ,)
updateMaskcount)fieldr   update_masks      r   AddFieldToUpdateMaskr8   <   sM    ((+1$!,s!2U!:m 
  %M	r    c                 \   t         j                  j                  |      }|j                         r|t	        d|      }t        j                  |       }|j                  |j                  j                  |j                  j                        j                         }|r||j                  _        |S )zUpdates labels of domain.labels)r   DiffFromUpdateArgsMayHaveUpdatesr8   r   r$   ApplyDomainLabelsValuer/   r:   	GetOrNone)r)   r   r   labels_diffr+   
new_labelss         r   UpdateLabelsrD   G   s      //5+!(=AM**:6H""8??#>#>#0#7#7#>#>@@I	 $.m!	r    c                     |j                   rk|j                  s,t        j                  |       }|j	                         }||_        |j                   |j                  _        t        d|      }t        d|      }|S )zHReads the pfx file into the LDAPSSettings proto and updates the request.certificatePfxcertificatePassword)certificate_pfx_filelDAPSSettingsr   r$   LDAPSSettingsrF   r8   )r)   r   requestr+   settingss        r   ProcessPfxFilerM   T   sm    	  ,,Z8h'')h&g+/+D+DG("#3W=G"#8'BG	.r    c                  0    t        j                  d      } | S )z&Prompt for user input of pfx password.z@Please enter the password used the encrypt the pfx certificate: )r	   PromptPassword)creds    r   GetPfxPassswordrQ   a   s    		"	"H
J$	+r    c                     ~ |j                   r|j                   |j                  _        |S |j                  r|S t	               }||j                  _        |S )zCAllows for the pfx password to be read from stdin if not specified.)certificate_passwordrI   rG   clear_certificatesrQ   )
unused_refr   rK   secrets       r   ReadPfxPasswordIfNeededrW   h   sP    	040I0IG-N	N&.4'+	.r    c                 P    ~ |j                   rt        d|      }t        d|      }|S )NrF   rG   )rT   r8   )rU   r   rK   s      r   ClearCertificatesrY   u   s-    	"#3W=G"#8'BG	.r    N)__doc__
__future__r   r   r   'googlecloudsdk.api_lib.active_directoryr   +googlecloudsdk.command_lib.active_directoryr   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.core.consoler	   r   r-   r1   r8   rD   rM   rQ   rW   rY    r    r   <module>ra      sM    9 &  ' > < < 2@$?


r    