
                         @   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 e	j                   e	j                   e	j"                  j$                  e	j"                  j&                         G d
 de	j(                                      ZddZy)z?Command to export Security Command Center findings to bigquery.    )absolute_import)division)print_function)unicode_literals)securitycenter_client)base)flags)utilc                   2    e Zd ZdZddddZed        Zd Zy)Exportz4Export Security Command Center findings to bigquery.a  
      To export findings for a given parent ``organizations/123/sources/456/locations/global`` and dataset ``projects/project_id/datasets/dataset_id`` run:

        $ {command} organizations/123 --dataset=projects/project_id/datasets/dataset_id --source=456 --location=global

      z
      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                  |        | j                  ddd       y )Nr   z	--datasetz'BigQuery dataset to export findings to.T)helprequired)	scc_flagsAppendParentArgAddToParserr	   SOURCE_FLAGLOCATION_FLAGadd_argument)parsers    .lib/surface/scc/findings/export_to_bigquery.pyArgszExport.Args1   sd     "..v6	!!&)''/
6      c                    d}t        j                  |      }t        j                  |      }|j                  t	        d      |j                         }t        j                  |j                        }|j                  |j                  |            |_        t        ||      |_        |j                  j                  |      S )Nv2zParent must be specified.)dataset)bigQueryDestination)r   GetMessages	GetClientparent
ValueError@SecuritycenterOrganizationsSourcesLocationsFindingsExportRequestr
   ValidateDatasetr   ExportFindingsRequestBigQueryDestinationexportFindingsRequest_GenerateParentResource(organizations_sources_locations_findingsr   )selfargsversionmessagesclientrequestvalidated_datasets          r   Runz
Export.Run>   s    G$009H",,W5F{{233 	QQS  ,,T\\:$,$B$B$88% 9 
 %C %G!
 -T7;GN::AA'JJr   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   r2    r   r   r   r      s9     = L
r- 
 
Kr   r   c                     t        j                  |        | j                  rd| j                  v r| j                  | _        t        j                  | |      }|S )zEGenerate a parent's name and parent using org, source and finding id.z	/sources/)r
   ValidateMutexOnSourceAndParentr"   sourceGetFullSourceName)r,   r-   r"   s      r   r)   r)   T   sD    %%d+	[[[DKK/++DK!!$0&	-r   N)r   )r6   
__future__r   r   r   r   googlecloudsdk.api_lib.sccr   googlecloudsdk.callioper   googlecloudsdk.command_lib.sccr	   r   'googlecloudsdk.command_lib.scc.findingsr
   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHAGACommandr   r)   r9   r   r   <module>rI      s    F &  % ' < ( = 9 8 D%%++T->->-A-AB2KT\\ 2K C 2Kjr   