
    9                        S r SSKJr  SSKJr  SSKJr  SSK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rS r S$S jr  S$S jr!S r"S r# S$S jr$S r%S r&S r' " S S\RP                  5      r)\RT                  " \RV                  RX                  5      \RZ                   " S S\R\                  5      5       5       r/\RT                  " \RV                  R`                  5       " S  S!\/5      5       r1\RT                  " \RV                  Rd                  5       " S" S#\15      5       r3g)%zCommand for modifying URL maps.    )absolute_import)division)unicode_literalsN)messages)encoding)base_classes)property_selector)base)
exceptions)scope)flags)url_maps_utils)	resources)yaml)
console_io)editc                      SSS.$ )NzModify URL mapsa        *{command}* can be used to modify a URL map. The URL map
      resource is fetched from the server and presented in a text
      editor. After the file is saved and closed, this command will
      update the resource. Only fields that can be modified are
      displayed in the editor.

      The editor used to modify the resource is chosen by inspecting
      the ``EDITOR'' environment variable.
      )briefDESCRIPTION r       $lib/surface/compute/url_maps/edit.py_DetailedHelpr   (   s     	

 r   c                 l   SR                  S UR                  5        5       5      n[        R                  " XR                  =(       d    [
        R                  5      n	[        R                  " [        U R                  U5      S9n
U
R                  U	5      n	XY:X  a  SnOXUS   U	S'   UR                  S5      nU(       a  XS'   [        R                  " XR                  R                   R"                  5      nU(       a  X;:X  a  U/$ U R                  R%                  ['        U R                  X5      /5      $ )z8Returns an updated resource that was edited by the user.
c              3   n   #    U  H+  nUR                  S 5      (       a  S[        U5      -  OUv   M-     g7f)# N)
startswithlen).0lines     r   	<genexpr>)_ProcessEditedResource.<locals>.<genexpr>L   s2       ,$ --cCIo47,s   35)transformationsNnamefingerprint)join
splitlinesr   DeserializeValueformatEditDEFAULT_FORMATr	   PropertySelector_GetReferenceNormalizersr   Applygetr   DictToMessageclientr   UrlMapMakeRequests_GetSetRequest)holderurl_map_reffile_contentsoriginal_objectoriginal_recordmodifiable_recordargsenable_regional_backend_bucketsnon_comment_linesmodified_recordreference_normalizer
new_objectr'   s                r   _ProcessEditedResourcerC   8   s   ( ii  **,  
 !11;(;(;/ +;;.


;
 )..?/)J .f5OF!%%m4K'2m$''//66J 
4		#	#fmm[=>
 r   c           
         [         R                  " U5      n[        R                  " / SQS9nUR	                  U5      n	[        XXU5      n
U
R                  5       n  [        R                  " U5      n US;   n[        UUUUUU	U U5      n U$ ! [        R                   a    [        R                  " S5      ef = f! [        [        R                  [         R"                  [$        R&                  4 a  n[)        US[*        R,                  " U5      5      n[/        U[$        R&                  5      (       a  SnOSnSR1                  X5      n[2        R4                  " US	S
9(       d  [        R                  " S5      e SnAOSnAff = fGM.  )z Allows user to edit the URL Map.)defaultServicedescription	hostRulespathMatcherstests defaultCustomErrorResponsePolicy)
propertieszEdit aborted by user.)alphamessageapplyingparsingz)There was a problem {0} your changes: {1}z*Would you like to edit the resource again?)rM   prompt_stringN)r   MessageToDictr	   r.   r0   _BuildFileContentsgetvaluer   
OnlineEditNoSaveExceptioncompute_exceptionsAbortedErrorrC   
ValueErrorr   YAMLParseErrorr   ValidationErrorr   ToolExceptiongetattrsix	text_type
isinstancer+   r   PromptContinue)r=   r3   r7   r:   r8   trackr>   r;   field_selectorr<   bufr9   resource_listerM   problem_types                   r   _EditResourcerg   t   s    **?;/ %55	. %**?;
%	# ,,.-Eoom4m!G(-(:%,







)	m , 
I  E++,CDDE  	    	 G 9cmmA&67g	Az//	0	0! ;BB
g &&D !--.EFF	!G% 	s%   B 4B< +B9<8F4BE??Fc                 z   [         R                  " 5       n[        R                  R	                  5        HN  nUR                  S5        U(       a  UR                  S5        UR                  U5        UR                  S5        MP     UR                  S5        UR                  [        R                  " X R                  =(       d    [        R                  5      5        UR                  S5        [        R                  " [        R                  " [        X5      5      U R                  =(       d    [        R                  5      n[        R                  " USU5        UR                  S5        [        R                  " X0R                  =(       d    [        R                  5      n[        R                  " USU5        U$ )z!Builds the initial editable file.r   r   r   zExample resource:z#
zOriginal resource:)ioStringIOr   HELPr)   writeSerializeDictr+   r,   r-   r   rQ   _GetExampleResourceWriteResourceInCommentBlock)	r=   r3   r<   r;   ra   rc   r"   exampleoriginals	            r   rR   rR      s.   
#**,dIIcN	iinIIdOIIdO - ))D/))  
[[?D,?,?
 ))D/&&0?@
kk(T((' **74GM))E''{{9d&9&9( **85I3O	*r   c                    SSU0-  nSSU0-  nU R                   R                  SUS-   U R                   R                  US-   U R                   R                  S/SS	S
9/S9U R                   R	                  SS/SS9U R                   R	                  / SQSS9/U R                   R                  SUS-   U R                   R                  SS/US-   S9U R                   R                  SS/US-   S9U R                   R                  S/US-   S9/S9U R                   R                  SUS-   U R                   R                  SS/US-   S9U R                   R                  / SQUS -   S9/S9/U R                   R                  S!S"US-   S#9U R                   R                  S$S%US-   S#9U R                   R                  S$S&US-   S#9/S'9$ )(zGets an example URL Map.z\https://compute.googleapis.com/compute/%(track)s/projects/my-project/global/backendServices/ra   z[https://compute.googleapis.com/compute/%(track)s/projects/my-project/global/backendBuckets/zsite-mapzdefault-servicezerror-service4xxz/errors/4xx/not-found.htmli  )matchResponseCodespathoverrideResponseCode)errorServiceerrorResponseRulesz*.google.comz
google.comwww)hostspathMatcher)z*.youtube.comyoutube.comz*-youtube.comyoutubezwww-defaultz/searchz	/search/*search)pathsservicez/search/adsz/search/ads/*adsz	/images/*images)r&   rE   	pathRuleszyoutube-defaultzyoutube-search)z/watchz/viewz/previewzyoutube-watchzwww.google.comz/search/ads/inline?q=flowers)hostru   r   r|   z/watch/thisz/images/logo.png)r&   rE   rJ   rG   rH   rI   )r   r4   CustomErrorResponsePolicy0CustomErrorResponsePolicyCustomErrorResponseRuleHostRulePathMatcherPathRule
UrlMapTest)r3   ra   backend_service_uri_prefixbackend_bucket_uri_prefixs       r   rn   rn      s   +	% *	% 
 
		/2CC'-'P'P1OCooNN&+W3'* O  (Q 	( //
"
"#\2 #  //
"
"E# # 	 //
%
%7-G//**&488C +  //***O<85@ +  //**(M7(B +  & $ //
%
%7:KK//**&48;KK +  //**;8?J + 	 & '!F //
$
$#1058 % 
 //
$
$  03DD % 
 //
$
$ %/(: % q 
  I
 Ir   c           	         ^  U 4S jnU(       a  / SQnO/ SQnSU" SU5      4SU" SU5      4SU" SU5      4SU" S	U5      4S
U" SU5      4/$ )z4Gets normalizers that translate short names to URIs.c                    >^ ^ UU U4S jnU$ )z4Returns a function to normalize resource references.c                   >  TR                  U 5      nUR                  5       T;  a  [        SR	                  TU S95      eUR                  5       $ ! [        R                   a    [        SR	                  TS95      ef = f)z&Returns normalized URI for field_name.z-[{field_name}] must be referenced using URIs.)
field_namez,Invalid [{field_name}] reference: [{value}].)r   value)Parser   UnknownCollectionExceptionInvalidResourceErrorr+   
CollectionSelfLink)	reference	value_refallowed_collectionsr   resource_registrys     r   NormalizeReferenceU_GetReferenceNormalizers.<locals>.MakeReferenceNormalizer.<locals>.NormalizeReference8  s    
%++I6	 
			':	:":AA%Y B 
 	

 !! 11 
";BB% C 
 	

s   A -A>r   )r   r   r   r   s   `` r   MakeReferenceNormalizer9_GetReferenceNormalizers.<locals>.MakeReferenceNormalizer5  s    "& r   )compute.backendServicescompute.backendBucketscompute.regionBackendServiceszcompute.regionBackendBuckets)r   r   r   rE   zpathMatchers[].defaultServicez"pathMatchers[].pathRules[].servicer   z&CustomErrorResponsePolicy.errorServicerw   ztests[].servicer   )r   r>   r   r   s   `   r   r/   r/   0  s    
0 % 
!"24G
H
 *
!"24G
H
 /
!)-@
A
 3
!.2E
F
 
!)-@
A#
 r   c                 b   [         R                  " U5      (       aT  U R                  R                  SU R                  R                  UR                  5       UR                  UR                  S94$ U R                  R                  SU R                  R                  " S0 UR                  5       D64$ )z)Gets the request for getting the URL Map.Get)urlMapprojectregionr   )r   IsRegionalUrlMapRefapitools_clientregionUrlMapsr   ComputeRegionUrlMapsGetRequestNamer   r   urlMapsComputeUrlMapsGetRequestAsDict)r3   r8   s     r   _GetGetRequestr   r  s    ''44,,66##%''%% 	7 	
  $$oo..F1C1C1EF
 r   c           	      h   [         R                  " U5      (       aU  U R                  R                  SU R                  R                  UR                  5       UUR                  UR                  S94$ U R                  R                  SU R                  R                  " SSU0UR                  5       D64$ )z)Gets the request for setting the URL Map.Update)r   urlMapResourcer   r   r   r   )r   r   r   r   r   !ComputeRegionUrlMapsUpdateRequestr   r   r   r   ComputeUrlMapsUpdateRequestr   )r3   r8   replacements      r   r6   r6     s    ''44,,99##%&''%%	 	: 	
	 	 $$oo11 $(3(:(:(<
 r   c              #      #    UR                   nUR                  XR                  [        R                  R
                  S9n[        XE5      nUR                  U/5      n[        XXS   XR5      nU H  n	U	v   M	     g7f)z+Issues requests necessary to edit URL maps.)default_scoper   N)	r3   ResolveAsResourcer   compute_scope	ScopeEnumGLOBALr   r5   rg   )
r=   r7   ra   url_map_argr3   r8   get_requestobjectsrd   resources
             r   _Runr     s~     ==&--
M,C,C,J,J . + v3+.'
FAJ-  h
N  s   A:A<c                       \ rS rSrSrg)r   i  r   N)__name__
__module____qualname____firstlineno____static_attributes__r   r   r   r   r     s     r   r   c                   H    \ rS rSrSr\" 5       rSrSrSr	\
S 5       rS rSrg)	r,   i  zModify URL maps.r   Nv1c                 n    [         R                  " 5       U l        U R                  R                  U5        g N)r   UrlMapArgumentURL_MAP_ARGAddArgument)clsparsers     r   Args	Edit.Args  s$    **,COOO'r   c                     [         R                  " U R                  5       5      n[        XU R                  U R
                  5      $ r   )r   ComputeApiHolderReleaseTrackr   TRACKr   )selfr=   r7   s      r   RunEdit.Run  s4    **4+<+<+>?Fdjj$*:*:;;r   r   )r   r   r   r   __doc__r   detailed_helpr-   r   r   classmethodr   r   r   r   r   r   r,   r,     s4     /-.+
%( (<r   r,   c                       \ rS rSrSrSrg)EditBetai  betar   Nr   r   r   r   r   r   r   r   r   r   r     s	     %r   r   c                       \ rS rSrSrSrg)	EditAlphai  rL   r   Nr   r   r   r   r   r     s	     %r   r   )F)4r   
__future__r   r   r   ri   apitools.base.protorpcliter   apitools.base.pyr   googlecloudsdk.api_lib.computer   r	   googlecloudsdk.callioper
   r   "googlecloudsdk.command_lib.computerV   r   r   +googlecloudsdk.command_lib.compute.url_mapsr   r   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   r]   r   rC   rg   rR   rn   r/   r   r6   r   r[   r   ReleaseTracksr   GAUniverseCompatibleCommandr,   BETAr   ALPHAr   r   r   r   <module>r      s?   & &  ' 	 / % 7 < ( . O E = F ) $ 2 ) 
0 %*9F %*DN:Ur 8=?D(.:33  D%%(()<4<< <  *<$ D%%**+t  ,
 D%%++,  -r   