
    "                        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 ddlmZ d Zd ZddZd Zd Z d Z!d Z" ejF                  ejH                  jJ                  ejH                  jL                  ejH                  jN                         G d dejP                               Z)y)z$Import target HTTPS Proxies command.    )absolute_import)division)unicode_literals)
exceptions)base_classes)base)flags)operation_utils)scope)target_https_proxies_utils)util)yaml_validator)
console_ioc                      ddddS )NzImport a target HTTPS proxy.zN          Imports a target HTTPS proxy's configuration from a file.
          a            A global target HTTPS proxy can be imported by running:

            $ {command} NAME --source=<path-to-file>

          A regional target HTTPS proxy can be imported by running:

            $ {command} NAME --source=<path-to-file> --region=REGION_NAME
          )briefDESCRIPTIONEXAMPLES r       2lib/surface/compute/target_https_proxies/import.py_DetailedHelpr   #   s     )
 r   c                 |    | t         j                  j                  k(  ry| t         j                  j                  k(  ryy)z3Returns the API version based on the release track.alphabetav1)r   ReleaseTrackALPHABETA)release_tracks    r   _GetApiVersionr    8   s3    d''---))...	r   c                 F    t        j                  dt        |       d|      S )z!Returns the resource schema path.computeTargetHttpsProxyfor_help)export_utilGetSchemaPathr    )r   r%   s     r   _GetSchemaPathr(   A   s&    		"	"]#	
 r   c                    t        j                  |      rX| j                  j                  }|j	                  | j
                  j                  |j                  |j                  |            }nL| j                  j                  }|j	                  | j
                  j                  |j                  |            }t        ||||d      S )z(Sends Target HTTPS Proxy insert request.)projectregiontargetHttpsProxy)r*   r,   zInserting TargetHttpsProxy)r   IsRegionalTargetHttpsProxiesRefapitools_clientregionTargetHttpsProxiesInsertmessages,ComputeRegionTargetHttpsProxiesInsertRequestr*   r+   targetHttpsProxies&ComputeTargetHttpsProxiesInsertRequest_WaitForOperationclient	resourcestarget_https_proxy_reftarget_https_proxyservice	operations         r   _SendInsertRequestr=   J   s      ??$$==GDD*22)00/ 	E 	12I $$77G>>*22/ 	? 	12I
 
9gy13O
Q Qr   c                    t        j                  |      rg| j                  j                  }|j	                  | j
                  j                  |j                  |j                  |j                         |            }n[| j                  j                  }|j	                  | j
                  j                  |j                  |j                         |            }t        ||||d      S )z%Make target HTTP proxy patch request.)r*   r+   r,   targetHttpsProxyResource)r*   r,   r?   zUpdating TargetHttpsProxy)r   r-   r.   r/   Patchr1   +ComputeRegionTargetHttpsProxiesPatchRequestr*   r+   Namer3   %ComputeTargetHttpsProxiesPatchRequestr5   r6   s         r   _SendPatchRequestrD   `   s      ??$$==GCC*22)00388:%7	 	D 	9:I $$77G==*22388:%7 	> 	9:I 
9gy13N
P Pr   c                     t        j                  |      rt        j                         }nt        j                         }t        j
                  | |||||      S )z3Waits for the TargetHttpsProxy operation to finish.)r   r-   r
   GetRegionalOperationsCollectionGetGlobalOperationsCollectionWaitForOperation)r8   r;   r<   r9   message
collections         r   r5   r5   x   sS      ?? @@BJ >>@J		)	))Wi*46L*1
3 3r   c                 `   |j                   }|j                  }|j                  | |j                  t        j                  j
                  t        j                  |            }t        j                  | j                  xs dd      }	 t        j                  |j                  j                  |t        |            }	 t)        j*                  ||      }
|
|k(  ryt        j4                  dj7                  |j9                               d	
       |
j:                  |_        t=        |
d      r|
j>                  |_        g }|j@                  |jC                  d       |jD                  |jC                  d       |jF                  |jC                  d       t=        |d      r|jH                  |jC                  d       t=        |d      r|jJ                  s|jC                  d       |jL                  |jC                  d       |jN                  |jC                  d       |jP                  s|jC                  d       |jR                  |jC                  d       |jT                  |jC                  d       |jV                  jY                  |      5  t[        ||||      cddd       S # t         j"                  $ r#}	t%        j"                  t'        |	            d}	~	ww xY w# t,        j.                  $ r)}|j0                  dk7  r|t3        ||||      cY d}~S d}~ww xY w# 1 sw Y   yxY w)z9Issues requests necessary to import target HTTPS proxies.)default_scopescope_lister-F)binary)message_typestreamschema_pathNi  z-Target Https Proxy [{0}] will be overwritten.T)rI   cancel_on_nofingerprintdescriptionserverTlsPolicyauthorizationPolicycertificateMaphttpFilters	proxyBindquicOverridesslCertificates	sslPolicyurlMap).r7   r8   ResolveAsResourcecompute_scope	ScopeEnumGLOBALcompute_flagsGetDefaultScopeListerr   ReadFromFileOrStdinsourcer&   Importr1   r#   r(   r   ValidationErrorcompute_exceptionsstrr   SendGetRequestapitools_exceptions	HttpErrorstatus_coder=   PromptContinueformatrB   idhasattrrT   rU   appendrV   rW   rX   rY   rZ   r[   r\   r]   r^   r.   IncludeFieldsrD   )argsholdertarget_https_proxy_argr   r7   r8   r9   datar:   eold_target_https_proxyerrorcleared_fieldss                r   _Runr}      s   ==&)1CC
!++22 66v>	 D @ 
	'	'(:s5	I$5$++__55"=1327FF&( 11
>FF
 
%
%
') 133#]3%;%G%G" .##+-(''/+,++3/0#5#D#D#L*+$6$B$B-(!!)+&$$,.)		+	++,!!)+&&(#++N;VY0F/1 <;m 
	'	' 5

,
,SV
445 
	&	& 2Ckfi1G02 2	2^ <;sB   	5J, ?K% L$,K"?KK"%L!8LL!L!$L-c                   8    e Zd ZdZ e       ZdZed        Zd Z	y)rg   zImport a target HTTPS Proxy.Nc                     t        j                         | _        | j                  j                  |d       t	        j
                  |t        | j                         d             y )Nimport)operation_typeTr$   )r	   TargetHttpsProxyArgumentTARGET_HTTPS_PROXY_ARGAddArgumentr&   AddImportFlagsr(   r   )clsparsers     r   ArgszImport.Args   sP    !&!?!?!AC**6(*Ks//1DACr   c                     t        j                  | j                               }t        ||| j                  | j                               S )N)r   ComputeApiHolderr   r}   r   )selfru   rv   s      r   Runz
Import.Run   s;    **4+<+<+>?Ffd994;L;L;NOOr   )
__name__
__module____qualname____doc__r   detailed_helpr   classmethodr   r   r   r   r   rg   rg      s.     %/-C CPr   rg   N)F)*r   
__future__r   r   r   apitools.base.pyr   rl   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computeri   r	   rc   r
   r   r`   7googlecloudsdk.command_lib.compute.target_https_proxiesr   !googlecloudsdk.command_lib.exportr   r&   googlecloudsdk.corer   googlecloudsdk.core.consoler   r   r    r(   r=   rD   r5   r}   ReleaseTracksr   GAr   r   UpdateCommandrg   r   r   r   <module>r      s    + &  ' > 7 ( O E > E I ^ A . 2*Q,P03J1Z D%%(($*;*;*@*@%%++-PT P-Pr   