
    $                         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  G d de
j2                        Zy)z(Command for updating target SSL proxies.    )absolute_import)division)unicode_literals)base_classes)target_proxies_utils)utils)base)resource_args)
exceptions)flags)target_ssl_proxies_utilsc                   N    e Zd ZdZdZdZdZdZdZe	d        Z
	 	 	 ddZd Zd Zy)	UpdateaI  Update a target SSL proxy.

  *{command}* is used to replace the SSL certificate, backend service, proxy
  header or SSL policy of existing target SSL proxies. A target SSL proxy is
  referenced by one or more forwarding rules which define which packets the
  proxy is responsible for routing. The target SSL proxy in turn points to a
  backend service which will handle the requests. The target SSL proxy also
  points to at most 15 SSL certificates used for server-side authentication
  or one certificate map. The target SSL proxy can be associated with at most
  one SSL policy.
  TNc                    t        j                  |       t        j                  d      | _        | j                  j                  |       t        j                         | _        | j                  j                  |d       t        j                  ddd      | _        | j                  s| j                  j                  |d       t        j                  d	d      | _        |j!                         }|j#                         }| j                  j                  |       t        j$                  d	d      j'                  |       | j                  r|j!                  d
      }| j                  j                  |d       t        j(                  d	      j'                  |       t+        j,                  |ddddd       t+        j.                  d      j'                  |       y y )NF)requiredupdate)operation_typeztarget SSL proxy)r   !include_regional_ssl_certificatesSSL_CERTIFICATE)cust_metavarSSL)	sort_argsz	to attachzcertificate-map)name
positionalr   with_locationz	SSL proxy)r   AddProxyHeaderRelatedUpdateArgsbackend_service_flags'BackendServiceArgumentForTargetSslProxyBACKEND_SERVICE_ARGAddArgumentr   TargetSslProxyArgumentTARGET_SSL_PROXY_ARGssl_certificates_flags'SslCertificatesArgumentForOtherResourceSSL_CERTIFICATES_ARG_certificate_mapssl_policies_flags.GetSslPolicyMultiScopeArgumentForOtherResourceSSL_POLICY_ARGadd_mutually_exclusive_groupadd_argument_group)GetClearSslPolicyArgumentForOtherResourceAddToParser/GetClearSslCertificatesArgumentForOtherResourcer
   AddCertificateMapResourceArg.GetClearCertificateMapArgumentForOtherResource)clsparsergroupssl_policy_groups       0lib/surface/compute/target_ssl_proxies/update.pyArgszUpdate.Args9   s   88@ 	EE	  ''/$;;=C(((IFF.3	5 
 	**
0 + 2 	IIE	#  //1E//1""#34@@*{51
11E1Be	**
/ + 1LL
U#00

  BB
"{5)     c                    t        j                  | j                               }g }| j                  j	                  ||j
                        }|j                  j                  }|j                  j                  }	|j                  d      }
|j                  s|
rg }|j                  rC| j                  j	                  ||j
                        }|D cg c]  }|j                          }}|j                  |j                  d|	j                  |j                   |j#                         |	j%                  |            f       |j&                  r| j(                  j	                  ||j
                        }|j                  |j                  d|	j+                  |j                   |j#                         |	j-                  |j                                     f       |j.                  r}|	j0                  j3                  |j.                        }|j                  |j                  d|	j5                  |j                   |j#                         |	j1                  |	      
      f       |j6                  rMt9        j:                  || j<                  ||j
                        }|	j?                  |j                               }nd }|j@                  }|s|rH|j                  |j                  d|	jC                  |j                   |j#                         |      f       |j                  d      }| jD                  r$|jF                  jH                  jK                         nd }|s|rl|r|j                         nd }|j                  |j                  d|	jM                  |j                   |j#                         |	jO                  |            f       g }|j                  jQ                  ||      }|rtS        jT                  |       |S c c}w )Nclear_ssl_certificatesSetSslCertificates)sslCertificates)projecttargetSslProxy)targetSslProxiesSetSslCertificatesRequestSetBackendService)service)r<   r=   (targetSslProxiesSetBackendServiceRequestSetProxyHeader)proxyHeader)r<   r=   %targetSslProxiesSetProxyHeaderRequest)	sslPolicySetSslPolicy)r<   r=   sslPolicyReferenceclear_certificate_mapSetCertificateMap)certificateMap)r<   r=   (targetSslProxiesSetCertificateMapRequest)+r   ComputeApiHolderReleaseTrackr"   ResolveAsResource	resourcesclientapitools_clientmessagesIsKnownAndSpecifiedssl_certificatesr%   SelfLinkappendtargetSslProxies0ComputeTargetSslProxiesSetSslCertificatesRequestr<   Name)TargetSslProxiesSetSslCertificatesRequestbackend_servicer   /ComputeTargetSslProxiesSetBackendServiceRequest(TargetSslProxiesSetBackendServiceRequestproxy_header%TargetSslProxiesSetProxyHeaderRequestProxyHeaderValueValuesEnum,ComputeTargetSslProxiesSetProxyHeaderRequest
ssl_policyr   ResolveSslPolicyr)   SslPolicyReferenceclear_ssl_policy*ComputeTargetSslProxiesSetSslPolicyRequestr&   CONCEPTScertificate_mapParse/ComputeTargetSslProxiesSetCertificateMapRequest(TargetSslProxiesSetCertificateMapRequestMakeRequestsr   RaiseToolException)selfargsrb   re   certificate_map_refholderrequeststarget_ssl_proxy_refrP   rR   r9   	ssl_certsssl_cert_refsrefbackend_service_refr^   ssl_policy_refrH   	self_linkerrorsrO   s                        r5   _SendRequestszUpdate._SendRequestsf   s   
 **4+<+<+>?FH44FFf  ]]**F}}%%H!556NO 6i			11CC&""$/<=}S\\^}	=oo""$8DD+332779EE'0 F 2	 E 456  44FF
  "oo""$7CC+332779DD2;;= E ?	 D ABC 

8
8%%d&7&78  oov..0@LL#7#?#?*>*C*C*E'MM/;  N  =	 M ?@ A /@@
##%96;K;KMn.."++- / /j j,,%oov..JJ#7#?#?*>*C*C*E.8 K :; < !445LM			 --77== $( 3 &.. $( oov..0COO#7#?#?*>*C*C*EDLDD.7 E 9	 P :; < F**8V<Iv&I >s   O>c                    g d}g d}| j                   rf|j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       t        fd	|D              s1t        j                  d
dj                  |dd       d|d   d      y)zChecks for missing argument.)rT   r^   r[   rb   re   )z[--ssl-certificates]z[--backend-service]z[--proxy-header]z[--ssl-policy]z[--clear-ssl-policy]rh   z[--certificate-map]rH   z[--clear-certificate-map]r9   z[--clear-ssl-certificates]c              3   @   K   | ]  }j                  |        y wN)IsSpecified).0argro   s     r5   	<genexpr>z/Update._CheckMissingArgument.<locals>.<genexpr>   s     9t$s   z!You must specify at least one of z, Nz or .)r&   rV   sumcompute_exceptionsUpdatePropertyErrorjoin)rn   ro   all_argserr_msg_argss    `  r5   _CheckMissingArgumentzUpdate._CheckMissingArgument   s    HL oo'(/0oo-.56oo./679992299\#2&'b)9;< < :r7   c                 F    | j                  |       | j                  |      S r~   )r   r{   )rn   ro   s     r5   Runz
Update.Run   s!    t$d##r7   )NFN)__name__
__module____qualname____doc__r&   r   r%   r"   r)   classmethodr6   r{   r   r    r7   r5   r   r   %   sU    
 .** **\  $%*(,	Wr<,$r7   r   N)r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   .googlecloudsdk.command_lib.certificate_managerr
   "googlecloudsdk.command_lib.computer   r   3googlecloudsdk.command_lib.compute.backend_servicesr   r   3googlecloudsdk.command_lib.compute.ssl_certificatesr#   /googlecloudsdk.command_lib.compute.ssl_policiesr'   5googlecloudsdk.command_lib.compute.target_ssl_proxiesr   SilentCommandr   r   r7   r5   <module>r      sO    / &  ' 7 ? 0 ( H O$%Q G Zr$T r$r7   