
                            d Z ddlmZ ddlmZ ddlmZ ddl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dZdZd Zd Z e	j$                  e	j&                  j(                        e	j*                   G d de	j,                                      Zy)z7Command to list all triggers in a project and location.    )absolute_import)division)unicode_literalsN)triggers)base)flags)typesz{description}z         To list all triggers in location ``us-central1'', run:

          $ {command} --location=us-central1

        To list all triggers in all locations, run:

          $ {command} --location=-

        or

          $ {command}
        )DESCRIPTIONEXAMPLESz table(
    name.scope("triggers"):label=NAME,
    eventFilters.type():label=TYPE,
    destination():label=DESTINATION,
    active_status():label=ACTIVE,
    name.scope("locations").segment(0):label=LOCATION
)
a   table(
    name.scope("triggers"):label=NAME,
    matchingCriteria.type():label=TYPE,
    destination.cloudRunService.service:label=DESTINATION_RUN_SERVICE,
    destination.cloudRunService.path:label=DESTINATION_RUN_PATH,
    active_status():label=ACTIVE
)
c                     | j                  d| j                  d            }t        j                  |      }t        j                  || d         }|rdj                  |      S dS )NeventFiltersmatchingCriteria
updateTimezBy {}Yes)getr	   EventFiltersDictToTyper   TriggerActiveTimeformat)triggerevent_filters
event_typeactive_times       %lib/surface/eventarc/triggers/list.py_ActiveStatusr   D   sY    ++ngkk:L.MN-++M:***:w|7LM+(3	$>>    c                    | j                  d      }|yd|v rW|j                  d      }|j                  d      }|rdj                  |      S |j                  d      }dj                  |      S d|v r1|j                  d      }d	j                  |j                  d            S d
|v rMd}|j                  d
      }t        j                  ||      }|r dj                  |j	                  d            S dS d|v rMd}|j                  d      }t        j                  ||      }|r dj                  |j	                  d            S dS d|v r1|j                  d      }dj                  |j                  d            S y)a  Generate a destination string for the trigger.

  Based on different destination types, this function returns a destination
  string accordingly:

    * Cloud Run trigger: "Cloud Run: {cloud run service or job}"
    * GKE trigger: "GKE: {gke service}"
    * Workflows trigger: "Workflows: {workflow name}"
    * Cloud Functions trigger: "Cloud Functions: {cloud function name}"

  For unknown destination (e.g. new types of destination and corrupted
  destination), this function returns an empty string.

  Args:
    trigger: eventarc trigger proto in python map format.

  Returns:
    A string representing the destination for the trigger.
  destination cloudRunjobzCloud Run job: {}servicezCloud Run service: {}gkezGKE: {}cloudFunctionz)^projects/.*/locations/.*/functions/(.*)$zCloud Functions: {}   workflowz)^projects/.*/locations/.*/workflows/(.*)$zWorkflows: {}httpEndpointzHTTP endpoint: {}uri)r   r   researchgroup)r   r   destr    r!   cloud_function_str_patternmatchworkflows_str_patterns           r   _Destinationr/   K   sp   ( M*+;??:&D
((5/C
 '',,hhy!G"))'22??5!DDHHY/00+%!L???+DII0$7E;@ ''A7HbH[ G??:&DII+T2E5:?!!%++a.1CC$??>*D%%dhhuo66 r   c                   *    e Zd ZdZeZed        Zd Zy)ListzList Eventarc triggers.c                 Z   t        j                  | ddd       t        j                  |        | j                  j	                  t
               | j                  j                  t        j                         | j                  j                  t        t        t        j                  d       y )NzjThe location for which to list triggers. This should be either ``global'' or one of the supported regions.FT)requiredallow_aggregation)active_statusr   type)r   AddLocationResourceArgAddProjectResourceArgdisplay_info	AddFormat_FORMAT
AddUriFuncr   GetTriggerURIAddTransformsr   r/   r	   r   )parsers    r   Argsz	List.Args   s    	  	6 
'
!!'*
""8#9#9:
%%&#,,' r   c                    t        j                         }|j                  j                  j	                          |j                  j
                  j	                         }|j                  ||j                  |j                        S )zRun the list command.)	r   TriggersClientV1CONCEPTSprojectParselocationr1   limit	page_size)selfargsclientlocation_refs       r   RunzList.Run   sY    &&(FMM!==))//1L;;|TZZ@@r   N)	__name__
__module____qualname____doc___DETAILED_HELPdetailed_helpstaticmethodr@   rM    r   r   r1   r1      s$       - "Ar   r1   )rQ   
__future__r   r   r   r(   googlecloudsdk.api_lib.eventarcr   googlecloudsdk.callioper   #googlecloudsdk.command_lib.eventarcr   r	   rR   r;   _FORMAT_BETAr   r/   ReleaseTracksReleaseTrackGADefaultUniverseOnlyListCommandr1   rU   r   r   <module>r`      s    > &  ' 	 4 ( 5 5 			&?2j D%%(()A4 A  *Ar   