
                            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dl	m
Z
 ddlmZ dd	lmZ ej                   ej                   ej"                  j$                         G d
 dej&                                      Zy)zList protection summary.    )rbc_filter_rewrite)resource_backup_config)common_args)base)
exceptions)flags)log)resource_projection_specc                   <    e Zd ZdZddddddZed        Zd	 Zd
 Zy)ListzpShow backup configuration metadata associated with specified resources in a particular location for the project.z@list backup configurations for a specified project and location.z{description}a%            `--project`: Project for which backup configurations should be listed.

          `--location`: Location for which backup configurations should be listed.

          `--filter`: The filter expression to filter results.

          `--sort-by`: The field to sort results by.
          a            `target_resource_display_name`: Name of the resource for which protection summary is to be listed.

          `target_resource_type`: Type of resource for which protection summary is to be displayed.

          Allowed values:
              * CLOUD_SQL_INSTANCE
              * COMPUTE_ENGINE_VM

          `backup_configured`: Displays if the specified resource has backups configured.

          `vaulted`: Displays if configured backups are protected using a backup vault.

          `backup_configs_details.backup_config_source_display_name`: Name of the backup schedule applied to the resource.

          `backup_configs_details.type`: Backup schedule type applied to the resource.

          Allowed values:
              * CLOUD_SQL_INSTANCE_BACKUP_CONFIG
              * COMPUTE_ENGINE_RESOURCE_POLICY
              * BACKUPDR_BACKUP_PLAN
              * BACKUPDR_TEMPLATE
          a            * To list protection summary for a resource named `resource-1`:

              $ {command} --project=sample-project --location=us-central1 --filter="target_resource_display_name=resource-1"

          * To list protection summary for a resource named `resource-1` that has backup configured:

              $ {command} --project=sample-project --location=us-central1 --filter="target_resource_display_name=resource-1 AND backup_configured=true"

        You can sort the results using the `--sort-by` flag. The only supported field for sorting is `target_resource_display_name`.

        Example of sorting:

          $ {command} --project=sample-project --location=us-central1 --sort-by="target_resource_display_name"
        )BRIEFDESCRIPTIONzFLAGS/ARGUMENTSSUBARGUMENTSEXAMPLESc                 0    t        j                  | d       y )N?Location for which the resource backup config should be listed.)r   AddLocationResourceArg)parsers    4lib/surface/backup_dr/resource_backup_config/list.pyArgsz	List.ArgsV   s    	  I    c                     t        j                  |j                        }|y |j                  d      }|r0t	        |d   t
              r|d   dvrt        j                  dd      d|d<   dj                  |      }|S )N r   )target_resource_display_nametargetResourceDisplayNamesort_byzkInvalid sort_by argument. Only sort_by target_resource_display_name/targetResourceDisplayName is supported.r   )	r   ParseSortByArgr   split
isinstancestrr   InvalidArgumentExceptionjoin)selfargsorder_byorder_by_fieldss       r   _Validate_and_Parse_SortByzList._Validate_and_Parse_SortBy]   s    ))$,,7HnnS)Oq)3/ALM //
  8OAxx(HOr   c                    |j                   t        j                  dd      t        j                         }|j
                  j                   j                         }|j                         }t        j                  |j                  |j                        }t        j                         j                  |j                  |      \  }}t!        j"                  d|j                  |       d|_        |j$                  t'        d|j$                        |_        |j(                  sd|_        | j+                  |      }|j-                  |j/                         ||j$                  |j0                  |	      S )
zConstructs and sends request.Nlocationr   )symbolsaliases)defaultsz$original_filter=%r, server_filter=%ri  json)parentfilters	page_sizelimitr%   )r)   r   RequiredArgumentExceptionr   ResourceBackupConfigClientCONCEPTSParseGetDisplayInfor
   ProjectionSpec
transformsr+   r   ListFilterRewriteRewritefilterr	   infor0   minformatr'   r   RelativeNamer1   )	r#   r$   client
parent_refdisplay_infor,   _server_filterr%   s	            r   RunzList.Runs   s@    }}00

K 
 $>>@F''--/J &&(L'66''1E1EH *;;=EEh F (A}HH3[[-) DK~~!3/dn;;dk..t4H;;&&(..jj   r   N)	__name__
__module____qualname____doc__detailed_helpstaticmethodr   r'   rE    r   r   r   r      sI     y M *K4-l  ,'r   r   N)rI   googlecloudsdk.api_lib.backupdrr   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   #googlecloudsdk.command_lib.backupdrr   googlecloudsdk.corer	   googlecloudsdk.core.resourcer
   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHAListCommandr   rL   r   r   <module>rX      so     ? B 3 ( . 5 # A D%%++,|4 | - |r   