1# -*- coding: utf-8 -*- #
2# Copyright 2020 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"""recommender API insights Describe command."""
16
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import unicode_literals
20
21from googlecloudsdk.api_lib.recommender import flag_utils as api_utils
22from googlecloudsdk.calliope import base
23from googlecloudsdk.command_lib.recommender import flags
24
25
26@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
27                    base.ReleaseTrack.GA)
28class Describe(base.Command):
29  r"""Describe an insight.
30
31     Describe an insight. This currently supports the following parent entities:
32     project, billing account, folder, and organization.
33
34     ## EXAMPLES
35     To describe a insight:
36
37      $ {command} INSIGHT_ID --project=${PROJECT} --location=${LOCATION}
38      --recommender=${RECOMMENDER}
39  """
40
41  @staticmethod
42  def Args(parser):
43    """Args is called by calliope to gather arguments for this command.
44
45    Args:
46      parser: An argparse parser that you can use to add arguments that go on
47        the command line after this command.
48    """
49    flags.AddParentFlagsToParser(parser)
50    parser.add_argument(
51        'INSIGHT',
52        type=str,
53        help='insight to describe',
54    )
55    parser.add_argument('--location', metavar='LOCATION', help='Location')
56    parser.add_argument(
57        '--insight-type',
58        metavar='INSIGHT_TYPE',
59        required=True,
60        help='Insight type to describe insights')
61
62  def Run(self, args):
63    """Run 'gcloud recommender insights describe'.
64
65    Args:
66      args: argparse.Namespace, The arguments that this command was invoked
67        with.
68
69    Returns:
70      The result insights to describe
71    """
72    api_version = api_utils.GetApiVersion(self.ReleaseTrack())
73    is_insight_api = True
74    is_list_api = False
75    recommender_service = api_utils.GetServiceFromArgs(args, is_insight_api,
76                                                       api_version)
77    parent_ref = flags.GetParentFromFlags(args, is_list_api, is_insight_api)
78    request = api_utils.GetDescribeRequestFromArgs(args, parent_ref,
79                                                   is_insight_api, api_version)
80    return recommender_service.Get(request)
81