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,65 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 Stacks 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 platforms
from googlecloudsdk.command_lib.runapps import flags
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.Deprecate(
is_removed=True,
error='Stacks is no longer supported.'
)
@base.DefaultUniverseOnly
class Stacks(base.Group):
"""View and manage your Stacks resources.
This set of commands can be used to view and manage your Stacks resources.
"""
category = base.SERVERLESS_CATEGORY
detailed_help = {
'EXAMPLES': """
To deploy your existing Stacks resources, run:
$ {command} deploy stacks.yaml
""",
}
@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
return context

View File

@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 print_function
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
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.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Deploy(base.Command):
"""Create or replace an application from a YAML specification."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create an application 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."""
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,33 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 Stacks resources group."""
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class StacksResources(base.Group):
"""Stacks resources command group.
This set of commands can be used to view Cloud Run resources.
"""
detailed_help = {
'EXAMPLES': """
To list Stacks resources, run:
$ {command} list
""",
}

View File

@@ -0,0 +1,85 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 deleting Stacks resource."""
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 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)
class Delete(base.Command):
"""Delete a Stacks resource and its associated bindings."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To delete a resources and the associated bindings
$ {command} my-resource
""",
}
@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 Stacks resource."""
resource_name = args.name
release_track = self.ReleaseTrack()
console_io.PromptContinue(
message=(
'Resource [{}] will be deleted. This will also delete any'
' underlying resources this Stacks resource created.'
).format(resource_name),
throw_if_unattended=True,
cancel_on_no=True,
)
with run_apps_operations.Connect(args, release_track) as client:
client.VerifyLocation()
try:
resource_type = client.DeleteIntegration(name=resource_name)
except exceptions.IntegrationsOperationError as err:
pretty_print.Info(messages_util.GetDeleteErrorMessage(resource_name))
raise err
else:
pretty_print.Info('')
pretty_print.Success(
messages_util.GetSuccessMessage(
integration_type=resource_type,
integration_name=resource_name,
action='deleted',
)
)

View File

@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 Stacks resource."""
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 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)
class Describe(base.DescribeCommand):
"""Describe a Stacks resource."""
detailed_help = {
'DESCRIPTION':
"""\
{description}
""",
'EXAMPLES':
"""\
To describe an resource
$ {command} my-resource
""",
}
@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 a Stacks resource."""
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,61 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 Stacks resources."""
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 graph
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class ExportGraph(base.ListCommand):
"""Export a graph for Stacks resources."""
def Run(self, args):
"""Export a graph for Stacks resources.
Args:
args: ArgumentParser, used to reference the inputs provided by the user.
Returns:
dict with a single key that maps to a list of resources.
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.
"""
release_track = self.ReleaseTrack()
with run_apps_operations.Connect(args, release_track) as client:
return client.GetBindingData()
def Display(self, args, bindings):
"""This method is called to print the result of the Run() method.
Args:
args: all the arguments that were provided to this command invocation.
bindings: The binding data returned from Run().
"""
del args
if bindings:
for line in graph.GenerateBindingGraph(bindings, 'ResourcesGraph'):
log.out.write(line)
log.out.write('\n')

View File

@@ -0,0 +1,108 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 Stacks resources."""
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 flags
from googlecloudsdk.command_lib.run.integrations import run_apps_operations
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class List(base.ListCommand):
"""List Stacks resources."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
List all resources within the current project
$ {command}
List all resources of a particular type
$ {command} --type=redis
List all resources 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 Stacks resources.
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 resources.
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.
"""
_SetFormat(args)
resource_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 resource_type:
types_utils.CheckValidIntegrationType(resource_type)
return client.ListIntegrations(resource_type, service_name, region)
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=NAME',
'integration_type:label=TYPE',
'region:label=REGION',
'services:label=BINDINGS',
]
namespace.GetDisplayInfo().AddFormat(
'table({columns})'.format(columns=','.join(columns))
)

View File

@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 stacks types group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class StacksTypes(base.Group):
"""View available Stacks Types.
This set of commands can be used to view Stacks Types.
"""
detailed_help = {
'EXAMPLES': """
To list available Stacks types, run:
$ {command} list
""",
}

View File

@@ -0,0 +1,114 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 Stacks 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 import exceptions
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.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)
class Describe(base.DescribeCommand):
"""Describes a Stacks type."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To describe a Stacks 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 a Stacks type."""
release_track = self.ReleaseTrack()
type_name = args.type
with run_apps_operations.Connect(args, release_track) as client:
type_def = client.GetIntegrationTypeDefinition(type_name, True)
if not type_def:
raise exceptions.ArgumentError(
'Cannot find type [{}]'.format(type_name)
)
return {
'description':
type_def.description,
'example_command':
type_def.example_yaml,
'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.config_name,
'description': param.description
}))
else:
optional_params.append(
frozendict({
'name': param.config_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,61 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 Stacks 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 run_apps_operations
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class List(base.ListCommand):
"""Lists Stacks Types."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To list all 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 Stacks types."""
release_track = self.ReleaseTrack()
with run_apps_operations.Connect(args, release_track) as client:
# Output is sorted by the type name to guarantee the same ordering
# for scenario tests.
result = sorted(client.ListIntegrationTypes(include_workload=True),
key=lambda t: t.integration_type)
return list(result)