
                             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\	R                   5      rSS jrS r " S S\	R(                  5      rg)z-Module containing the KCC Declarative Client.    )absolute_import)division)unicode_literalsN)
enable_api)declarative_client_base)resource_name_translator)
properties)
console_ioc                       \ rS rSrSrSrg)!AssetInventoryNotEnabledException   z2Exception for when Asset Inventory Is Not Enabled. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       Elib/googlecloudsdk/command_lib/util/declarative/clients/kcc_client.pyr   r      s    :r   r   c                 h   U =(       d2    [         R                  R                  R                  R	                  5       n Sn[
        R                  " X5      (       dZ  [        R                  " SSR                  X5      S9(       a  [
        R                  " X5        g[        SR                  X5      5      eg)zBChecks if the cloudasset API is enabled, prompts to enable if not.zcloudasset.googleapis.comFzAPI [{}] is required to continue, but is not enabled on project [{}]. Would you like to enable and retry (this will take a few minutes)?)defaultprompt_stringzFAborted by user: API [{}] must be enabled on project [{}] to continue.N)r	   VALUEScoreproject	GetOrFailr   IsServiceEnabledr
   PromptContinueformatEnableServicer   )r   service_names     r   *CheckForAssetInventoryEnablementWithPromptr#   #   s    Az((--55??A',,		$	$W	;	;  #VL:< w5-
R6,(* * 
<r   c                 Z    [         R                  " 5       R                  U S9R                  $ )N)collection_name)r   ResourceNameTranslatorget_resourceasset_inventory_type)
collections    r   _TranslateCollectionToAssetTyper*   5   s-    	!	8	8	:	G	G  
H 
""6"67r   c                   V    \ rS rSrSr\S 5       r\S 5       rS rS r	S r
S rS	 rS
rg)	KccClient:   z=Binary Client Interface for the config-connector binary tool.c                     g)Nzconfig-connectorr   selfs    r   binary_nameKccClient.binary_name=   s    r   c                      g)NzThis command requires the `config-connector` binary to be installed to export GCP resource configurations. Would you like to install the `config-connector` binary to continue command execution?r   r/   s    r   binary_promptKccClient.binary_promptA   s    	CDr   c                     U$ Nr   r0   argscmds      r   !_GetBinarySpecificExportArguments+KccClient._GetBinarySpecificExportArgumentsH   s    Jr   c                     [        [        USS 5      5        UR                  S5      (       d  UR                  S5      (       a  U R                  U5      $ U R	                  USSS9nU R                  X!S S9$ )Nr   resource_typesresource_types_filebulk-exportT)skip_filterasset_list_input)r#   getattrIsSpecified_CallBulkExportFromAssetList_GetBinaryExportCommand_CallBulkExportr8   s      r   
BulkExportKccClient.BulkExportK   sx    .i&()**.//..t44

&
&t]
&
MCDAAr   c                 |    U(       d  g[         R                  " SU5       Vs/ s H  o"(       d  M  UPM     sn$ s  snf )z2Parse Resource Types data into input string Array.Nz\s+|,+)resplit)r0   	file_dataxs      r   _ParseKindTypesFileData!KccClient._ParseKindTypesFileDataT   s/    xx	95;5!A5;;;s   
99c                    [        [        USS5      5        U R                  U5      n[        R                  " [        USS5      [        USS5      [        USS5      U[        USS5      S9nU R                  USSSS	9nU R                  XAUS
9$ )zCBulkExport with support for resource kind/asset type and filtering.r   Nfolderorganizationfilter)rS   r   orgkrm_kind_filterfilter_expressionr@   Tskip_parentrA   rB   )r#   rD   _ParseResourceTypesr   GetAssetInventoryListInputrG   rH   )r0   r9   	kind_argsrC   r:   s        r   rF   &KccClient._CallBulkExportFromAssetListZ   s    .wtY/MN((.I.IItXt,i.D.$/!!$$79 
&
&m4 ' AC<LMMr   c                    U R                  USSSS9n[        U5      /n[        R                  " [	        USS5      [	        USS5      =(       d2    [
        R                  R                  R                  R                  5       [	        USS5      U[	        USS5      S	9nU R                  USSSS9nU R                  X1U5      $ )
z1Exports all resources of a particular collection.r@   TrY   rS   Nr   rT   rU   )rS   r   rV   asset_types_filterrX   )rG   r*   r   r\   rD   r	   r   r   r   r   rH   )r0   r9   r)   r:   
asset_typerC   s         r   	ExportAllKccClient.ExportAlli   s    

&
&m4 ' AC1*=>J.IItXt,y$/ <""''//99;D.$/%!$$79 
&
&m4 ' AC+;<<r   r   N)r   r   r   r   r   propertyr1   r4   r;   rI   rP   rF   rb   r   r   r   r   r,   r,   :   sH    E  D DB<N=r   r,   r7   )r   
__future__r   r   r   rL   googlecloudsdk.api_lib.servicesr   3googlecloudsdk.command_lib.util.declarative.clientsr   8googlecloudsdk.command_lib.util.resource_map.declarativer   googlecloudsdk.corer	   googlecloudsdk.core.consoler
   ClientExceptionr   r#   r*   DeclarativeClientBaser,   r   r   r   <module>rm      sU    4 &  ' 	 6 W ] * 2;(?(O(O ;
*$7
=='== ==r   