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,98 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""The gcloud run domain-mappings group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import exceptions
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.command_lib.run import platforms
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class DomainMappings(base.Group):
"""View and manage your Cloud Run for Anthos domain mappings.
This set of commands can be used to view and manage your service's domain
mappings.
To view and manage fully managed Cloud Run domain mappings, use
`gcloud beta run domain-mappings`.
"""
# Hide GA command because only used by Cloud Run for Anthos
hidden = True
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To list your Cloud Run domain mappings, run:
$ {command} list
""",
}
@staticmethod
def Args(parser):
"""Adds --platform and the various related args."""
flags.AddPlatformAndLocationFlags(parser, anthos_only=True)
def Filter(self, context, args):
"""Runs before command.Run and validates platform with passed args."""
# Ensures a platform is set on the run/platform property and
# all other passed args are valid for this platform and release track.
flags.GetAndValidatePlatform(args, self.ReleaseTrack(), flags.Product.RUN)
self._CheckPlatform()
return context
def _CheckPlatform(self):
if platforms.GetPlatform() == platforms.PLATFORM_MANAGED:
raise exceptions.PlatformError(
'This command group is in beta for fully managed Cloud Run; '
'use `gcloud beta run domain-mappings`.')
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class DomainMappingsBeta(base.Group):
"""View and manage your Cloud Run domain mappings.
This set of commands can be used to view and manage your service's domain
mappings.
"""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To list your Cloud Run domain mappings, run:
$ {command} list
""",
}
@staticmethod
def Args(parser):
"""Adds --platform and the various related args."""
flags.AddPlatformAndLocationFlags(parser)
def _CheckPlatform(self):
pass

View File

@@ -0,0 +1,174 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Surface for creating domain mappings."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.run import global_methods
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import config_changes
from googlecloudsdk.command_lib.run import connection_context
from googlecloudsdk.command_lib.run import deletion
from googlecloudsdk.command_lib.run import exceptions
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.command_lib.run import platforms
from googlecloudsdk.command_lib.run import resource_args
from googlecloudsdk.command_lib.run import serverless_operations
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
from googlecloudsdk.core.console import console_io
DOMAIN_MAPPINGS_HELP_DOCS_URL = ('https://cloud.google.com/run/docs/'
'mapping-custom-domains/')
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.Command):
"""Create domain mappings for Cloud Run for Anthos."""
# Hide GA command because only used by Cloud Run for Anthos
hidden = True
detailed_help = {
'DESCRIPTION':
"""\
{description}
For domain mapping support with fully managed Cloud Run, use
`gcloud beta run domain-mappings create`.
""",
'EXAMPLES':
"""\
To create a Cloud Run domain mapping, run:
$ {command} --service=myapp --domain=www.example.com
""",
}
@staticmethod
def CommonArgs(parser):
parser.add_argument(
'--service', required=True,
help='Create domain mapping for the given service.')
domain_mapping_presentation = presentation_specs.ResourcePresentationSpec(
'--domain',
resource_args.GetDomainMappingResourceSpec(),
'Domain name is the ID of DomainMapping resource.',
required=True,
prefixes=False)
parser.add_argument(
'--force-override',
action='store_true',
help='Map this domain even if it is already mapped to another service.'
)
concept_parsers.ConceptParser([
domain_mapping_presentation]).AddToParser(parser)
parser.display_info.AddFormat(
"""table(
name:label=NAME,
type:label="RECORD TYPE",
rrdata:label=CONTENTS)""")
@staticmethod
def Args(parser):
Create.CommonArgs(parser)
def Run(self, args):
"""Create a domain mapping."""
# domains.cloudrun.com api group only supports v1alpha1 on clusters.
conn_context = connection_context.GetConnectionContext(
args,
flags.Product.RUN,
self.ReleaseTrack(),
version_override=('v1alpha1' if
platforms.GetPlatform() != platforms.PLATFORM_MANAGED
else None))
domain_mapping_ref = args.CONCEPTS.domain.Parse()
changes = [
config_changes.SetLaunchStageAnnotationChange(self.ReleaseTrack())
]
# Check if the provided domain has already been verified
# if mapping to a non-CRoGKE service
if platforms.GetPlatform() == platforms.PLATFORM_MANAGED:
client = global_methods.GetServerlessClientInstance()
all_domains = global_methods.ListVerifiedDomains(client)
# If not already verified, explain and error out
if all(d.id not in domain_mapping_ref.Name() for d in all_domains):
if not all_domains:
domains_text = 'You currently have no verified domains.'
else:
domains = ['* {}'.format(d.id) for d in all_domains]
domains_text = ('Currently verified domains:\n{}'.format(
'\n'.join(domains)))
raise exceptions.DomainMappingCreationError(
'The provided domain does not appear to be verified '
'for the current account so a domain mapping '
'cannot be created. Visit [{help}] for more information.'
'\n{domains}'.format(
help=DOMAIN_MAPPINGS_HELP_DOCS_URL, domains=domains_text))
with serverless_operations.Connect(conn_context) as client:
try:
mapping = client.CreateDomainMapping(domain_mapping_ref, args.service,
changes, args.force_override)
except exceptions.DomainMappingAlreadyExistsError as e:
if console_io.CanPrompt() and console_io.PromptContinue(
('This domain is already being used as a mapping elsewhere. '
'The existing mapping can be overriden by passing '
'`--force-override` or by continuing at the prompt below.'),
prompt_string='Override the existing mapping'):
deletion.Delete(domain_mapping_ref, client.GetDomainMapping,
client.DeleteDomainMapping, async_=False)
mapping = client.CreateDomainMapping(domain_mapping_ref, args.service,
changes, True)
else:
raise e
for record in mapping.records:
record.name = record.name or mapping.route_name
return mapping.records
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaCreate(Create):
"""Create domain mappings."""
detailed_help = {
'DESCRIPTION': '{description}',
'EXAMPLES':
"""\
To create a Cloud Run domain mapping, run:
$ {command} --service=myapp --domain=www.example.com
""",
}
@staticmethod
def Args(parser):
Create.CommonArgs(parser)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaCreate(BetaCreate):
"""Create domain mappings."""
@staticmethod
def Args(parser):
Create.CommonArgs(parser)

View File

@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Surface for deleting domain mappings."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import connection_context
from googlecloudsdk.command_lib.run import deletion
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.command_lib.run import platforms
from googlecloudsdk.command_lib.run import pretty_print
from googlecloudsdk.command_lib.run import resource_args
from googlecloudsdk.command_lib.run import serverless_operations
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Delete(base.Command):
"""Delete domain mappings for Cloud Run for Anthos."""
# Hide GA command because only used by Cloud Run for Anthos
hidden = True
detailed_help = {
'DESCRIPTION':
"""\
{description}
For domain mapping support with fully managed Cloud Run, use
`gcloud beta run domain-mappings delete`.
""",
'EXAMPLES':
"""\
To delete a Cloud Run domain mapping, run:
$ {command} --domain=www.example.com
""",
}
@staticmethod
def CommonArgs(parser):
domain_mapping_presentation = presentation_specs.ResourcePresentationSpec(
'--domain',
resource_args.GetDomainMappingResourceSpec(),
'Domain name is the ID of DomainMapping resource.',
required=True,
prefixes=False)
concept_parsers.ConceptParser([domain_mapping_presentation
]).AddToParser(parser)
flags.AddAsyncFlag(parser, default_async_for_cluster=True)
@staticmethod
def Args(parser):
Delete.CommonArgs(parser)
def Run(self, args):
"""Delete domain mappings."""
# domains.cloudrun.com api group only supports v1alpha1 on clusters.
conn_context = connection_context.GetConnectionContext(
args,
flags.Product.RUN,
self.ReleaseTrack(),
version_override=('v1alpha1' if
platforms.GetPlatform() != platforms.PLATFORM_MANAGED
else None))
domain_mapping_ref = args.CONCEPTS.domain.Parse()
with serverless_operations.Connect(conn_context) as client:
async_ = deletion.AsyncOrDefault(args.async_)
deletion.Delete(
domain_mapping_ref,
client.GetDomainMapping,
client.DeleteDomainMapping,
async_,
)
msg = """Mappings to [{domain}] now have been deleted.""".format(
domain=domain_mapping_ref.domainmappingsId)
if async_:
msg = """Mappings to [{domain}] are being deleted.""".format(
domain=domain_mapping_ref.domainmappingsId
)
pretty_print.Success(msg)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaDelete(Delete):
"""Delete domain mappings."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To delete a Cloud Run domain mapping, run:
$ {command} --domain=www.example.com
""",
}
@staticmethod
def Args(parser):
Delete.CommonArgs(parser)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaDelete(BetaDelete):
"""Delete domain mappings."""
@staticmethod
def Args(parser):
Delete.CommonArgs(parser)

View File

@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Surface for creating domain mappings."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import connection_context
from googlecloudsdk.command_lib.run import exceptions
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.command_lib.run import platforms
from googlecloudsdk.command_lib.run import resource_args
from googlecloudsdk.command_lib.run import serverless_operations
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.Command):
"""Describe domain mappings for Cloud Run for Anthos."""
# Hide GA command because only used by Cloud Run for Anthos
hidden = True
detailed_help = {
'DESCRIPTION':
"""\
{description}
For domain mapping support with fully managed Cloud Run, use
`gcloud beta run domain-mappings describe`.""",
'EXAMPLES':
"""\
To describe a Cloud Run domain mapping, run:
$ {command} --domain=www.example.com
""",
}
@staticmethod
def CommonArgs(parser):
domain_mapping_presentation = presentation_specs.ResourcePresentationSpec(
'--domain',
resource_args.GetDomainMappingResourceSpec(),
'Domain name is the ID of DomainMapping resource.',
required=True,
prefixes=False)
concept_parsers.ConceptParser([
domain_mapping_presentation]).AddToParser(parser)
parser.display_info.AddFormat('yaml')
@staticmethod
def Args(parser):
Describe.CommonArgs(parser)
def Run(self, args):
"""Describe a domain mapping."""
# domains.cloudrun.com api group only supports v1alpha1 on clusters.
conn_context = connection_context.GetConnectionContext(
args,
flags.Product.RUN,
self.ReleaseTrack(),
version_override=('v1alpha1' if
platforms.GetPlatform() != platforms.PLATFORM_MANAGED
else None))
domain_mapping_ref = args.CONCEPTS.domain.Parse()
with serverless_operations.Connect(conn_context) as client:
domain_mapping = client.GetDomainMapping(domain_mapping_ref)
if not domain_mapping:
raise exceptions.ArgumentError(
'Cannot find domain mapping for domain name [{}]'.format(
domain_mapping_ref.domainmappingsId))
return domain_mapping
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaDescribe(Describe):
"""Describe domain mappings."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To describe a Cloud Run domain mapping, run:
$ {command} --domain=www.example.com
""",
}
@staticmethod
def Args(parser):
Describe.CommonArgs(parser)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaDescribe(BetaDescribe):
"""Describe domain mappings."""
@staticmethod
def Args(parser):
Describe.CommonArgs(parser)

View File

@@ -0,0 +1,128 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Surface for listing all domain mappings."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import commands
from googlecloudsdk.command_lib.run import connection_context
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.command_lib.run import platforms
from googlecloudsdk.command_lib.run import pretty_print
from googlecloudsdk.command_lib.run import resource_args
from googlecloudsdk.command_lib.run import serverless_operations
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(commands.List):
"""Lists domain mappings for Cloud Run for Anthos."""
# Hide GA command because only used by Cloud Run for Anthos
hidden = True
detailed_help = {
'DESCRIPTION':
"""\
{description}
For domain mapping support with fully managed Cloud Run, use
`gcloud beta run domain-mappings list`.""",
'EXAMPLES':
"""\
To list all Cloud Run domain mappings, run:
$ {command}
""",
}
@classmethod
def CommonArgs(cls, parser):
# Flags specific to connecting to a cluster
namespace_presentation = presentation_specs.ResourcePresentationSpec(
'--namespace',
resource_args.GetNamespaceResourceSpec(),
'Namespace to list domain mappings in.',
required=True,
prefixes=False,
hidden=True,
)
concept_parsers.ConceptParser(
[namespace_presentation]).AddToParser(parser)
parser.display_info.AddFormat(
"""table(
{ready_column},
metadata.name:label=DOMAIN,
route_name:label=SERVICE,
region:label=REGION):({alias})""".format(
ready_column=pretty_print.READY_COLUMN,
alias=commands.SATISFIES_PZS_ALIAS,
)
)
parser.display_info.AddUriFunc(cls._GetResourceUri)
@classmethod
def Args(cls, parser):
cls.CommonArgs(parser)
def Run(self, args):
"""List available domain mappings."""
# domains.cloudrun.com api group only supports v1alpha1 on clusters.
conn_context = connection_context.GetConnectionContext(
args,
flags.Product.RUN,
self.ReleaseTrack(),
version_override=('v1alpha1' if
platforms.GetPlatform() != platforms.PLATFORM_MANAGED
else None))
namespace_ref = args.CONCEPTS.namespace.Parse()
with serverless_operations.Connect(conn_context) as client:
self.SetCompleteApiEndpoint(conn_context.endpoint)
return commands.SortByName(client.ListDomainMappings(namespace_ref))
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaList(List):
"""Lists domain mappings."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To list all Cloud Run domain mappings, run:
$ {command}
""",
}
@classmethod
def Args(cls, parser):
cls.CommonArgs(parser)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaList(BetaList):
"""Lists domain mappings."""
@classmethod
def Args(cls, parser):
cls.CommonArgs(parser)