
    >@                        S 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Jr  SSKJr  SSKJr  SSKJr  S rS rS$S jrS rS r S r!S r"S r#S r$S r%S r&S r'S r(S r)S r*S r+S r,S  r-\R\                  " \R^                  R`                  \R^                  Rb                  \R^                  Rd                  5      \Rf                   " S! S"\Rh                  5      5       5       r5g#)%zImport URL maps command.    )absolute_import)division)unicode_literals)
exceptions)base_classes)base)flags)scope)url_maps_utils)util)log)yaml_validator)
console_ioc                      SSSS.$ )NImport a URL map.zC          Imports a URL map's configuration from a file.
          zp          A URL map can be imported by running:

            $ {command} NAME --source=<path-to-file>
          )briefDESCRIPTIONEXAMPLES r       &lib/surface/compute/url_maps/import.py_DetailedHelpr   #   s     
 r   c                     U [         R                  R                  :X  a  gU [         R                  R                  :X  a  gg)z3Returns the API version based on the release track.alphabetav1)r   ReleaseTrackALPHABETA)release_tracks    r   _GetApiVersionr!   4   s3    d''---))...	r   c                 B    [         R                  " S[        U 5      SUS9$ )z!Returns the resource schema path.computeUrlMapfor_help)export_utilGetSchemaPathr!   )r    r&   s     r   _GetSchemaPathr)   =   s%    		"	".8
M Mr   c           	      $   UR                  5       S:X  ax  U R                  R                  nU R                  R                  R                  U R                  R                  UR                  UR                  UR                  5       US95      nOlU R                  R                  nU R                  R                  R                  U R                  R                  UR                  UR                  5       US95      n[        R                  " XUUS5      $ )zSends a URL map patch request and waits for the operation to finish.

Args:
  client: The API client.
  resources: The resource parser.
  url_map_ref: The URL map reference.
  replacement: The URL map to patch with.

Returns:
  The operation result.
compute.regionUrlMaps)projectregionurlMapurlMapResource)r,   r.   r/   zUpdating URL map)
Collectionapitools_clientregionUrlMapsPatchmessages ComputeRegionUrlMapsPatchRequestr,   r-   NameurlMapsComputeUrlMapsPatchRequestr   WaitForOperation)client	resourcesurl_map_refreplacementservice	operations         r   _SendPatchRequestr@   C   s     !88$$22G&&44::88''%%##%&	 	9 	()I $$,,G&&..4422''##%& 	3 	()I 
	(	(Y)46H
J Jr   c                    UR                  5       S:X  ai  U R                  R                  nU R                  R                  R                  U R                  R                  UR                  UR                  US95      nO]U R                  R                  nU R                  R                  R                  U R                  R                  UR                  US95      n[        R                  " XUUS5      $ )zSends a URL map insert request and waits for the operation to finish.

Args:
  client: The API client.
  resources: The resource parser.
  url_map_ref: The URL map reference.
  url_map: The URL map to insert.

Returns:
  The operation result.
r+   )r,   r-   r.   )r,   r.   zCreating URL map)r0   r1   r2   Insertr4   !ComputeRegionUrlMapsInsertRequestr,   r-   r7   ComputeUrlMapsInsertRequestr   r9   )r:   r;   r<   url_mapr>   r?   s         r   _SendInsertRequestrF   c   s     !88$$22G&&44;;99''%% 	: 	I $$,,G&&..5533'' 	4 	9:I 
	(	(Y)46H
J Jr   c                     / n[        U S5      (       a  UR                  US-   5        [        U S5      (       a  UR                  US-   5        U$ )z7Gets a list of fields cleared by the user for Duration.secondsnanos)hasattrappend)durationfield_prefixcleared_fieldss      r   _GetClearedFieldsForDurationrO      sM    .Xy!!,23Xw,01	r   c                     / nU R                   (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U$ )z9Gets a list of fields cleared by the user for UrlRewrite.pathPrefixRewritehostRewrite)rQ   rK   rR   )url_rewriterM   rN   s      r   _GetClearedFieldsForUrlRewriterT      sF    .		&	&,)<<=		 	 ,67	r   c                 $   / nU R                   (       d  UR                  US-   5        [        U S5      (       a  UR                  US-   5        U R                  (       d  UR                  US-   5        U$ U[	        U R                  US-   5      -   nU$ )z:Gets a list of fields cleared by the user for RetryPolicy.retryConditions
numRetriesperTryTimeoutzperTryTimeout.)rV   rK   rJ   rX   rO   )retry_policyrM   rN   s      r   _GetClearedFieldsForRetryPolicyrZ      s    .		%	%,)::;\<((,56		#	#,89 
 $&B""L3C$C'E EN	r   c                 T    / nU R                   (       d  UR                  US-   5        U$ )zBGets a list of fields cleared by the user for RequestMirrorPolicy.backendService)r\   rK   )mirror_policyrM   rN   s      r   '_GetClearedFieldsForRequestMirrorPolicyr^      s*    .		%	%,)99:	r   c                 Z   / nU R                   (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R
                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U$ )	z9Gets a list of fields cleared by the user for CorsPolicy.allowOriginsallowOriginRegexesallowMethodsallowHeadersexposeHeadersmaxAgeallowCredentialsdisabled)	r`   rK   ra   rb   rc   rd   re   rf   rg   )cors_policyrM   rN   s      r   _GetClearedFieldsForCorsPolicyri      s    .		!	!,78		'	',)==>		!	!,78		!	!,78		"	",89			,12		%	%,);;<			,34	r   c                     / nU R                   (       d  UR                  US-   5        OU[        U R                   US-   5      -   nU R                  (       d  UR                  US-   5        U$ )z=Gets a list of fields cleared by the user for HttpFaultDelay.
fixedDelayzfixedDelay.
percentage)rk   rK   rO   rl   )fault_delayrM   rN   s      r   _GetClearedFieldsForFaultDelayrn      sg    .			,56#&B} <'> >N			,56	r   c                     / nU R                   (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U$ )z=Gets a list of fields cleared by the user for HttpFaultAbort.
httpStatusrl   )rp   rK   rl   )fault_abortrM   rN   s      r   _GetClearedFieldsForFaultAbortrr      sE    .			,56			,56	r   c                    / nU R                   (       d  UR                  US-   5        OU[        U R                   US-   5      -   nU R                  (       d  UR                  US-   5        U$ U[	        U R                  US-   5      -   nU$ )zCGets a list of fields cleared by the user for FaultInjectionPolicy.delayzdelay.abortzabort.)rt   rK   rn   ru   rr   )fault_injection_policyrM   rN   s      r   (_GetClearedFieldsForFaultInjectionPolicyrw      s     .		%	%,01#&D$$lX&='? ?N		%	%,01 
 $&D$$lX&='? ?N	r   c                 n   / nU R                   (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        OU[        U R                  US-   5      -   nU R                  (       d  UR                  US-   5        OU[        U R                  US-   5      -   nU R                  (       d  UR                  US-   5        OU[        U R                  US-   5      -   nU R                  (       d  UR                  US-   5        OU[        U R                  US	-   5      -   nU R                  (       d  UR                  US
-   5        OU[        U R                  US-   5      -   nU R                  (       d  UR                  US-   5        U$ U[        U R                  US-   5      -   nU$ )z>Gets a list of fields cleared by the user for HttpRouteAction.weightedBackendServices
urlRewritezurlRewrite.timeoutztimeout.retryPolicyzretryPolicy.requestMirrorPolicyzrequestMirrorPolicy.
corsPolicyzcorsPolicy.faultInjectionPolicyzfaultInjectionPolicy.)ry   rK   rz   rT   r{   rO   r|   rZ   r}   r^   r~   ri   r   rw   )route_actionrM   rN   s      r   _GetClearedFieldsForRoutActionr      s   .		-	-,)BBC		 	 ,56#&D!='? ?N			,23#&BlZ7'9 9N		!	!,67#&E  ,"?'A AN		)	),)>>?#&M((,9O*O'Q QN		 	 ,56#&D!='? ?N		*	*,)??@
 
 $&N))..'0 0N 
r   c                     / nU R                   (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U$ )zHGets a list of fields cleared by the user for CustomErrorResponsePolicy.errorResponseRuleserrorService)r   rK   r   )custom_error_response_policyrM   rN   s      r   -_GetClearedFieldsForCustomErrorResponsePolicyr     sH     .	%	8	8,)==>	%	2	2,78	r   c                    / nU R                   (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R
                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U$ )z:Gets a list of fields cleared by the user for UrlRedirect.hostRedirectpathRedirectprefixRedirectredirectResponseCodehttpsRedirect
stripQuery)r   rK   r   r   r   r   r   )url_redirectrM   rN   s      r   _GetClearedFieldsForUrlRedirectr     s    .		"	",78		"	",78		$	$,)99:		*	*,)??@		#	#,89		 	 ,56	r   c                 2   / nU R                   (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U$ )z;Gets a list of fields cleared by the user for HeaderAction.requestHeadersToRemoverequestHeadersToAddresponseHeadersToRemoveresponseHeadersToAdd)r   rK   r   r   r   )header_actionrM   rN   s      r    _GetClearedFieldsForHeaderActionr   .  s    .		-	-,)AAB		*	*,)>>?		.	.,)BBC		+	+,)??@	r   c                    UR                   nUR                  nUR                  U U[        R                  R
                  [        R                  " U5      S9n[        R                  " U R                  =(       d    SSS9n [        R                  " UR                  R                  U[        U5      S9nUR(                  UR+                  5       :w  a  [,        R.                  " S5         [0        R2                  " XF5      n
X:X  a  g[        R<                  " S	R?                  UR+                  5       5      S
S9  UR@                  (       d  U
R@                  Ul         URB                  (       a'  [,        R.                  " S5        U
RB                  Ul!        / nURD                  (       d  URG                  S5        URH                  (       d  URG                  S5        URJ                  (       d  URG                  S5        URL                  (       d  URG                  S5        URN                  (       d  URG                  S5        URP                  (       d  URG                  S5        OU[S        URP                  S5      -   nURT                  (       d  URG                  S5        OU[W        URT                  S5      -   nURX                  (       d  URG                  S5        OU[[        URX                  S5      -   nUR\                  (       d  URG                  S5        OU[_        UR\                  S5      -   nUR`                  Rc                  U5         [e        XEXh5      sSSS5        $ ! [         R"                   a$  n	[$        R"                  " ['        U	5      5      eSn	A	ff = f! [4        R6                   a(  nUR8                  S:w  a  Ue[;        XEXh5      s SnA$ SnAff = f! , (       d  f       g= f)z-Issues requests necessary to import URL maps.)default_scopescope_lister-F)binary)message_typestreamschema_pathNzThe name of the Url Map must match the value of the 'name' attribute in the YAML file. Future versions of gcloud will fail with an error.i  z"Url Map [{0}] will be overwritten.T)messagecancel_on_nozAn up-to-date fingerprint must be provided to update the Url Map. Future versions of gcloud will fail with an error '412 conditionNotMet'description	hostRulespathMatcherstestsdefaultService defaultCustomErrorResponsePolicyz!defaultCustomErrorResponsePolicy.defaultRouteActionzdefaultRouteAction.defaultUrlRedirectzdefaultUrlRedirect.headerActionzheaderAction.)3r:   r;   ResolveAsResourcecompute_scope	ScopeEnumGLOBALcompute_flagsGetDefaultScopeListerr   ReadFromFileOrStdinsourcer'   Importr4   r$   r)   r   ValidationErrorcompute_exceptionsstrnamer6   r   warningr   SendGetRequestapitools_exceptions	HttpErrorstatus_coderF   PromptContinueformatidfingerprintr   rK   r   r   r   r   r   r   r   r   r   r   r   r   r1   IncludeFieldsr@   )argsholderurl_map_argr    r:   r;   r<   datarE   eurl_map_olderrorrN   s                r   _Runr   <  s7   ==&)--
!++22 66v>	 . @+ 
	'	'(:s5	I$5  __++"=13G \\[%%''KK 2 3G //DK 
3;;K<L<L<NO
 
GJKK 8 9 &11G .			-(			+&			.)	'"			*+		1	1<= 	
744/
	
  
	#	#./#&D""$9'; ;N		#	#./#&E""$9'; ;N			.)#&Fo'/ /N ++N;VE <;S 
	'	' 5

,
,SV
445 
	&	& GCkfFF	G| <;sB    3M (N ON1NNO,O	OO
O%c                   @    \ rS rSrSr\" 5       rSr\S 5       r	S r
Srg)r   i  r   Nc                     [         R                  " 5       U l        U R                  R                  USS9  [        R
                  " U[        U R                  5       SS95        g )Nimport)operation_typeTr%   )r	   UrlMapArgumentURL_MAP_ARGAddArgumentr'   AddImportFlagsr)   r   )clsparsers     r   ArgsImport.Args  sM    **,COOOx@s//1DACr   c                     [         R                  " U R                  5       5      n[        XU R                  U R                  5       5      $ )N)r   ComputeApiHolderr   r   r   )selfr   r   s      r   Run
Import.Run  s9    **4+<+<+>?Fd..0A0A0CDDr   r   )__name__
__module____qualname____firstlineno____doc__r   detailed_helpr   classmethodr   r   __static_attributes__r   r   r   r   r     s-    
 /-+C CEr   r   N)F)6r   
__future__r   r   r   apitools.base.pyr   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   r	   r   r
   r   +googlecloudsdk.command_lib.compute.url_mapsr   !googlecloudsdk.command_lib.exportr   r'   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   r   r!   r)   r@   rF   rO   rT   rZ   r^   ri   rn   rr   rw   r   r   r   r   r   ReleaseTracksr   GAr   r   UniverseCompatibleUpdateCommandr   r   r   r   <module>r      s    &  ' > 7 ( O E E = F A # . 2"MJ@J:,
"$N	$\F~ $++00$2C2C2I2I ET E Er   