
    #                     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 r	S r
S	 rS
 rS rS rS rg)z*Create request hook for snapshot settings.    )absolute_import)division)unicode_literals)apis)
exceptionsc                     UR                   c   U$ [        UR                   5      S:w  a  [        R                  " SS5      eU$ )z8Validates that only a single location name is specified.   storage_location_namesz5only a single location name is permitted at this time)r
   lenr   InvalidArgumentException_argsreqs      Llib/googlecloudsdk/api_lib/compute/snapshot_settings/modify_request_hooks.pyvalidate_single_locationr      sM    	  ( 
* 4&&'1,

-
- ? 
 
*    c                 *   ^ [        U 5      mU4S jnU$ )z4Adds locations to the request if they are specified.c           	         > UR                   (       d  U$ TR                  R                  UR                    Vs/ s H  n[        UT5      PM     snS9n[	        UT5        XBR
                  R                  l        U$ s  snf )N)additionalProperties)r
   'SnapshotSettingsStorageLocationSettingsLocationsValue_wrap_location_name_ensure_location_fieldsnapshotSettingsstorageLocation	locations)r   r   r   locationlocations_msgmessagess        r   _maybe_add_locations1maybe_add_locations.<locals>._maybe_add_locations)   s    &&j 	88GG !% ; ;" ;H $Hh7 ;" 	H 	
  3)5B((2J"s   A;)_get_message_module)versionr!   r    s     @r   maybe_add_locationsr%   %   s     )($ 
r   c                 d    UR                   R                  R                  U UR                  U S9S9$ )z9Wraps a location name into the appropriate proto message.)name)keyvalue)r   r   AdditionalProperty@SnapshotSettingsStorageLocationSettingsStorageLocationPreference)r   r    s     r   r   r   >   sC     
	9	9	H	H	[	[
UU V  
\ 
 r   c                 Z    [         R                  " S[         R                  " SU 5      5      $ )z/Returns the message module for the Compute API.compute)r   GetMessagesModuleResolveVersion)r$   s    r   r#   r#   I   s)     
		$$Y8
 r   c                     U R                   (       d  UR                  5       U l         U R                   R                  (       d   UR                  5       U R                   l        gg)z'Ensures that the location field is set.N)r   SnapshotSettingsr   r   )r   r    s     r   r   r   Q   sL     
		#446C				-	-88: ( 
.r   c                    UR                   (       a/  SR                  [        UR                  5      S/-   5      Ul        U$ UR                  (       a:  SR                  S UR                  R                  S5      S/-    5       5      Ul        U$ )a  Adjusts the update mask for storage locations.

If storage location policy is specified, then the update mask is adjusted so
that the whole storage location structure is replaced.

If a storage location name is specified, then the update mask is specified so
that other storage location names are clearead.

Args:
  _: this is ignored
  args: the parsed CLI args.
  req: the request message, partially populated.

Returns:
  the request message with modified update mask.
,r   c              3   8   #    U  H  nU(       d  M  Uv   M     g 7f)N ).0masks     r   	<genexpr>6adjust_storage_location_update_mask.<locals>.<genexpr>x   s       	
, D,s   	zstorageLocation.locations)storage_location_policyjoin"_remove_all_storage_location_masks
updateMaskr
   splitr   s      r   #adjust_storage_location_update_maskr?   ]   s    " 
!! XX*3>>:>O=PPCN 
* "" XX	
,,S1*+,	
CN 
*r   c                     U R                  S5       V s/ s H&  n U (       d  M  U R                  S5      (       a  M$  U PM(     sn $ s  sn f )Nr3   r   )r>   
startswith)r7   s    r   r<   r<      sF     **S/
!$	 oo&78 !
  
s   AAAN)__doc__
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   r%   r   r#   r   r?   r<   r5   r   r   <module>rF      s=    1 &  ' , .
2	#Lr   