
                            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Zddl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,                  j.                  ej,                  j0                  ej,                  j2                         G d dej4                               ZddZy)zdCommand to Filter an organization or source's findings and group them by their specified properties.    )absolute_import)division)print_function)unicode_literalsN)securitycenter_client)arg_parsers)base)flags)util)timesc                   2    e Zd ZdZddddZed        Zd Zy)	GroupzZFilter an organization or source's findings and groups them by their specified properties.zF
          To group across all sources provide a '-' as the source id.a'  
          Group findings under organization `123456` across all sources by their
          category:

            $ {command} 123456 --group-by="category"

          Group findings under project `example-project` across all sources by
          their category:

            $ {command} projects/example-project --group-by="category"

          Group findings under folders `456` across all sources by their
          category:

            $ {command} folders/456 --group-by="category"

          Group findings under organization `123456` and source `5678`, by their
          category:

            $ {command} 123456 --source=5678 --group-by="category"

          Group ACTIVE findings under organization `123456` and source `5678`,
          by their category:

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

          Group findings under organization `123456` and `location=eu` across
          all sources by their category:

            $ {command} 123456 --group-by="category" --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                    t        j                         d   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       | j                  dt        j                  dt        j                  d	
      d       y )Nr   z--filtera  
        Expression that defines the filter to apply across findings. The
        expression is a list of one or more restrictions combined via logical
        operators 'AND' and 'OR'. Parentheses are supported, and 'OR' has higher
        precedence than 'AND'. Restrictions have the form
        '<field> <operator> <value>' and may have a '-' character in front of
        them to indicate negation. Examples include: name,
        source_properties.a_property, security_marks.marks.marka.
        The supported operators are:
        *  '=' for all value types.
        *  '>', '<', '>=', '<=' for integer values.
        *  ':', meaning substring matching, for strings.

        The supported value types are:string literals in quotes, integer
        literals without quotes, boolean literals 'true' and 'false' without
        quotes. Some example filters: 'source_properties.size = 100',
        'category=\"XSS\" AND event_time > 10' etc.)helpz
--group-byaS  
        Expression that defines what findings fields to use for grouping
        (including 'state'). String value should follow SQL syntax: comma
        separated list  of fields. For example: "parent,resource_name".
        The following fields are supported:
        * resource_name
        * category
        * state
        * parentz--page-size   T)	unlimitedzx
        Maximum number of results to return in a single response. Default is 10,
        minimum is 1, maximum is 1000.)typer   )	scc_flagsAppendParentArgAddToParserPAGE_TOKEN_FLAGREAD_TIME_FLAGr
   COMPARE_DURATION_FLAGSOURCE_FLAGAPI_VERSION_FLAGLOCATION_FLAGadd_argumentr   
BoundedIntsysmaxsize)parsers    !lib/surface/scc/findings/group.pyArgsz
Group.ArgsP   s    "..v6))&1((0	++F3	!!&)**62''/
9  *    ##As{{dC*      c                    ddg}t        j                  ||      }t        j                  |      }|j	                         }|j                         |_        |dk(  r|j                  d      rh|j                  |j                  _	        t        j                  |j                  j                        }t        j                  |      |j                  _	        |j                  d      rh|j                  |j                  _        t        j                  |j                  j                        }t        j                   |      |j                  _        |j"                  |j                  _        |j$                  |j                  _        |j(                  |j                  _        |j,                  |j                  _        t1        |||      }t        j2                  |      }|j4                  j7                  |      }	|	S )Ncompare_duration	read_timev1)r    GetApiVersionUsingDeprecatedArgsr   GetMessages6SecuritycenterOrganizationsSourcesFindingsGroupRequestGroupFindingsRequestgroupFindingsRequestIsKnownAndSpecifiedr(   compareDurationr   ParseDurationFormatDurationForJsonr)   readTimeParseDateTimeFormatDateTimefiltergroup_bygroupBy	page_sizepageSize
page_token	pageToken_GenerateParentForGroupCommand	GetClientorganizations_sources_findingsr   )
selfargsdeprecated_argsversionmessagesrequestcompare_duration_isoread_time_dtclientresults
             r$   Runz	Group.Run   s   );7O33D/JG$009HMMOG#+#@#@#BG  $ 
	!	!"4	57;7L7L$$4$22((88 
 ''(<= 	$$4 
	!	!+	.04$$-**((11
 160D0D1
$$- +/++G  '+/==G  (,0NNG  )-1__G  *,T7GDG",,W5F2288AFMr&   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr%   rK    r&   r$   r   r   #   s=     cIF>rE%-N 1 1f&r&   r   c                    t        j                  |        | j                  |j                  _        d| _        t	        j
                  d      }t        j                  |       }|j                  |      r	||_	        |S t	        j
                  d      }|j                  |      r|| _
        t        j                  | |      |_	        |S )zFGenerate a finding's name and parent using org, source and finding id. z](organizations|projects|folders)/[a-z0-9]+/sources/[0-9-]{0,62}/locations/[A-Za-z0-9-]{0,62}$z@(organizations|projects|folders)/[a-z0-9]+/sources/[0-9-]{0,62}$)r   ValidateMutexOnSourceAndParentr7   r/   recompilescc_util GetParentFromPositionalArgumentsmatchparentsourceGetFullSourceName)rB   reqrD   region_resource_paternr[   resource_patterns         r$   r>   r>      s    %%d+$(KK#!$+::e 44T:&!!&)CJJZZH F#DK%%dG4#*	*r&   )r*   )rO   
__future__r   r   r   r   rV   r!   googlecloudsdk.api_lib.sccr   googlecloudsdk.callioper   r	   googlecloudsdk.command_lib.sccr
   r   r   rX   'googlecloudsdk.command_lib.scc.findingsgooglecloudsdk.core.utilr   ReleaseTracksReleaseTrackGABETAALPHACommandr   r>   rR   r&   r$   <module>rm      s    k &  % ' 	 
 < / ( = ; 9 8 * $++00$2C2C2I2IDDLL DDNr&   