
    X                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS	S
.r\R                  " \R                  R                  5       " S S\R                  5      5       r\\l        g)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                   .    \ rS rSrSr\S 5       rS rSrg)Create5   zCreates a sink.c                     U R                  SSS9  U R                  SSS9  U R                  SSS9  U R                  R                  S5        g)	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ArgsCreate.Args;   sh     *BC
D  E
 3  4 ''-    c           
      n   [         R                  " UR                  UR                  5      R	                  5       nUSUR
                  0S.n[         R                  " 5       R                  R                  [         R                  " 5       R                  [         R                  " UR                  5      R	                  5       [         R                  " 5       R                  " S0 UD6S95      n[        R                  R                  SR!                  UR"                  5      5        [         R$                  " U5      $ )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   Run
Create.RunJ   s     224>>37<<AAM  #4++
I .."66==DD**4<<8EEG&&(22?Y? 	E 	ABK
 JJ	$ %+F;+E+E$F	H ,,r   r   N)	__name__
__module____qualname____firstlineno____doc__staticmethodr   r3   __static_attributes__r   r   r   r   r   5   s       . .-r   r   N)r9   
__future__r   r   r   googlecloudsdk.api_lib.tracer   googlecloudsdk.callioper   googlecloudsdk.corer   DETAILED_HELPReleaseTracksReleaseTrackALPHACreateCommandr   detailed_helpr   r   r   <module>rF      sp    # &  ' - ( #	&	+8 D%%++,3-T 3- -3-l % r   