
    X                         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	d
Z ej                  ej                  j                         G d dej                               Zee_        y)z'trace sinks create command.    )absolute_import)division)unicode_literals)util)base)loga0  
        Creates a sink used to export trace spans to a destination.

        The sink's destination must be a BigQuery dataset.
        The destination must already exist. The identity created with the sink
        will need permission to write to the destination dataset. After creating
        a sink look for the *[writer_identity]* to be populated in the response.
        With that identity run the following command to give it permission:

        gcloud projects add-iam-policy-binding {bigquery_project_id} \
          --member serviceAccount:{writer_identity from trace_sink} \
          --role roles/bigquery.dataEditor

        You may also find an existing writer identity by describing a sink.

        It may take several minutes before trace spans are exported after the
        sink is created.
    zg
        $ {command} my-sink
      bigquery.googleapis.com/projects/my-project/datasets/my_dataset
    )DESCRIPTIONEXAMPLESc                   &    e Zd ZdZed        Zd Zy)CreatezCreates a sink.c                     | j                  dd       | j                  dd       | j                  dd       | j                  j                  d       y)	z Register flags for this command.	sink_namezThe name for the sink.)helpdestinationzThe destination must be a fully qualified BigQuery resource name. The destination can be for the same Google Cloud project or for a different Google Cloud project in the same organization.z	--projectzSCreate a sink associated with this project. This will override the default project.N)add_argumentdisplay_infoAddCacheUpdater)parsers    !lib/surface/trace/sinks/create.pyArgszCreate.Args;   sh     *BC
D  E
 3  4 ''-    c           
      h   t        j                  |j                  |j                        j	                         }|d|j
                  id}t        j                         j                  j                  t        j                         j                  t        j                  |j                        j	                          t        j                         j                  di |            }t        j                  j                  dj!                  |j"                               t        j$                  |      S )zThis is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The created sink with its destination.
    r   )nameoutputConfig)parent	traceSinkzYou can give permission to the service account by running the following command.
gcloud projects add-iam-policy-binding bigquery-project \
--member serviceAccount:{0} \
--role roles/bigquery.dataEditor )r   GetTraceSinkResourcer   projectRelativeNamer   	GetClientprojects_traceSinksr   GetMessages)CloudtraceProjectsTraceSinksCreateRequestGetProjectResource	TraceSinkr   statusPrintformatwriterIdentityFormatTraceSink)selfargssink_resource_name	sink_dataresult_sinks        r   Runz
Create.RunJ   s     224>>37<<AAM  #4++
I .."66==DD**4<<8EEG2d&&(22?Y? 	E 	ABK
 JJ	$ %+F;+E+E$F	H ,,r   N)__name__
__module____qualname____doc__staticmethodr   r1   r   r   r   r   r   5   s       . .-r   r   N)r5   
__future__r   r   r   googlecloudsdk.api_lib.tracer   googlecloudsdk.callioper   googlecloudsdk.corer   DETAILED_HELPReleaseTracksReleaseTrackALPHACreateCommandr   detailed_helpr   r   r   <module>rA      sr    # &  ' - ( #	&	+8 D%%++,3-T 3- -3-l % r   