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,77 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 integrations group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from typing import cast
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import platforms
from googlecloudsdk.command_lib.runapps import exceptions
from googlecloudsdk.command_lib.runapps import flags
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA,
base.ReleaseTrack.BETA)
@base.Deprecate(
is_removed=True,
error='Cloud Run integrations are no longer supported.'
)
@base.DefaultUniverseOnly
class Integrations(base.Group):
"""View and manage your Cloud Run (fully managed) integrations.
This set of commands can be used to view and manage your Cloud Run
integrations.
"""
detailed_help = {
'EXAMPLES': """
To list your existing integrations, run:
$ {command} list
""",
}
@staticmethod
def Args(parser):
"""Adds --region flag."""
flags.AddRegionArg(parser)
def Filter(self, context, args):
"""Runs before command.Run and validates platform with passed args.
Args:
context: {str:object}, A set of key-value pairs that can be used for
common initialization among commands.
args: argparse.Namespace: The same namespace given to the corresponding
.Run() invocation.
Returns:
The updated context
"""
del args # Unused argument
self._CheckPlatform()
return context
def _CheckPlatform(self):
platform = platforms.GetPlatform()
if platform != platforms.PLATFORM_MANAGED:
raise exceptions.PlatformError(
'This command group is only supported for Cloud Run (fully managed).')

View File

@@ -0,0 +1,130 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 for creating or replacing an application from YAML specification."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.run.integrations import types_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import pretty_print
from googlecloudsdk.command_lib.run.integrations import deprecation_util
from googlecloudsdk.command_lib.run.integrations import flags
from googlecloudsdk.command_lib.run.integrations import messages_util
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
from googlecloudsdk.command_lib.runapps import exceptions
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class Create(base.Command):
"""Create a Cloud Run Integration."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create and attach a redis instance to a Cloud Run service
$ {command} --type=redis --service=myservice
To attach a custom domain to a Cloud Run service
$ {command} --type=custom-domains --parameters='set-mapping=example.com/*:myservice'
""",
}
@classmethod
def Args(cls, parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
flags.AddTypeArg(parser)
flags.AddNameArg(parser)
flags.AddServiceCreateArg(parser)
flags.AddParametersArg(parser)
flags.AddServiceAccountArg(parser)
def Run(self, args):
"""Creates a Cloud Run Integration."""
deprecation_util.CheckIfEndOfSaleApplies()
deprecation_util.DeprecationNotice()
integration_type = args.type
service = args.service
input_name = args.name
parameters = flags.GetParameters(args)
flags.ValidateCreateParameters(integration_type, parameters, service)
flags.ValidateEnabledGcpApis(integration_type)
release_track = self.ReleaseTrack()
with run_apps_operations.Connect(args, release_track) as client:
client.VerifyLocation()
self._validateServiceNameAgainstIntegrations(
client,
integration_type=integration_type,
service=service,
integration_name=input_name,
)
integration_name = client.CreateIntegration(
integration_type=integration_type,
parameters=parameters,
service=service,
name=input_name,
)
resource = client.GetIntegrationGeneric(integration_name)
resource_status = client.GetIntegrationStatus(resource.id)
metadata = types_utils.GetTypeMetadata(integration_type)
pretty_print.Info('')
pretty_print.Success(
messages_util.GetSuccessMessage(
integration_type=integration_type,
integration_name=integration_name,
action='created',
)
)
call_to_action = messages_util.GetCallToAction(
metadata, resource, resource_status
)
if call_to_action:
pretty_print.Info('')
pretty_print.Info(call_to_action)
pretty_print.Info(
messages_util.CheckStatusMessage(release_track, integration_name)
)
def _validateServiceNameAgainstIntegrations(
self, client, integration_type, integration_name, service
):
"""Checks if the service name matches an integration name."""
if not service:
return
error = exceptions.ArgumentError(
'Service name cannot be the same as '
+ 'the provided integration name or an '
+ 'existing integration name'
)
if service == integration_name:
raise error
integrations = client.ListIntegrations(integration_type, None)
for integration in integrations:
if integration.integration_name == service:
raise error

View File

@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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 for creating or replacing an application from YAML specification."""
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 pretty_print
from googlecloudsdk.command_lib.run.integrations import deprecation_util
from googlecloudsdk.command_lib.run.integrations import flags
from googlecloudsdk.command_lib.run.integrations import messages_util
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
from googlecloudsdk.command_lib.runapps import exceptions
from googlecloudsdk.core.console import console_io
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class Delete(base.Command):
"""Delete a Cloud Run Integration and its associated resources."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To delete a redis integration and the associated resources
$ {command} my-redis-integration
""",
}
@classmethod
def Args(cls, parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
flags.AddNamePositionalArg(parser)
flags.AddServiceAccountArg(parser)
def Run(self, args):
"""Delete a Cloud Run Integration."""
deprecation_util.CheckIfEndOfSaleApplies()
deprecation_util.DeprecationNotice()
integration_name = args.name
release_track = self.ReleaseTrack()
console_io.PromptContinue(
message=(
'Integration [{}] will be deleted. '
'This will also delete any resources this integration created.'
).format(integration_name),
throw_if_unattended=True,
cancel_on_no=True,
)
with run_apps_operations.Connect(args, release_track) as client:
client.VerifyLocation()
try:
integration_type = client.DeleteIntegration(name=integration_name)
except exceptions.IntegrationsOperationError as err:
pretty_print.Info(messages_util.GetDeleteErrorMessage(integration_name))
raise err
else:
pretty_print.Info('')
pretty_print.Success(
messages_util.GetSuccessMessage(
integration_type=integration_type,
integration_name=integration_name,
action='deleted',
)
)

View File

@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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 for creating or updating application resources from YAML specification."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run.integrations import deprecation_util
from googlecloudsdk.command_lib.run.integrations import flags
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
from googlecloudsdk.command_lib.runapps import exceptions
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.DefaultUniverseOnly
class Deploy(base.Command):
"""Create or update application resources from a YAML specification."""
detailed_help = {
'DESCRIPTION':
"""\
{description}
""",
'EXAMPLES':
"""\
To create application resources from specification
$ {command} stack.yaml
""",
}
@classmethod
def Args(cls, parser):
flags.AddFileArg(parser)
flags.AddServiceAccountArg(parser)
def _ValidateAppConfigFile(self, file_content):
if 'name' not in file_content and 'resources' not in file_content:
raise exceptions.FieldMismatchError("'name' or 'resources' is missing.")
if '/t' in file_content:
raise exceptions.ConfigurationError('tabs found in manifest content.')
def Run(self, args):
"""Create or Update application from YAML."""
deprecation_util.CheckIfEndOfSaleApplies()
deprecation_util.DeprecationNotice()
file_content = args.FILE
self._ValidateAppConfigFile(file_content)
release_track = self.ReleaseTrack()
with run_apps_operations.Connect(args, release_track) as client:
client.VerifyLocation()
return client.ApplyYaml(file_content)

View File

@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 for describing Cloud Run Integrations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.run.integrations import types_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run.integrations import deprecation_util
from googlecloudsdk.command_lib.run.integrations import flags
from googlecloudsdk.command_lib.run.integrations import integration_printer
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
from googlecloudsdk.command_lib.run.integrations.formatters import base as fb
from googlecloudsdk.core.resource import resource_printer
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Describe a Cloud Run Integration."""
detailed_help = {
'DESCRIPTION':
"""\
{description}
""",
'EXAMPLES':
"""\
To describe an integration
$ {command} my-redis-integration
""",
}
@classmethod
def Args(cls, parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
flags.AddNamePositionalArg(parser)
resource_printer.RegisterFormatter(
integration_printer.INTEGRATION_PRINTER_FORMAT,
integration_printer.IntegrationPrinter)
parser.display_info.AddFormat(
integration_printer.INTEGRATION_PRINTER_FORMAT)
def Run(self, args):
"""Describe an integration type."""
deprecation_util.CheckIfEndOfSaleApplies()
deprecation_util.DeprecationNotice()
release_track = self.ReleaseTrack()
name = args.name
with run_apps_operations.Connect(args, release_track) as client:
client.VerifyLocation()
resource = client.GetIntegrationGeneric(name)
latest_deployment = client.GetLatestDeployment(resource)
resource_status = client.GetIntegrationStatus(resource.id)
metadata = types_utils.GetTypeMetadataByResource(resource)
return fb.Record(
name=name,
region=client.region,
metadata=metadata,
resource=resource,
status=resource_status,
latest_deployment=latest_deployment,
)

View File

@@ -0,0 +1,116 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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 for listing Cloud Run Integrations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.run.integrations import types_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_extensions
from googlecloudsdk.command_lib.run.integrations import deprecation_util
from googlecloudsdk.command_lib.run.integrations import flags
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class List(base.ListCommand):
"""List Cloud Run Integrations."""
detailed_help = {
'DESCRIPTION':
"""\
{description}
""",
'EXAMPLES':
"""\
List all Cloud Run Integrations within the current project
$ {command}
List all Cloud Run Integrations of a particular type
$ {command} --type=redis
List all Cloud Run Integrations attached to a particular Service
$ {command} --service=my-service
""",
}
@classmethod
def Args(cls, parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
flags.ListIntegrationsOfService(parser)
flags.ListIntegrationsOfType(parser)
def Run(self, args):
"""Lists all the Cloud Run Integrations.
All regions are listed by default similar to Cloud Run services unless
a specific region is provided with the --region flag.
Args:
args: ArgumentParser, used to reference the inputs provided by the user.
Returns:
dict with a single key that maps to a list of integrations.
This will be used by the integration_list_printer to format all
the entries in the list.
The reason this is not a list is because the printer will only recieve
one entry at a time and cannot easily format all entries into a table.
"""
deprecation_util.CheckIfEndOfSaleApplies()
deprecation_util.DeprecationNotice()
_SetFormat(args)
integration_type = args.type
service_name = args.service
release_track = self.ReleaseTrack()
region = (None if args.IsSpecified('region')
else run_apps_operations.ALL_REGIONS)
with run_apps_operations.Connect(args, release_track) as client:
# If a region is specified via the --region flag then we need to validate
# if the region is valid. Otherwise fetch from all regions by default.
if args.IsSpecified('region'):
client.VerifyLocation()
if integration_type:
types_utils.CheckValidIntegrationType(integration_type)
return client.ListIntegrations(
integration_type, service_name, region, types_utils.SERVICE_TYPE
)
def _SetFormat(namespace: parser_extensions.Namespace) -> None:
columns = [
# latest_resource_status does not have a column name
'formatted_latest_resource_status:label=',
'integration_name:label=INTEGRATION',
'integration_type:label=TYPE',
'region:label=REGION',
'services:label=SERVICE',
]
namespace.GetDisplayInfo().AddFormat(
'table({columns})'.format(columns=','.join(columns))
)

View File

@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 integrations types 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 flags
from googlecloudsdk.command_lib.run import platforms
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA,
base.ReleaseTrack.BETA)
class IntegrationsTypes(base.Group):
"""View available Cloud Run (fully managed) integrations types.
This set of commands can be used to view Cloud Run
integrations types.
"""
detailed_help = {
'EXAMPLES': """
To list available integrations types, run:
$ {command} list
""",
}

View File

@@ -0,0 +1,113 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 for describing Cloud Run Integration types."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from frozendict import frozendict
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run.integrations import deprecation_util
from googlecloudsdk.command_lib.run.integrations import flags
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
from googlecloudsdk.command_lib.run.integrations import types_describe_printer
from googlecloudsdk.command_lib.runapps import exceptions
from googlecloudsdk.core.resource import resource_printer
class Params:
"""Simple struct like class that only holds data."""
def __init__(self, required, optional):
self.required = required
self.optional = optional
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Describes a Cloud Run Integration type."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To describe an integration type
$ {command} [TYPE]
""",
}
@classmethod
def Args(cls, parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
flags.AddPositionalTypeArg(parser)
resource_printer.RegisterFormatter(
types_describe_printer.PRINTER_FORMAT,
types_describe_printer.TypesDescribePrinter,
)
parser.display_info.AddFormat(types_describe_printer.PRINTER_FORMAT)
def Run(self, args):
"""Describe an integration type."""
deprecation_util.CheckIfEndOfSaleApplies()
deprecation_util.DeprecationNotice()
release_track = self.ReleaseTrack()
type_name = args.type
with run_apps_operations.Connect(args, release_track) as client:
type_def = client.GetIntegrationTypeDefinition(type_name)
if not type_def:
raise exceptions.ArgumentError(
'Cannot find integration type [{}]'.format(type_name)
)
return {
'description': type_def.description,
'example_command': type_def.example_command.format(
track=self.ReleaseTrack().prefix
),
'parameters': self._GetParams(type_def),
}
def _GetParams(self, type_def):
required_params = []
optional_params = []
# Per the PRD, required parameters should come first.
for param in type_def.parameters:
hidden = param.hidden
required = param.required
if hidden:
continue
if required:
required_params.append(
frozendict({'name': param.name, 'description': param.description})
)
else:
optional_params.append(
frozendict({'name': param.name, 'description': param.description})
)
# sorting the parameters based on name to guarantee the same ordering
# for scenario tests.
required_params = sorted(required_params, key=lambda x: x['name'])
optional_params = sorted(optional_params, key=lambda x: x['name'])
return Params(required=required_params, optional=optional_params)

View File

@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 for listing Cloud Run Integration types."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run.integrations import deprecation_util
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class List(base.ListCommand):
"""Lists Cloud Run Integration Types."""
detailed_help = {
'DESCRIPTION':
"""\
{description}
""",
'EXAMPLES':
"""\
To list all integration types
$ {command}
""",
}
@classmethod
def Args(cls, parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
parser.display_info.AddFormat(
'table('
'integration_type:label="TYPE",'
'description:label=DESCRIPTION)')
def Run(self, args):
"""List integration types."""
deprecation_util.CheckIfEndOfSaleApplies()
deprecation_util.DeprecationNotice()
release_track = self.ReleaseTrack()
with run_apps_operations.Connect(args, release_track) as client:
# Output is sorted by the integration name to guarantee the same ordering
# for scenario tests.
result = sorted(client.ListIntegrationTypes(),
key=lambda t: t.integration_type)
return list(result)

View File

@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 for creating or replacing an application from YAML specification."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.run.integrations import types_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import pretty_print
from googlecloudsdk.command_lib.run.integrations import deprecation_util
from googlecloudsdk.command_lib.run.integrations import flags
from googlecloudsdk.command_lib.run.integrations import messages_util
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class Update(base.Command):
"""Update a Cloud Run Integration."""
detailed_help = {
'DESCRIPTION':
"""\
{description}
""",
'EXAMPLES':
"""\
To update a redis integration to change the cache size
$ {command} redis-integration --parameters=memory-size-gb=5
""",
}
@classmethod
def Args(cls, parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
flags.AddNamePositionalArg(parser)
flags.AddServiceUpdateArgs(parser)
flags.AddParametersArg(parser)
flags.AddServiceAccountArg(parser)
def Run(self, args):
"""Update a Cloud Run Integration."""
deprecation_util.CheckIfEndOfSaleApplies()
deprecation_util.DeprecationNotice()
add_service = args.add_service
remove_service = args.remove_service
integration_name = args.name
parameters = flags.GetParameters(args)
release_track = self.ReleaseTrack()
with run_apps_operations.Connect(args, release_track) as client:
client.VerifyLocation()
client.UpdateIntegration(
name=integration_name,
parameters=parameters,
add_service=add_service,
remove_service=remove_service)
resource = client.GetIntegrationGeneric(integration_name)
resource_status = client.GetIntegrationStatus(resource.id)
metadata = types_utils.GetTypeMetadataByResource(resource)
pretty_print.Info('')
pretty_print.Success(
messages_util.GetSuccessMessage(
integration_type=metadata.integration_type,
integration_name=integration_name,
action='updated',
)
)
call_to_action = messages_util.GetCallToAction(
metadata, resource, resource_status
)
# Call to action should not be shown upon service removals.
if call_to_action and not remove_service:
pretty_print.Info('')
pretty_print.Info(call_to_action)
pretty_print.Info(
messages_util.CheckStatusMessage(
self.ReleaseTrack(), integration_name
)
)