feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Package marker."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

View File

@@ -0,0 +1,170 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command utilities for `gcloud dns dns-keys`."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import encoding
from googlecloudsdk.api_lib.dns import dns_keys
from googlecloudsdk.api_lib.dns import util
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dns import flags
import six
ALGORITHM_NUMBERS = {
'rsamd5': 1,
'dh': 2,
'dsa': 3,
'rsasha1': 5,
'dsansec3sha1': 6,
'rsasha1nsec3sha1': 7,
'rsasha256': 8,
'rsasha512': 10,
'eccgost': 12,
'ecdsap256sha256': 13,
'ecdsap384sha384': 14,
}
DIGEST_TYPE_NUMBERS = {
'sha1': 1,
'sha256': 2,
'sha384': 4,
}
def _GenerateDSRecord(key):
key_tag = six.text_type(key.keyTag)
key_algorithm = six.text_type(ALGORITHM_NUMBERS[key.algorithm.name])
digest_algorithm = six.text_type(
DIGEST_TYPE_NUMBERS[key.digests[0].type.name])
digest = key.digests[0].digest
return ' '.join([key_tag, key_algorithm, digest_algorithm, digest])
def TransformDSRecord(r, undefined=''):
messages = apis.GetMessagesModule('dns', 'v1')
key = encoding.DictToMessage(r, messages.DnsKey)
try:
return _GenerateDSRecord(key)
except AttributeError:
return undefined
_TRANSFORMS = {'ds_record': TransformDSRecord}
def GetTransforms():
return _TRANSFORMS
DESCRIBE_HELP = {
'brief': 'Show details about a DNS key resource.',
'DESCRIPTION': ('This command displays the details of a single DNS key '
'resource.'),
'EXAMPLES': """\
To show details about a DNS key resource with ID 3 in a managed zone
`my_zone`, run:
$ {command} --zone=my_zone 3
To get the DS record corresponding for the DNSKEY record from the
previous example, run (the DNSKEY record must be for a key-signing key):
$ {command} --zone=my_zone 3 --format='value(ds_record())'
"""
}
def AddDescribeFlags(parser, hide_short_zone_flag=False, is_beta=False):
flags.GetZoneArg(
'The name of the managed-zone the DNSKEY record belongs to',
hide_short_zone_flag=hide_short_zone_flag).AddToParser(parser)
flags.GetKeyArg(is_beta=is_beta).AddToParser(parser)
parser.display_info.AddTransforms(GetTransforms())
LIST_HELP = {
'brief': 'List DNS key resources.',
'DESCRIPTION': 'List DNS key resources in a managed zone.',
'EXAMPLES': """\
To see the list of all DNS key resources for a managed zone `my_zone`,
run:
$ {command} --zone=my_zone
To see the DS records for every key-signing DnsKey in a managed zone,
run:
$ {command} --zone=my_zone --filter='type=keySigning' \
--format='value(ds_record())'
"""
}
def AddListFlags(parser, hide_short_zone_flag=False):
parser.display_info.AddFormat('table(id,keyTag,type,isActive,description)')
base.URI_FLAG.RemoveFromParser(parser)
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
flags.GetZoneArg(
'The name of the managed-zone you want to list DNSKEY records for.',
hide_short_zone_flag=hide_short_zone_flag).AddToParser(parser)
parser.display_info.AddCacheUpdater(None)
parser.display_info.AddTransforms(GetTransforms())
class Keys(object):
"""Wrapper object for DNS DNSKEYs commands."""
def __init__(self, keys_client, version):
self._keys_client = keys_client
self._version = version
def _GetRegistry(self):
return util.GetRegistry(self._version)
def _ParseDnsKey(self, key_id, zone, project):
return self._GetRegistry().Parse(
key_id,
params={
'project': project,
'managedZone': zone
},
collection='dns.dnsKeys')
def _ParseZone(self, zone_id, project):
return self._GetRegistry().Parse(
zone_id,
params={
'project': project,
},
collection='dns.managedZones')
def Describe(self, key_id, zone, project):
"""Calls Get on the DNS DnsKeys API with the given parameters."""
key_ref = self._ParseDnsKey(key_id, zone, project)
return self._keys_client.Get(key_ref)
def List(self, zone_id, project):
zone_ref = self._ParseZone(zone_id, project)
return self._keys_client.List(zone_ref)
@classmethod
def FromApiVersion(cls, version):
return cls(dns_keys.Client.FromApiVersion(version), version)

View File

@@ -0,0 +1,170 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Shared resource flags for Cloud DNS commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.calliope.concepts import deps
from googlecloudsdk.command_lib.util import completers
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.core import properties
class PolicyCompleter(completers.ListCommandCompleter):
def __init__(self, api_version, **kwargs):
super(PolicyCompleter, self).__init__(
collection='dns.policies',
api_version=api_version,
list_command='alpha dns policies list --format=value(name)',
parse_output=True,
**kwargs)
def PolicyAttributeConfig(api_version):
return concepts.ResourceParameterAttributeConfig(
name='policy',
completer=PolicyCompleter(api_version=api_version),
help_text='The Cloud DNS policy name {resource}.')
def ResponsePolicyAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='response-policy',
help_text='The Cloud DNS response policy name {resource}.')
def ResponsePolicyRuleAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='response-policy-rule',
help_text='The Cloud DNS response policy rule name {resource}.')
def ProjectAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='project',
help_text='The Cloud project for the {resource}.',
fallthroughs=[deps.PropertyFallthrough(properties.VALUES.core.project)])
def GetPolicyResourceSpec(api_version):
return concepts.ResourceSpec(
'dns.policies',
api_version=api_version,
resource_name='policy',
policy=PolicyAttributeConfig(api_version=api_version),
project=ProjectAttributeConfig())
def GetResponsePolicyResourceSpec(api_version):
return concepts.ResourceSpec(
'dns.responsePolicies',
api_version=api_version,
resource_name='response_policy',
responsePolicy=ResponsePolicyAttributeConfig(),
project=ProjectAttributeConfig())
def GetResponsePolicyRuleSpec(api_version):
return concepts.ResourceSpec(
'dns.responsePolicyRules',
api_version=api_version,
resource_name='response_policy_rule',
responsePolicy=ResponsePolicyAttributeConfig(),
responsePolicyRule=ResponsePolicyRuleAttributeConfig(),
project=ProjectAttributeConfig())
def AddPolicyResourceArg(parser,
verb,
api_version,
positional=True,
required=True):
"""Add a resource argument for a Cloud DNS Policy.
Args:
parser: the parser for the command.
verb: str, the verb to describe the resource, such as 'to update'.
api_version: str, the version of the API to use.
positional: bool, if True, means that the policy name is a positional rather
than a flag.
required: bool, if True, means that the arg will be required.
"""
if positional:
name = 'policy'
else:
name = '--policy'
concept_parsers.ConceptParser.ForResource(
name,
GetPolicyResourceSpec(api_version),
'The policy {}.'.format(verb),
required=required).AddToParser(parser)
def AddResponsePolicyResourceArg(parser,
verb,
api_version,
positional=True,
required=True):
"""Add a resource argument for a Cloud DNS Response Policy.
Args:
parser: the parser for the command.
verb: str, the verb to describe the resource, such as 'to update'.
api_version: str, the version of the API to use.
positional: bool, if True, means that the policy name is a positional rather
than a flag.
required: bool, if True, means that the arg will be required.
"""
if positional:
name = 'response_policies'
else:
name = '--response_policies'
concept_parsers.ConceptParser.ForResource(
name,
GetResponsePolicyResourceSpec(api_version),
'The response policy {}.'.format(verb),
required=required).AddToParser(parser)
def AddResponsePolicyRuleArg(parser,
verb,
api_version,
positional=True,
required=True):
"""Add a resource argument for a Cloud DNS Policy Rule.
Args:
parser: the parser for the command.
verb: str, the verb to describe the resource, such as 'to update'.
api_version: str, the version of the API to use.
positional: bool, if True, means that the policy name is a positional rather
than a flag.
required: bool, if True, means that the arg will be required.
"""
if positional:
name = 'response_policy_rule'
else:
name = '--response_policy_rule'
concept_parsers.ConceptParser.ForResource(
name,
GetResponsePolicyRuleSpec(api_version),
'The response policy rule {}.'.format(verb),
flag_name_overrides={'response-policy-rule': 'response_policy_rule'},
required=required).AddToParser(parser)

View File

@@ -0,0 +1,67 @@
project:
name: project
collection: dns.projects
request_id_field: project.name
attributes:
- &project
parameter_name: project
attribute_name: project
help: The project name.
policy:
name: policy
collection: dns.policies
request_id_field: policy.name
attributes:
- &policy
parameter_name: policy
attribute_name: policy
help: The policy name.
response_policy:
name: response policy
collection: dns.responsePolicies
request_id_field: response_policy.response_policy_name
attributes:
- &responsePolicy
parameter_name: responsePolicy
attribute_name: response_policy
help: The response policy name.
response_policy_rule:
name: response policy rule
collection: dns.responsePolicyRules
request_id_field: response_policy_rule.rule_name
attributes:
- parameter_name: responsePolicy
attribute_name: response-policy
help: The response policy name.
- &responsePolicyRule
parameter_name: responsePolicyRule
attribute_name: response_policy_rule
help: The response policy rule name.
managed_zone:
name: managed_zone
collection: dns.managedZones
attributes:
- *project
- &managedZone
parameter_name: managedZone
attribute_name: managed_zone
help: The ID of the managed zone.
resource_record_set:
name: record set
collection: dns.resourceRecordSets
attributes:
- *project
- parameter_name: managedZone
attribute_name: managed-zone
help: The ID of the managed zone.
- parameter_name: name
attribute_name: dns_name
help: The DNS name of the record set.
- parameter_name: type
attribute_name: type
help: The DNS record type of the record set.

View File

@@ -0,0 +1,478 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Helper functions for DNS commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dns import util as api_util
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.command_lib.dns import flags
import ipaddr
def IsIPv4(ip: str) -> bool:
"""Returns True if ip is an IPv4."""
try:
ipaddr.IPv4Address(ip)
return True
except ValueError:
return False
def IsIPv6(ip: str) -> bool:
"""Returns True if ip is an IPv6."""
try:
ipaddr.IPv6Address(ip)
return True
except ValueError:
return False
def ParseKey(algorithm, key_length, key_type, messages):
"""Generate a keyspec from the given (unparsed) command line arguments.
Args:
algorithm: (str) String mnemonic for the DNSSEC algorithm to be specified in
the keyspec; must be a value from AlgorithmValueValuesEnum.
key_length: (int) The key length value to include in the keyspec.
key_type: (KeyTypeValueValuesEnum) Enum value for whether to create a
keyspec for a KSK or a ZSK.
messages: (module) Module (generally auto-generated by the API build rules)
containing the API client's message classes.
Returns:
A messages.DnsKeySpec instance created from the given arguments.
"""
key_spec = None
if algorithm is not None or key_length is not None:
spec_args = {}
spec_args['keyType'] = key_type
if algorithm is not None:
spec_args['algorithm'] = messages.DnsKeySpec.AlgorithmValueValuesEnum(
algorithm)
if key_length is not None:
spec_args['keyLength'] = key_length
if spec_args:
key_spec = messages.DnsKeySpec(**spec_args)
return key_spec
def ParseDnssecConfigArgs(args, messages, api_version='v1'):
# TODO(b/215745011) Clean up this function once move to v2
"""Parse all relevant command line arguments and generate a DNSSEC config.
Args:
args: (dict{str,(str|int)}) Dict of command line arguments; value type
dependent on particular command line argument.
messages: (module) Module (generally auto-generated by the API build rules)
containing the API client's message classes.
api_version: api_version that this function should use.
Returns:
A messages.ManagedZoneDnsSecConfig instance populated from the given
command line arguments.
"""
dnssec_config = None
key_specs = []
ksk_algorithm = None
if args.ksk_algorithm:
ksk_algorithm = flags.GetKeyAlgorithmFlagMapper(
'ksk',
messages,
).GetEnumForChoice(args.ksk_algorithm)
zsk_algorithm = None
if args.zsk_algorithm:
zsk_algorithm = flags.GetKeyAlgorithmFlagMapper(
'zsk',
messages,
).GetEnumForChoice(args.zsk_algorithm)
if api_version == 'v2':
key_enum = messages.DnsKeySpec.KeyTypeValueValuesEnum.KEY_SIGNING
else:
key_enum = messages.DnsKeySpec.KeyTypeValueValuesEnum.keySigning
ksk_key = ParseKey(ksk_algorithm, args.ksk_key_length, key_enum, messages)
if ksk_key is not None:
key_specs.append(ksk_key)
if api_version == 'v2':
key_enum = messages.DnsKeySpec.KeyTypeValueValuesEnum.ZONE_SIGNING
else:
key_enum = messages.DnsKeySpec.KeyTypeValueValuesEnum.zoneSigning
zsk_key = ParseKey(zsk_algorithm, args.zsk_key_length, key_enum, messages)
if zsk_key is not None:
key_specs.append(zsk_key)
dnssec_config_args = {}
if key_specs:
dnssec_config_args['defaultKeySpecs'] = key_specs
if getattr(args, 'denial_of_existence', None) is not None:
dnssec_config_args['nonExistence'] = (
flags.GetDoeFlagMapper(messages).GetEnumForChoice(
args.denial_of_existence))
if args.dnssec_state is not None:
dnssec_config_args['state'] = flags.GetDnsSecStateFlagMapper(
messages, api_version
).GetEnumForChoice(args.dnssec_state)
if dnssec_config_args:
dnssec_config = messages.ManagedZoneDnsSecConfig(**dnssec_config_args)
return dnssec_config
def ParseManagedZoneForwardingConfigWithForwardingPath(
messages, server_list=None, private_server_list=None):
"""Parses list of forwarding nameservers into ManagedZoneForwardingConfig.
Args:
messages: (module) Module (generally auto-generated by the API build rules)
containing the API client's message classes.
server_list: (list) List of IP addresses to use as forwarding targets for
the DNS Managed Zone that uses default forwarding logic (based on RFC1918
check).
private_server_list: (list) List of IP addresses to use as forwarding
targets for the DNS Managed Zone that always use the private VPC path.
Returns:
A messages.ManagedZoneForwardingConfig instance populated from the given
command line arguments.
"""
target_servers = []
default_enum = messages.ManagedZoneForwardingConfigNameServerTarget.ForwardingPathValueValuesEnum(
0)
private_enum = messages.ManagedZoneForwardingConfigNameServerTarget.ForwardingPathValueValuesEnum(
1)
if server_list is not None:
for name in server_list:
if IsIPv4(name):
target_servers.append(
messages.ManagedZoneForwardingConfigNameServerTarget(
ipv4Address=name, ipv6Address=None, forwardingPath=default_enum
)
)
elif IsIPv6(name):
target_servers.append(
messages.ManagedZoneForwardingConfigNameServerTarget(
ipv4Address=None, ipv6Address=name, forwardingPath=default_enum
)
)
else:
target_servers.append(
messages.ManagedZoneForwardingConfigNameServerTarget(
ipv4Address=None,
ipv6Address=None,
domainName=name,
forwardingPath=default_enum,
)
)
if private_server_list is not None:
for name in private_server_list:
if IsIPv4(name):
target_servers.append(
messages.ManagedZoneForwardingConfigNameServerTarget(
ipv4Address=name, ipv6Address=None,
forwardingPath=private_enum))
elif IsIPv6(name):
target_servers.append(
messages.ManagedZoneForwardingConfigNameServerTarget(
ipv4Address=None, ipv6Address=name,
forwardingPath=private_enum))
else:
target_servers.append(
messages.ManagedZoneForwardingConfigNameServerTarget(
ipv4Address=None,
ipv6Address=None,
domainName=name,
forwardingPath=private_enum,
)
)
return messages.ManagedZoneForwardingConfig(targetNameServers=target_servers)
def PolicyNetworkProcessor(parsed_value, version='v1'):
"""Build PolicyNetwork message from parsed_value."""
# Parsed Value should be a list of compute.network resources
messages = GetMessages(version)
if not parsed_value:
return []
return [
messages.PolicyNetwork(networkUrl=network_ref.SelfLink())
for network_ref in parsed_value
]
def BetaPolicyNetworkProcessor(parsed_value):
"""Build Beta PolicyNetwork message from parsed_value."""
# Parsed Value should be a list of compute.network resources
return PolicyNetworkProcessor(parsed_value, version='v1beta2')
def ResponsePolicyNetworkProcessor(parsed_value, version='v1'):
"""Build PolicyNetwork message from parsed_value."""
# Parsed value should be a list of compute.network resources
messages = GetMessages(version)
if not parsed_value:
return []
return [
messages.ResponsePolicyNetwork(networkUrl=network_ref.SelfLink())
for network_ref in parsed_value
]
def TargetNameServerType(value, version='v1'):
"""Build a single TargetNameServer based on 'value'.
Args:
value: (str) A string representation of an IPV4 ip address representing the
PrivateTargetNameServer.
version: (str) A string indicating the version of the API to be used, should
be 'v1' only before removing BetaTargetNameServerType.
Returns:
A messages.PolicyAlternativeNameServerConfigTargetNameServer instance
populated from the given ip address.
"""
messages = GetMessages(version)
if IsIPv4(value):
return messages.PolicyAlternativeNameServerConfigTargetNameServer(
ipv4Address=value,
ipv6Address=None,
forwardingPath=messages.PolicyAlternativeNameServerConfigTargetNameServer.ForwardingPathValueValuesEnum(
0
),
)
else:
return messages.PolicyAlternativeNameServerConfigTargetNameServer(
ipv4Address=None,
ipv6Address=value,
forwardingPath=messages.PolicyAlternativeNameServerConfigTargetNameServer.ForwardingPathValueValuesEnum(
0
),
)
def BetaTargetNameServerType(value, version='v1beta2'):
"""Build a single TargetNameServer based on 'value'.
Args:
value: (str) A string representation of an IPV4 ip address representing the
PrivateTargetNameServer.
version: (str) A string indicating the version of the API to be used, should
be one of 'v1beta2' or 'v1alpha2'. This function will be removed after
promoting v6 address to GA.
Returns:
A messages.PolicyAlternativeNameServerConfigTargetNameServer instance
populated from the given ip address.
"""
messages = GetMessages(version)
if IsIPv4(value):
return messages.PolicyAlternativeNameServerConfigTargetNameServer(
ipv4Address=value,
ipv6Address=None,
forwardingPath=messages
.PolicyAlternativeNameServerConfigTargetNameServer
.ForwardingPathValueValuesEnum(0))
else:
return messages.PolicyAlternativeNameServerConfigTargetNameServer(
ipv4Address=None,
ipv6Address=value,
forwardingPath=messages
.PolicyAlternativeNameServerConfigTargetNameServer
.ForwardingPathValueValuesEnum(0))
def PrivateTargetNameServerType(value, version='v1'):
"""Build a single PrivateTargetNameServer based on 'value'.
Args:
value: (str) A string representation of an IPV4 ip address representing the
PrivateTargetNameServer.
version: (str) A string indicating the version of the API to be used, should
be 'v1' only before removing BetaPrivateTargetNameServerType.
Returns:
A messages.PolicyAlternativeNameServerConfigTargetNameServer instance
populated from the given ip address.
"""
messages = GetMessages(version)
if IsIPv4(value):
return messages.PolicyAlternativeNameServerConfigTargetNameServer(
ipv4Address=value,
ipv6Address=None,
forwardingPath=messages.PolicyAlternativeNameServerConfigTargetNameServer.ForwardingPathValueValuesEnum(
1
),
)
else:
return messages.PolicyAlternativeNameServerConfigTargetNameServer(
ipv4Address=None,
ipv6Address=value,
forwardingPath=messages.PolicyAlternativeNameServerConfigTargetNameServer.ForwardingPathValueValuesEnum(
1
),
)
def BetaPrivateTargetNameServerType(value, version='v1beta2'):
"""Build a single PrivateTargetNameServer based on 'value'.
Args:
value: (str) A string representation of an IPV4 ip address representing the
PrivateTargetNameServer.
version: (str) A string indicating the version of the API to be used, should
be one of 'v1beta2' or 'v1alpha2'. This function will be removed after
promoting v6 address to GA.
Returns:
A messages.PolicyAlternativeNameServerConfigTargetNameServer instance
populated from the given ip address.
"""
messages = GetMessages(version)
if IsIPv4(value):
return messages.PolicyAlternativeNameServerConfigTargetNameServer(
ipv4Address=value,
ipv6Address=None,
forwardingPath=messages
.PolicyAlternativeNameServerConfigTargetNameServer
.ForwardingPathValueValuesEnum(1))
else:
return messages.PolicyAlternativeNameServerConfigTargetNameServer(
ipv4Address=None,
ipv6Address=value,
forwardingPath=messages
.PolicyAlternativeNameServerConfigTargetNameServer
.ForwardingPathValueValuesEnum(1))
def ParsePolicyNetworks(value, project, version):
"""Build a list of PolicyNetworks from command line args."""
networks = ParseNetworks(value, project, version)
return PolicyNetworkProcessor(networks, version)
def ParseNetworks(value, project, version):
"""Build a list of PolicyNetworks or ResponsePolicyNetworks from command line args."""
if not value:
return []
registry = api_util.GetRegistry(version)
networks = [
registry.Parse(
network_name,
collection='compute.networks',
params={'project': project}) for network_name in value
]
return networks
def ParseResponsePolicyNetworks(value, project, version):
"""Build a list of ResponsePolicyNetworks from command line args."""
networks = ParseNetworks(value, project, version)
return ResponsePolicyNetworkProcessor(networks, version)
def ParseAltNameServers(version, server_list=None, private_server_list=None):
"""Parses list of alternative nameservers into AlternativeNameServerConfig.
Args:
version: (str) A string indicating the version of the API to be used, should
be 'v1' only before removing BetaParseAltNameServers.
server_list: (Sequence) List of IP addresses to use as forwarding targets
for the DNS managed zone that uses default forwarding logic.
private_server_list: (Sequence) List of IP addresses to use as forwarding
targets for the DNS Managed Zone that always uses the private VPC path.
Returns:
A messages.PolicyAlternativeNameServerConfig instance populated from the
given command line arguments.Only the not none server list will be parsed
and
an empty list will be returned if both are none.
"""
if not server_list and not private_server_list:
return None
messages = GetMessages(version)
result_list = []
if server_list:
result_list += [TargetNameServerType(ip, version) for ip in server_list]
if private_server_list:
result_list += [
PrivateTargetNameServerType(ip, version) for ip in private_server_list
]
return messages.PolicyAlternativeNameServerConfig(
targetNameServers=result_list)
def BetaParseAltNameServers(version,
server_list=None,
private_server_list=None):
"""Parses list of alternative nameservers into AlternativeNameServerConfig.
Args:
version: (str) A string indicating the version of the API to be used, should
be one of 'v1beta2' or 'v1alpha2'. This function will be moved after
promoting v6 address to GA.
server_list: (Sequence) List of IP addresses to use as forwarding targets
for the DNS Managed Zone that uses default forwarding logic.
private_server_list: (Sequence) List of IP addresses to use as forwarding
targets for the DNS Managed Zone that always uses the private VPC path.
Returns:
A messages.PolicyAlternativeNameServerConfig instance populated from the
given command line arguments.Only the not none server list will be parsed
and
an empty list will be returned if both are none.
"""
if not server_list and not private_server_list:
return None
messages = GetMessages(version)
result_list = []
if server_list:
result_list += [BetaTargetNameServerType(ip, version) for ip in server_list]
if private_server_list:
result_list += [
BetaPrivateTargetNameServerType(ip, version)
for ip in private_server_list
]
return messages.PolicyAlternativeNameServerConfig(
targetNameServers=result_list)
def ParseResponsePolicyRulesBehavior(args, version='v1'):
"""Parses response policy rule behavior."""
m = GetMessages(version)
if args.behavior == 'bypassResponsePolicy':
return m.ResponsePolicyRule.BehaviorValueValuesEnum.BYPASS_RESPONSE_POLICY if version == 'v2' else m.ResponsePolicyRule.BehaviorValueValuesEnum.bypassResponsePolicy
else:
return None
# TODO(b/215745011) Use this once GCloud is migrated to v2
# return flags.GetResponsePolicyRulesBehaviorFlagMapper(
# messages).GetEnumForChoice(args.behavior)
def GetMessages(version='v1'):
return apis.GetMessagesModule('dns', version)