
                             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
dZ ej                  ej                  j                          G d dej"                               Zee_        y)z'trace sinks update' command.    )absolute_import)division)unicode_literals)util)base)
exceptions)logz/
        Changes the *[destination]* associated with a sink.
        The new destination must already exist and Stackdriver Trace must have
        permission to write to it.

        Trace spans are exported to the new destination in a few minutes.
    zg/

        $ {command} my-sink bigquery.googleapis.com/projects/my-project/datasets/my_new_dataset
    )DESCRIPTIONEXAMPLESc                   ,    e Zd ZdZed        Zd Zd Zy)UpdatezUpdates a sink.c                     | j                  dd       | j                  dd       | j                  dd       | j                  j                  d       | j                  j                  d	       y	)
z Register flags for this command.	sink_namezThe name of the sink to update.)helpdestinationzThe new destination for the sink. The 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	--projectzSUpdate a sink associated with this project. This will override the default project.yamlN)add_argumentdisplay_info	AddFormatAddCacheUpdater)parsers    !lib/surface/trace/sinks/update.pyArgszUpdate.Args/   sz     *KL
   3  4 !!&)
''-    c           
          t        j                         }t        j                         j                  j	                  |j                  | |j                  di |dj                  |                  S )z*Patches a sink specified by the arguments.,)name	traceSink
updateMask )r   GetMessages	GetClientprojects_traceSinksPatch(CloudtraceProjectsTraceSinksPatchRequest	TraceSinkjoin)selfr   	sink_dataupdate_maskmessagess        r   	PatchSinkzUpdate.PatchSink@   se    !H>>//5599(h((595xx, 	: 	./ /r   c                    t        j                  |j                  |j                        }|j	                         }d|i}g }|j                  d      r"d|j                  i|d<   |j                  d       |st        j                  d      | j                  |||      }t        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 updated sink with its new destination.
    r   r   outputConfigzoutput_config.destinationz(Please specify the destination to update)r   GetTraceSinkResourcer   projectRelativeNameIsSpecifiedr   appendcalliope_exceptionsMinimumArgumentExceptionr,   r	   UpdatedResourceFormatTraceSink)r(   argssink_refsink_resource_namer)   r*   results          r   Runz
Update.RunI   s     ((FH!..0+,IK&#0$2B2B"Ci4588
46 6 ^^.	;GF!''r   N)__name__
__module____qualname____doc__staticmethodr   r,   r<   r    r   r   r   r   +   s!    . . /(r   r   N)r@   
__future__r   r   r   googlecloudsdk.api_lib.tracer   googlecloudsdk.callioper   r   r4   googlecloudsdk.corer	   DETAILED_HELPReleaseTracksReleaseTrackALPHAUpdateCommandr   detailed_helpr    r   r   <module>rL      su    $ &  ' - ( E #		" D%%++,6(T 6( -6(r % r   