
    3                        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 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.                  j0                  ej.                  j2                  ej.                  j4                        ej6                   G d dej8                                      ZddZy)z9Command for listing an organization or source's findings.    )absolute_import)division)print_function)unicode_literals)
list_pager)securitycenter_client)base)flags)util)
properties)timesc                       e Zd ZdZddej
                  j                  j                  j                          dddZ	e
d        Zd Zy	)
Listz*List an organization or source's findings.zz
          List an organization or source's findings. To list across all
          sources provide a '-' as the source id.a  
          List all ACTIVE findings under organization `123456` across all
          sources:

            $ {command} 123456 --filter="state=\"ACTIVE\""

          List all ACTIVE findings under project `abc` across all sources:

            $ {command} projects/abc --filter="state=\"ACTIVE\""

          List all ACTIVE findings under folder `456` across all sources:

            $ {command} folders/456 --filter="state=\"ACTIVE\""

          List all ACTIVE findings under organization `123456` and source
          `5678`:

            $ {command} 123456 --source=5678 --filter="state=\"ACTIVE\""

          Only list category and resource_name of all ACTIVE findings under
          organization `123456` and source `5678`:

            $ {command} 123456 --source=5678  --filter="state=\"ACTIVE\""
              --field-mask="finding.category,finding.resource_name"

          List all ACTIVE findings of XSS category/type, under organization
          `123456` and source `5678`:

            $ {command} 123456 --source=5678
              --filter="state=\"ACTIVE\" AND category=\"XSS\""

          List all findings attached to a particular resource under organization
          `123456`:

            $ {command} 123456
              --filter="resource_name=\"//container.a  /projects/pid/zones/zone-id/clusters/cluster-id\""

          List all ACTIVE findings that took place on `2019-01-01T01:00:00 GMT`
          time, under organization `123456`:

            $ {command} 123456
              --filter="state=\"ACTIVE\" AND event_time > 1546304400000""

          List all findings under organization `123456` across all sources and
          `location=eu`:

            $ {command} 123456 --location=euz
      This command uses the Security Command Center API. For more information,
      see [Security Command Center API.](https://cloud.google.com/security-command-center/docs/reference/rest))DESCRIPTIONEXAMPLESzAPI REFERENCEc                 x   t         j                  j                  |        t        j                         d   j                  |        t        j                  |        t        j                  j                  |        t        j                  j                  |        t        j                  j                  |        t        j                  j                  |        t        j                  j                  |        t        j                  j                  |        | j                  dd       | j                  dd       y )Nr   z--field-maska  
        Field mask to specify the finding fields listed in the response. An
        empty field mask will list all fields. For example:
        --field-mask="finding.category,finding.resource_name" will only output
        category and resource_name for the findings in addition to default
        attributes. Notice the difference between hyphens (-) used with flags
        v/s camel case used in field masks. An empty or missing field mask will
        list all fields.)helpz
--order-bya$  
        Expression that defines what fields and order to use for sorting.
        String value should follow SQL syntax: comma separated list of fields.
        For example: "name,resource_properties.a_property". The default sorting
        order is ascending. To specify descending order for a field, a suffix "
        desc" should be appended to the field name. For example:
        --order-by="name desc,source_properties.a_property" will order by name
        in descending order while source_properties.a_property in ascending
        order.)r	   URI_FLAGRemoveFromParser	scc_flagsAppendParentArgAddToParserr
   AddParentGroupPAGE_TOKEN_FLAGREAD_TIME_FLAGCOMPARE_DURATION_FLAGSOURCE_FLAGAPI_VERSION_FLAGLOCATION_FLAGadd_argument)parsers     lib/surface/scc/findings/list.pyArgsz	List.Argsd   s     	MM""6* "..v6	 ))&1((0	++F3	!!&)**62''/
  
       c                    ddg}t        j                  ||      }t        j                  |      }|j	                         }|dk(  r|j                  d      rJ|j                  |_        t        j                  |j                        }t        j                  |      |_        |j                  d      rJ|j                  |_        t        j                  |j                        }t        j                  |      |_        |j                  |_        |j                   $t#        j$                  |j                         |_        |j&                  |_        d|_        |j(                  |_        |j,                  |_        |j0                  |_        |j4                  |_        t7        |||      }t        j8                  |      }t;        j<                  |j>                  |d|j,                  d      S )Ncompare_duration	read_timev1 pageSizelistFindingsResults)batch_size_attribute
batch_sizefield) r    GetApiVersionUsingDeprecatedArgsr   GetMessages5SecuritycenterOrganizationsSourcesFindingsListRequestIsKnownAndSpecifiedr&   compareDurationr   ParseDurationFormatDurationForJsonr'   readTimeParseDateTimeFormatDateTime
field_mask	fieldMaskscc_utilCleanUpUserMaskInputfilterorder_byorderBy	page_sizer*   
page_token	pageTokenparent_GenerateParent	GetClientr   YieldFromListorganizations_sources_findings)	selfargsdeprecated_argsversionmessagesrequestcompare_duration_isoread_time_dtclients	            r"   RunzList.Run   s   );7O33D/JG$009HLLNG $		!	!"4	5"&"7"7$2273J3JK"'"="= #
 
	!	!+	.>>**7+;+;< //=G$"778I8IJg[[GNDKmmGO~~GG[[GNdGW5G",,W5F ##--'>># r$   N)__name__
__module____qualname____doc__r   VALUEScoreuniverse_domainGetdetailed_helpstaticmethodr#   rQ    r$   r"   r   r   #   sl    
 35#6F 7A6G6G6L6L6\6\6`6`6b5c d/G.2`rk8-t ' 'R,r$   r   c                     t        j                  |        | j                  rd| j                  v r| j                  | _        t        j                  | |      |_        |S )zGenerates a finding's parent using org and source and hook up filter.

  Args:
    args: (argparse namespace)
    req: request
    version: API version for the request

  Returns:
    req: Modified request
  z	/sources/)r   ValidateMutexOnSourceAndParentrC   sourceGetFullSourceName)rI   reqrK   s      r"   rD   rD      sH     %%d+	[[[DKK/++DK%%dG4#*	*r$   N)r(   )rU   
__future__r   r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.sccr   googlecloudsdk.callioper	   googlecloudsdk.command_lib.sccr
   r   r   r;   'googlecloudsdk.command_lib.scc.findingsgooglecloudsdk.corer   googlecloudsdk.core.utilr   ReleaseTracksReleaseTrackGABETAALPHADefaultUniverseOnlyListCommandr   rD   r\   r$   r"   <module>rq      s    @ &  % ' ' < ( = ; 9 8 * *
 $++00$2C2C2I2I S4 S Slr$   