1# -*- coding: utf-8 -*- #
2# Copyright 2017 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
16"""Command to list all registries in a project and location."""
17
18from __future__ import absolute_import
19from __future__ import division
20from __future__ import unicode_literals
21
22from googlecloudsdk.api_lib.cloudiot import registries
23from googlecloudsdk.calliope import base
24from googlecloudsdk.command_lib.iot import resource_args
25from googlecloudsdk.command_lib.iot import util
26
27
28_FORMAT = """\
29table(
30    name.scope("registries"):label=ID,
31    name.scope("locations").segment(0):label=LOCATION,
32    mqttConfig.mqttEnabledState:label=MQTT_ENABLED
33)
34"""
35
36
37@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
38class List(base.ListCommand):
39  """List device registries."""
40
41  detailed_help = {
42      'DESCRIPTION':
43          '{description}',
44      'EXAMPLES':
45          """\
46        To list all device registries in a project and region 'us-central1', run:
47
48          $ {command} --region=us-central1
49        """,
50  }
51
52  @staticmethod
53  def Args(parser):
54    resource_args.AddRegionResourceArg(parser, 'to list registries for')
55    parser.display_info.AddFormat(_FORMAT)
56    parser.display_info.AddUriFunc(util.RegistriesUriFunc)
57
58  def Run(self, args):
59    """Run the list command."""
60    client = registries.RegistriesClient()
61
62    location_ref = args.CONCEPTS.region.Parse()
63
64    return client.List(location_ref, args.limit, args.page_size)
65