
    !                        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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 Zd Zy)z:Command to Update a Cloud Security Command Center finding.    )absolute_import)division)print_function)unicode_literalsN)securitycenter_client)base)flags)util)log)
properties)timesc                   2    e Zd ZdZddddZed        Zd Zy)Updatez)Update a Security Command Center finding.a  
        Update testFinding's state from `ACTIVE` to `INACTIVE`:

          $ {command} `testFinding` --organization=123456 --source=5678
            --state=INACTIVE

        Update testFinding's state from `ACTIVE` to `INACTIVE` using project name
        for example-project:

          $ {command} projects/example-project/sources/5678/findings/testFinding
            --state=INACTIVE

        Update testFinding's state from `ACTIVE` to `INACTIVE` using folder name
        `456`:

          $ {command} folders/456/sources/5678/findings/testFinding
            --state=INACTIVE

        Override all source properties on `testFinding`:

          $ {command} `testFinding` --organization=123456 --source=5678
            --source-properties="propKey1=propVal1,propKey2=propVal2"

        Selectively update a specific source property on `testFinding`:

          $ {command} `testFinding` --organization=123456 --source=5678
            --source-properties="propKey1=propVal1,propKey2=propVal2" --update-mask="source_properties.propKey1"

        Update finding `testFinding` with `location=eu`, state from `ACTIVE` to
        `INACTIVE`:

          $ {command} `testFinding` --organization=123456 --source=5678
            --state=INACTIVE --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                  j                  |        t         j                  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                  j                  t        j                   j"                  j$                  j'                                y )Nz--update-maska  
        Optional: If left unspecified (default), an update-mask is automatically
        created using the flags specified in the command and only those values
        are updated. For example: --external-uri='<some-uri>'
        --event-time='<some-time>' would automatically generate
        --update-mask='external_uri,event_time'. Note that as a result, only
        external-uri and event-time are updated for the given finding and
        everything else remains untouched. If you want to delete
        attributes/properties (that are not being changed in the update command)
        use an empty update-mask (''). That will delete all the mutable
        properties/attributes that aren't specified as flags in the update
        command. In the above example it would delete source-properties.
        State can be toggled from ACTIVE to INACTIVE and vice-versa but it
        cannot be deleted.)help)r	   FINDING_FLAGAddToParserSOURCE_FLAGAddParentGroupEVENT_TIME_FLAG_NOT_REQUIREDEXTERNAL_URI_FLAGSOURCE_PROPERTIES_FLAG
STATE_FLAG	scc_flagsAPI_VERSION_FLAGLOCATION_FLAGadd_argumentdisplay_info	AddFormatr   VALUEScoredefault_formatGet)parsers    "lib/surface/scc/findings/update.pyArgszUpdate.ArgsR   s     
""6*	!!&)	 	&&226:	''/	  ,,V4	  (**62''/
  " !!*"3"3"8"8"G"G"K"K"MN    c                 D   t        j                  ||j                        }t        j                  |      }|j                         }|j                  |_        |j                  srddddd}d|_        |j                         D ]"  }||v s|xj                  d||   z   z  c_        $ |j                  j                  d      r|j                  dd  |_        |d	k(  r|j                         |_        |j                  |j                  _        |j                  r/t        j                  |j                  |      |j                  _        t        j"                  |j$                  |      |j                  _        n|j'                         |_        |j                  |j(                  _        |j                  r/t        j                  |j                  |      |j(                  _        t        j"                  |j$                  |      |j(                  _        t+        ||      |_        t        j.                  |j                        |_        t1        |||      }t        j2                  |      }|j4                  j7                  |      }t8        j:                  j=                  d
       |S )N	eventTimeexternalUrisourcePropertiesstate)z--event-timez--external-uriz--source-propertiesz--state ,   v1zUpdated.)scc_utilGetVersionFromArgumentsfindingr   GetMessages6SecuritycenterOrganizationsSourcesFindingsPatchRequestupdate_mask
updateMaskGetSpecifiedArgNames
startswithFindingexternal_urir,   source_propertiesr
   ConvertSourcePropertiesr-   ConvertStateInputr.   "GoogleCloudSecuritycenterV2Finding"googleCloudSecuritycenterV2Finding_GenerateFindingNamenameCleanUpUserMaskInput_UpdateEventTime	GetClientorganizations_sources_findingsPatchr   statusPrint)	selfargsversionmessagesrequestmutable_fieldsargclientresponses	            r'   Runz
Update.Runq   s3   ..tT\\BG$009HMMOG))G
 %)!3	n g**,#. 


nS&9 9
9
 -
 
			&	&s	+$//3$ ((*go$($5$5goo!			+/+G+G""G,
( #44TZZIgoo 
5
5
7 0 @D?P?Pg00<			(()?)?I 	22C :>9O9O
**g:g006 (g6GL!66w7I7IJGtWg6G",,W5F44::7CHJJZ Or)   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr(   rU    r)   r'   r   r   #   s=    
 2 A .BrG&-P O O<7r)   r   c                 X    t        j                  |        t        j                  | |      S )z;Generate a finding's name using org, source and finding id.)r
   .ValidateMutexOnFindingAndSourceAndOrganizationGetFullFindingName)rM   rN   s     r'   rC   rC      s#    55d;		 	 w	//r)   c                    | j                   rmt        j                  | j                         }|dk(  r%t        j                  |      |j                  _        n$t        j                  |      |j                  _        | j                   t        j                  j                  t        j                  j                        j                  d      }|dk(  rE|j                  't        j                         j                         |_        ||j                  _        nD|j                  't        j                         j                         |_        ||j                  _        |j                   dz   |_        |S )z0Process and include the event time of a finding.r2   )tzz%Y-%m-%dT%H:%M:%S.%fZz,event_time)
event_timer   ParseDateTimeFormatDateTimer5   r+   rB   datetimenowtimezoneutcstrftimer   r6   r<   rA   r9   )rM   reqrN   event_time_dtrb   s        r'   rF   rF      s    
__''8M$#22=Ackk9>9M9M
:c,,6
 
__""&&(*;*;*?*?&@IIJ $		+779AAC(ckk		/	/	7!--/RRT 	. :Dc,,6^^m3CN	*r)   ) rY   
__future__r   r   r   r   re   googlecloudsdk.api_lib.sccr   googlecloudsdk.callioper   googlecloudsdk.command_lib.sccr	   r   r
   r3   'googlecloudsdk.command_lib.scc.findingsgooglecloudsdk.corer   r   googlecloudsdk.core.utilr   ReleaseTracksReleaseTrackGAALPHABETADefaultUniverseOnlyUpdateCommandr   rC   rF   r\   r)   r'   <module>rz      s    A &  % '  < ( = ; 9 8 # * * $++1143D3D3I3I AT A AH0r)   