
    
N                        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 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)S r*S r+S  r,\RZ                  " \R\                  R^                  \R\                  R`                  \R\                  Rb                  5      \Rd                   " S! S"\Rf                  5      5       5       r4g#)%zImport URL maps command.    )
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   1   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=   @   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)r-   r.   r/   Insertr1   !ComputeRegionUrlMapsInsertRequestr)   r*   r4   ComputeUrlMapsInsertRequestr   r6   )r7   r8   r9   url_mapr;   r<   s         r   _SendInsertRequestrC   `   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   _GetClearedFieldsForDurationrN   }   sM    .Xy!!,23Xw,01	r   c                     / n[        U S5      (       a!  U R                  c  UR                  US-   5        [        U S5      (       a!  U R                  c  UR                  US-   5        U$ rE   )rH   rF   rI   rG   rJ   s      r   '_GetClearedFieldsForCachePolicyDurationrP      sa    .Xy!!h&6&6&>,23XwHNN$:,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)rR   rI   rS   )url_rewriterL   rM   s      r   _GetClearedFieldsForUrlRewriterU      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.)rW   rI   rH   rY   rN   )retry_policyrL   rM   s      r   _GetClearedFieldsForRetryPolicyr[      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]   rI   )mirror_policyrL   rM   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)	ra   rI   rb   rc   rd   re   rf   rg   rh   )cors_policyrL   rM   s      r   _GetClearedFieldsForCorsPolicyrj      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)rl   rI   rN   rm   )fault_delayrL   rM   s      r   _GetClearedFieldsForFaultDelayro      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.
httpStatusrm   )rq   rI   rm   )fault_abortrL   rM   s      r   _GetClearedFieldsForFaultAbortrs      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.)ru   rI   ro   rv   rs   )fault_injection_policyrL   rM   s      r   (_GetClearedFieldsForFaultInjectionPolicyrx      s     .		%	%,01#&D$$lX&='? ?N		%	%,01 
 $&D$$lX&='? ?N	r   c                    / nU R                   c  UR                  US-   5        U R                  c  UR                  US-   5        U R                  c  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 CacheKeyPolicy.includeProtocolincludeHostincludeQueryStringincludedQueryParametersexcludedQueryParametersincludedHeaderNamesincludedCookieNames)rz   rI   r{   r|   r}   r~   r   r   )cache_key_policyrL   rM   s      r   "_GetClearedFieldsForCacheKeyPolicyr      s    .%%-,)::;!!),67((0,)==>		1	1,)BBC		1	1,)BBC		-	-,)>>?		-	-,)>>?	r   c                    / nU R                   (       d  UR                  US-   5        OU[        U R                   US-   5      -   nU R                  c  UR                  US-   5        U R                  (       d  UR                  US-   5        U R
                  c  UR                  US-   5        OU[        U R
                  US-   5      -   nU R                  c  UR                  US-   5        OU[        U R                  US-   5      -   nU R                  c  UR                  US	-   5        OU[        U R                  US
-   5      -   nU R                  c  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  (       d  UR                  US-   5        U R                  c  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 CachePolicy.cacheKeyPolicyzcacheKeyPolicy.requestCoalescing	cacheMode
defaultTtlzdefaultTtl.maxTtlzmaxTtl.	clientTtlz
clientTtl.negativeCachingnegativeCachingPolicycacheBypassRequestHeaderNamesserveWhileStalezserveWhileStale.)r   rI   r   r   r   r   rP   r   r   r   r   r   r   )cache_policyrL   rM   s      r   _GetClearedFieldsForCachePolicyr     s   .		$	$,)99:#&H##\4E%E'G GN##+,)<<=			,45$,56#&M!='? ?N ,12#&M\I5'7 7N#,45#&M| ;'= =N!!),)::;		+	+,)@@A		3	3,)HHI!!),)::; 
 $&M$$l5G&G'I IN	r   c                    / 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        OU[        U R                  US-   5      -   n[        U S5      (       aC  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.cachePolicyzcachePolicy.)r   rI   r   rU   r   rN   r   r[   r   r_   r   rj   r   rx   rH   r   r   )route_actionrL   rM   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
 \=))##L=89 
 &(G

"
"L>$A)C Cn	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   rI   r   )custom_error_response_policyrL   rM   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   rI   r   r   r   r   r   )url_redirectrL   rM   s      r   _GetClearedFieldsForUrlRedirectr   h  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   rI   r   r   r   )header_actionrL   rM   s      r    _GetClearedFieldsForHeaderActionr   z  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.)3r7   r8   ResolveAsResourcecompute_scope	ScopeEnumGLOBALcompute_flagsGetDefaultScopeListerr   ReadFromFileOrStdinsourcer$   Importr1   r!   r&   r   ValidationErrorcompute_exceptionsstrnamer3   r
   warningr   SendGetRequestapitools_exceptions	HttpErrorstatus_coderC   PromptContinueformatidfingerprintr   rI   r   r   r   r   r   r   r   r   r   r   r   r   r.   IncludeFieldsr=   )argsholderurl_map_argr   r7   r8   r9   datarB   eurl_map_olderrorrM   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)5r   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=   rC   rN   rP   rU   r[   r_   rj   ro   rs   rx   r   r   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:,
"(&R,^	$\F~ $++00$2C2C2I2I ET E Er   