
    6                     H    S 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
g)z'Utils for transfer appliances commands.    )storage_url)flagsc                    / nUR                   b:  [        [        R                  UR                   5      U l         UR	                  S5        UR                  S5      (       a"  UR                  U l        UR	                  S5        UR                  S5      (       a"  UR                  U l	        UR	                  S5        [        US5      (       a  UR                  U l        UR                  b,  [        UR                  5      nX0l        UR	                  S5        UR                   b,  [        UR                   5      nX0l        UR	                  S	5        UR$                  b  S
/ 0nUR$                  R'                  S
S5      nUR$                  R'                  SS5      nUb2  [)        U5      u  pxUS
   R	                  SSR+                  Xx5      05        Ub  SU0US'   X@l        UR	                  S5        SR/                  U5      $ )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?lfX%%x1M&NO,6+An'(.<+-.	+	    c                     U R                  S/ 5      nUR                  S5      UU R                  SS5      U R                  SS5      U R                  SS5      S.$ )z/Maps command arguments to order contact values.emailsr   businessNnamephone)emailadditionalEmailsr-   contactNamer/   )r   pop)contact_fieldr,   s     r(   _apply_args_to_order_contactr5   M   s\    Xr*&zz!} ##J5"&&vt4  $/
 r*   Nc                 6   / nUR                  S5      (       a"  UR                  U l        UR                  S5        UR                  S5      (       a"  UR                  U l        UR                  S5        Ub  U/U l        UR                  b  UR                  R                  SS5      UR                  R                  SS5      UR                  R                  SS5      UR                  R                  S	S5      [        X5      S
.U l        UR                  S5        UR                  b+  [        UR                  5      U l        UR                  S5        UR                  b+  [        UR                  5      U l        UR                  S5        SR                  U5      $ )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   r7   r8   r   r   r   
appliancesr?   r   _get_region_codeorder_contactr5   r@   shipping_contactrA   r"   )order_resourcer$   appliance_namer%   s       r(   apply_args_to_orderrH   Y   sb    +	&''#'#6#6N '	n%%!%!2!2N}%!/ 0N	\\(($7LL$$Z6"ll../DdKll&&}d;&~<N y!	#">#N~&	&%A&N"()	+	r*   c                 h    [        US5      (       a  UR                  $ U R                  R                  $ )zBGet region code either from the country arg or the previous value.country)r   rJ   r?   r>   )rF   r$   s     r(   rC   rC      s-     T9<<				*	**r*   c                     [         R                  " U 5      nUR                  nUR                  nUb  UR	                  S5      (       d  US-  nX#4$ )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       sK    ++J7#??&& 4 4
cMF	r*   c                 *    [        U 5      u  pSUUS.0$ )z8Takes a storage_url string and returns a GcsDestination.r&   )outputBucket
outputPath)r    )rQ   r   rS   s      r(   r   r      s&    5jA.& 
 r*   )N)__doc__"googlecloudsdk.command_lib.storager   .googlecloudsdk.command_lib.transfer.appliancesr   r)   r5   rH   rC   r    r    r*   r(   <module>r[      s2    . ; @4n	,^+r*   