
    #                     n    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 Z	d Z
d	 Zd
 Zd Zd Zd Zy)z*Create request hook for snapshot settings.    )absolute_import)division)unicode_literals)apis)
exceptionsc                     |j                   	 |S t        |j                         dk7  rt        j                  dd      |S )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                 (    t        |       fd}|S )z4Adds locations to the request if they are specified.c           	          |j                   s|S j                  j                  |j                   D cg c]  }t        |       c}      }t	        |       ||j
                  j                  _        |S c c}w )N)additionalProperties)r
   'SnapshotSettingsStorageLocationSettingsLocationsValue_wrap_location_name_ensure_location_fieldsnapshotSettingsstorageLocation	locations)r   r   r   locationlocations_msgmessagess        r   _maybe_add_locationsz1maybe_add_locations.<locals>._maybe_add_locations)   s    &&j 	88GG !% ; ;" ;H $Hh7 ;" 	H 	
  3)5BC((2J"s   A7)_get_message_module)versionr!   r    s     @r   maybe_add_locationsr$   %   s     )($ 
r   c                 p    |j                   j                  j                  | |j                  |             S )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                 V    t        j                  dt        j                  d|             S )z/Returns the message module for the Compute API.compute)r   GetMessagesModuleResolveVersion)r#   s    r   r"   r"   I   s)     
		$$Y8
 r   c                     | j                   s|j                         | _         | j                   j                  s |j                         | j                   _        yy)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                    |j                   r/dj                  t        |j                        dgz         |_        |S |j                  r:dj                  d |j                  j                  d      dgz   D              |_        |S )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   $   K   | ]  }|r| 
 y w)N ).0masks     r   	<genexpr>z6adjust_storage_location_update_mask.<locals>.<genexpr>x   s      	
, ,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                 p    | j                  d      D  cg c]  } | r| j                  d      s|  c} S c c} w )Nr2   r   )r<   
startswith)r6   s    r   r:   r:      s@     **S/
!$	doo&78 !
  
s   3N)__doc__
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   r$   r   r"   r   r=   r:   r4   r   r   <module>rD      s=    1 &  ' , .
2	#Lr   