
                            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 ddlmZ  ej.                  ej0                  j2                  ej0                  j4                  ej0                  j6                        ej8                   G d dej:                                      Zd Zd Z y)zLCommand for Updating Cloud Security Command Center finding's security marks.    )absolute_import)division)print_function)unicode_literals)encoding)securitycenter_client)arg_parsers)base)flags)util)
properties)timesc                   2    e Zd ZdZddddZed        Zd Zy)UpdateMarksz8Update Security Command Center finding's security marks.aP  
      Selectively update security mark `Key1` with value `v1` on testFinding. Note
      that other security marks on `testFinding` are untouched:

        $ {command} `testFinding` --organization=123456 --source=5678
          --security-marks="key1=v1" --update-mask="marks.markKey1"

      Update all security marks on `testFinding`, under project `example-project`
      and source `5678`:

        $ {command} projects/example-project/sources/5678/findings/testFinding
          --security-marks="key1=v1,key2=v2"

      Update all security marks on `testFinding`, under folder `456` and source
      `5678`:

        $ {command} folders/456/sources/5678/findings/testFinding
          --security-marks="key1=v1,key2=v2"

      Update all security marks on `testFinding`, under organization `123456` and
      source `5678`:

        $ {command} `testFinding` --organization=123456 --source=5678
          --security-marks="key1=v1,key2=v2"

      Delete all security marks on `testFinding`:

        $ {command} `testFinding` --organization=123456 --source=5678
          --security-marks=""

      Update all security marks on `testFinding`, under project `example-project`,
      source `5678` and `location=eu`:

        $ {command} projects/example-project/sources/5678/findings/testFinding
          --security-marks="key1=v1,key2=v2" --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                  ddt        j                         d      j                  |        | j                  dd       | j                  dd	       | j                  j                  t        j                   j"                  j$                  j'                                y )
Nz--security-marksz
        SecurityMarks resource to be passed as the request body. It's a
        key=value pair separated by comma (,). For example:
        --security-marks="key1=val1,key2=val2".z	KEY=VALUE)helptypemetavarz--start-timez
        Time at which the updated SecurityMarks take effect. See `$ gcloud topic
        datetimes` for information on supported time formats.)r   z--update-maskaL  
        Use update-mask if you want to selectively update marks represented by
        --security-marks flag. For example:
        --update-mask="marks.key1,marks.key2". If you want to override all the
        marks for the given finding either skip the update-mask flag or provide
        an empty value (--update-mask '') for it.)r   FINDING_FLAGAddToParserSOURCE_FLAGAddParentGroup	scc_flagsAPI_VERSION_FLAGLOCATION_FLAGr
   Argumentr	   ArgDictadd_argumentdisplay_info	AddFormatr   VALUEScoredefault_formatGet)parsers    (lib/surface/scc/findings/update_marks.pyArgszUpdateMarks.ArgsU   s     
""6*	!!&)	 **62''/MM3   " k&
A   5   !!*"3"3"8"8"G"G"K"K"MN    c                 B   t        |      }t        j                  |      }|j                         }|j                  r9t        j                  |j                        }t        j                  |      |_        t        j                  |      }|j                  |_        |dk(  rQ|j                         }t        j                  |j                  |j                  j                         |_        ||_        nU|dk(  rP|j'                         }t        j                  |j                  |j&                  j                         |_        ||_        t+        |||      }|j                  $t-        j.                  |j                        |_        |j0                  j3                  |      }|S )Nv1v2)_GetApiVersionr   GetMessagesDSecuritycenterOrganizationsSourcesFindingsUpdateSecurityMarksRequest
start_timer   ParseDateTimeFormatDateTime	startTime	GetClientupdate_mask
updateMaskSecurityMarksr   DictToMessagesecurity_marks
MarksValuemarkssecurityMarks(GoogleCloudSecuritycenterV2SecurityMarks(googleCloudSecuritycenterV2SecurityMarks_ValidateParentAndUpdateNamescc_utilCleanUpUserMaskInputorganizations_sources_findingsUpdateSecurityMarks)	selfargsversionmessagesrequeststart_time_dtclientr:   r<   s	            r(   RunzUpdateMarks.Runy   s]   T"G$009HUUW  ))$//:m..}=g",,W5F))G$--/n%33


x55@@n -g	DHHJn%33




;
;
F
Fn :Hg6*4'BG%#889K9KLg11EEgNELr*   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr)   rL    r*   r(   r   r   "   s?    
 A I">FrO*-X !O !OF r*   r   c                 l    t        j                  |        t        j                  | |      dz   |_        |S )zAGenerate a security mark's name using org, source and finding id.z/securityMarks)r   .ValidateMutexOnFindingAndSourceAndOrganizationGetFullFindingNamename)rF   reqrG   s      r(   r@   r@      s/    55d;$$T736FF#(	*r*   c                 J    dg}t        j                  | | j                  |      S )zADetermine what version to call from --location and --api-version.r1   )rA   GetVersionFromArgumentsfinding)rF   deprecated_argss     r(   r.   r.      s"    !N/		)	)$o	NNr*   N)!rP   
__future__r   r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.sccr   googlecloudsdk.callioper	   r
   googlecloudsdk.command_lib.sccr   r   r   rA   'googlecloudsdk.command_lib.scc.findingsgooglecloudsdk.corer   googlecloudsdk.core.utilr   ReleaseTracksReleaseTrackGABETAALPHADefaultUniverseOnlyUpdateCommandr   r@   r.   rS   r*   r(   <module>rl      s    S &  % ' % < / ( = ; 9 8 * * $++00$2C2C2I2I s$$$ s slOr*   