1# -*- coding: utf-8 -*- #
2# Copyright 2019 Google LLC. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#    http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15"""Command for listing existing triggers."""
16
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import unicode_literals
20
21from googlecloudsdk.calliope import base
22from googlecloudsdk.command_lib.events import eventflow_operations
23from googlecloudsdk.command_lib.run import connection_context
24from googlecloudsdk.command_lib.run import flags as serverless_flags
25
26
27@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
28class List(base.ListCommand):
29  """List available event source kinds."""
30
31  detailed_help = {
32      'DESCRIPTION': """\
33          {description}
34          """,
35      'EXAMPLES': """\
36          To list available event source kinds:
37
38              $ {command}
39          """,
40  }
41
42  @staticmethod
43  def CommonArgs(parser):
44    parser.display_info.AddFormat("""table(source_kind:label=SOURCE:sort=1)""")
45
46  @staticmethod
47  def Args(parser):
48    List.CommonArgs(parser)
49
50  def Run(self, args):
51    conn_context = connection_context.GetConnectionContext(
52        args, serverless_flags.Product.EVENTS, self.ReleaseTrack())
53
54    with eventflow_operations.Connect(conn_context) as client:
55      source_crds = client.ListSourceCustomResourceDefinitions()
56      return [crd for crd in source_crds if crd.event_types]
57