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,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))
)