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
16"""Common flag setup and parsing for Cloud API Gateway surface."""
17
18from __future__ import absolute_import
19from __future__ import division
20from __future__ import unicode_literals
21
22from googlecloudsdk.command_lib.iam import completers as iam_completers
23from googlecloudsdk.command_lib.util.args import labels_util
24
25
26def AddDisplayNameArg(parser):
27  """Adds the display name arg to the parser."""
28  parser.add_argument(
29      '--display-name',
30      help="""\
31      Human readable name which can optionally be supplied.
32      """)
33
34
35def AddManagedServiceFlag(parser):
36  """Adds the managed service flag."""
37  parser.add_argument(
38      '--managed-service',
39      help="""\
40      The name of a pre-existing Google Managed Service.
41      """)
42
43
44def AddBackendAuthServiceAccountFlag(parser):
45  """Adds the backend auth service account flag."""
46  parser.add_argument(
47      '--backend-auth-service-account',
48      help="""\
49      Service account which will be used to sign tokens for backends with \
50      authentication configured.
51      """)
52
53
54def ProcessLabelsFlag(labels, message):
55  """Parses labels into a specific message format."""
56
57  class Object(object):
58    pass
59
60  if labels:
61    labels_obj = Object()
62    labels_obj.labels = labels
63    labels = labels_util.ParseCreateArgs(
64        labels_obj,
65        message)
66
67  return labels
68
69
70class GatewayIamRolesCompleter(iam_completers.IamRolesCompleter):
71
72  def __init__(self, **kwargs):
73    super(GatewayIamRolesCompleter, self).__init__(
74        resource_collection='apigateway.projects.locations.gateways',
75        resource_dest='gateway',
76        **kwargs)
77