
                         j    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d
Zd Zd Zd Zy	)z'Utils for transfer appliances commands.    )absolute_import)division)unicode_literals)storage_url)flagsc                    g }|j                   :t        t        j                  |j                         | _         |j	                  d       |j                  d      r"|j                  | _        |j	                  d       |j                  d      r"|j                  | _	        |j	                  d       t        |d      r|j                  | _        |j                  -t        |j                        }|| _        |j	                  d       |j                   -t        |j                         }|| _        |j	                  d	       |j$                  d
g i}|j$                  j'                  d
d      }|j$                  j'                  dd      }|4t)        |      \  }}|d
   j	                  ddj+                  ||      i       |d|i|d<   || _        |j	                  d       dj/                  |      S )a  Maps command arguments to appliance resource values.

  Args:
    appliance_resource (messages.Appliance): The target appliance resource.
    args (parser_extensions.Namespace): The args from the command.

  Returns:
    List[str] A list of strings representing the update mask.
  Nmodeldisplay_namedisplayNamecmekcustomerManagedKeyinternet_enabledofflineImportFeatureonlineImportFeaturesourcemanifestbucketz{}/{}locationtransferManifestofflineExportFeature,)r	   getattrr   APPLIANCE_MODEL_ENUMappendIsSpecifiedr
   r   r   r   hasattrr   internetEnabledoffline_import$_get_gcs_destination_from_url_stringr   online_importr   offline_exportget"_get_bucket_folder_from_url_stringformatr   join)	appliance_resourceargsupdate_maskdestinationr!   r   r   r   paths	            Blib/googlecloudsdk/command_lib/transfer/appliances/mapping_util.pyapply_args_to_appliancer,      s    +	ZZ&u'A'A4::Nw 
n%%)%6%6"}%	f,0II)+, T%&)-)>)>&	$6t7J7JKK.9+-.	#6t7I7IJK-8*,-	$^N  $$Xt4F""&&z48H7?lfdX%%x1M&NO,6+An'(.<+-.	+	    c                     | j                  dg       }|j                  d      || j                  dd      | j                  dd      | j                  dd      dS )z/Maps command arguments to order contact values.emailsr   businessNnamephone)emailadditionalEmailsr0   contactNamer2   )r"   pop)contact_fieldr/   s     r+   _apply_args_to_order_contactr8   P   s\    Xr*&zz!} ##J5"&&vt4  $/
 r-   Nc                    g }|j                  d      r"|j                  | _        |j                  d       |j                  d      r"|j                  | _        |j                  d       ||g| _        |j                  |j                  j                  dd      |j                  j                  dd      |j                  j                  dd      |j                  j                  d	d      t        | |      d
| _        |j                  d       |j                  +t        |j                        | _        |j                  d       |j                  +t        |j                        | _        |j                  d       dj                  |      S )a;  Maps command arguments to appliance resource values.

  Args:
    order_resource (messages.Order): The target order resource.
    args (parser_extensions.Namespace): The args from the command.
    appliance_name (str): The name of the appliance associated with the order.

  Returns:
    List['field1', 'field2']
  delivery_notesdeliveryNotesr
   r   Nlineslocalityzadministrative-areazpostal-code)addressLinesr=   administrativeArea
postalCode
regionCodeaddressorderContactshippingContactr   )r   r:   r;   r   r
   r   
appliancesrB   r"   _get_region_codeorder_contactr8   rC   shipping_contactrD   r%   )order_resourcer'   appliance_namer(   s       r+   apply_args_to_orderrK   \   s^    +	&'#'#6#6N '	n%!%!2!2N}%!/ 0N	\\(($7LL$$Z6"ll../DdKll&&}d;&~t<N y!	#">#N~&	&%A&N"()	+	r-   c                 ^    t        |d      r|j                  S | j                  j                  S )zBGet region code either from the country arg or the previous value.country)r   rM   rB   rA   )rI   r'   s     r+   rF   rF      s*     T9<<				*	**r-   c                     t        j                  |       }|j                  }|j                  }||j	                  d      s|dz  }||fS )zDTakes a storage_url string and returns a tuple of bucket and folder./)r   storage_url_from_stringbucket_nameresource_nameendswith)
url_stringurlr   folders       r+   r#   r#      sJ    ++J7#??&& 4
cMF	r-   c                 ,    t        |       \  }}d||diS )z8Takes a storage_url string and returns a GcsDestination.r)   )outputBucket
outputPath)r#   )rT   r   rV   s      r+   r   r      s(    5jA.&& 
 r-   )N)__doc__
__future__r   r   r   "googlecloudsdk.command_lib.storager   .googlecloudsdk.command_lib.transfer.appliancesr   r,   r8   rK   rF   r#   r    r-   r+   <module>r_      s9    . &  ' : @4n	,^+r-   