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,29 @@
# -*- 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.
"""The message buses command group for Eventarc."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class MessageBuses(base.Group):
"""Manage Eventarc message buses."""
category = base.SERVERLESS_CATEGORY

View File

@@ -0,0 +1,78 @@
# -*- 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 to create a message bus."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import message_buses
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.eventarc import flags
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
_DETAILED_HELP = {
'DESCRIPTION': '{description}',
'EXAMPLES': """ \
To create a new message bus `my-message-bus` in location `us-central1`, run:
$ {command} my-message-bus --location=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Create(base.CreateCommand):
"""Create an Eventarc message bus."""
detailed_help = _DETAILED_HELP
@classmethod
def Args(cls, parser):
flags.AddMessageBusResourceArg(
parser, 'The message bus to create.', required=True
)
flags.AddLoggingConfigArg(parser, 'The logging config of the message bus.')
flags.AddCryptoKeyArg(parser, with_clear=False, hidden=False)
labels_util.AddCreateLabelsFlags(parser)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run the create command."""
client = message_buses.MessageBusClientV1()
message_bus_ref = args.CONCEPTS.message_bus.Parse()
log.debug(
'Creating message bus {} for project {} in location {}'.format(
message_bus_ref.messageBusesId,
message_bus_ref.projectsId,
message_bus_ref.locationsId,
)
)
operation = client.Create(
message_bus_ref,
client.BuildMessageBus(
message_bus_ref,
args.logging_config,
args.crypto_key,
labels_util.ParseCreateArgs(args, client.LabelsValueClass()),
),
)
if args.async_:
return operation
return client.WaitFor(operation, 'Creating', message_bus_ref)

View File

@@ -0,0 +1,70 @@
# -*- 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 to delete the specified message bus."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import message_buses
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.eventarc import flags
from googlecloudsdk.core.console import console_io
_DETAILED_HELP = {
'DESCRIPTION': '{description}',
'EXAMPLES': """ \
To delete the message bus `my-message-bus` in location `us-central1`, run:
$ {command} my-message-bus --location=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Delete(base.DeleteCommand):
"""Delete an Eventarc message bus."""
detailed_help = _DETAILED_HELP
@classmethod
def Args(cls, parser):
flags.AddMessageBusResourceArg(
parser, 'Message bus to delete.', required=True
)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run the delete command."""
client = message_buses.MessageBusClientV1()
message_bus_ref = args.CONCEPTS.message_bus.Parse()
console_io.PromptContinue(
message=(
'The following message bus will be deleted.\n'
'[{name}] in location [{location}]'.format(
name=message_bus_ref.messageBusesId,
location=message_bus_ref.locationsId,
)
),
throw_if_unattended=True,
cancel_on_no=True,
)
operation = client.Delete(message_bus_ref)
if args.async_:
return operation
return client.WaitFor(operation, 'Deleting', message_bus_ref)

View File

@@ -0,0 +1,52 @@
# -*- 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 to describe the specified message bus."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import message_buses
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.eventarc import flags
_DETAILED_HELP = {
'DESCRIPTION': '{description}',
'EXAMPLES': """ \
To describe the message bus `my-message-bus` in location `us-central1`, run:
$ {command} my-message-bus --location=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Describe an Eventarc message bus."""
detailed_help = _DETAILED_HELP
@classmethod
def Args(cls, parser):
flags.AddMessageBusResourceArg(
parser, 'Message bus to describe.', required=True
)
def Run(self, args):
client = message_buses.MessageBusClientV1()
message_bus_ref = args.CONCEPTS.message_bus.Parse()
return client.Get(message_bus_ref)

View File

@@ -0,0 +1,74 @@
# -*- 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 to list all message buses in a project and location."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import message_buses
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.eventarc import flags
_DETAILED_HELP = {
"DESCRIPTION": "{description}",
"EXAMPLES": """\
To list all message buses in location ``us-central1'', run:
$ {command} --location=us-central1
To list all message buses in all locations, run:
$ {command} --location=-
or
$ {command}
""",
}
_FORMAT = """\
table(
name.scope("messageBuses"):label=NAME,
name.scope("locations").segment(0):label=LOCATION,
loggingConfig.logSeverity:label=LOGGING_CONFIG
)
"""
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class List(base.ListCommand):
"""List Eventarc message buses."""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
flags.AddLocationResourceArg(
parser,
"The location for which to list message buses. This should be one of"
" the supported regions.",
required=False,
allow_aggregation=True,
)
flags.AddProjectResourceArg(parser)
parser.display_info.AddFormat(_FORMAT)
parser.display_info.AddUriFunc(message_buses.GetMessageBusURI)
def Run(self, args):
client = message_buses.MessageBusClientV1()
location_ref = args.CONCEPTS.location.Parse()
return client.List(location_ref, args.limit, args.page_size)

View File

@@ -0,0 +1,61 @@
# -*- 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 to list all message buses in a project and location."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import enrollments
from googlecloudsdk.api_lib.eventarc import message_buses
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.eventarc import flags
_DETAILED_HELP = {
"DESCRIPTION": "{description}",
"EXAMPLES": """\
To list all enrollments in message-bus `my-message-bus` in `us-central1`, run:
$ {command} my-message-bus --location=us-central1
""",
}
_FORMAT = """ \
table(
list().scope("projects").segment(1):label=ENROLLMENT_PROJECT,
list().scope("enrollments"):label=NAME
)
"""
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class ListEnrollments(base.ListCommand):
"""List Eventarc enrollments attached to an Eventarc message bus."""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
flags.AddMessageBusResourceArg(
parser, "The message bus on which to list enrollments.", required=True
)
parser.display_info.AddFormat(_FORMAT)
parser.display_info.AddUriFunc(enrollments.GetEnrollmentURI)
def Run(self, args):
client = message_buses.MessageBusClientV1()
message_bus_ref = args.CONCEPTS.message_bus.Parse()
return client.ListEnrollments(message_bus_ref, args.limit, args.page_size)

View File

@@ -0,0 +1,86 @@
# -*- 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 to publish on message buses."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import message_buses
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions as calliope_exceptions
from googlecloudsdk.command_lib.eventarc import flags
from googlecloudsdk.core import log
_DETAILED_HELP = {
'DESCRIPTION': '{description}',
'EXAMPLES': """ \
To publish an event to the message bus `my-message-bus` with event id `1234`, event type `event-provider.event.v1.eventType`, event source `//event-provider/event/source`, event data `{ "key": "value" }` and event attributes of `attribute1=value`, run:
$ {command} my-message-bus --location=us-central1 --event-id=1234 --event-type=event-provider.event.v1.eventType --event-source="//event-provider/event/source" --event-data='{"key": "value"}' --event-attributes=attribute1=value
To publish an event to the message bus `my-message-bus` with a json message, run:
$ {command} my-message-bus --location=us-central1 --json-message='{"id": 1234, "type": "event-provider.event.v1.eventType", "source": "//event-provider/event/source", "specversion": "1.0", "data": {"key": "value"}}'
""",
}
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Publish(base.Command):
"""Publish to an Eventarc message bus."""
detailed_help = _DETAILED_HELP
@classmethod
def Args(cls, parser):
flags.AddMessageBusPublishingArgs(parser)
def Run(self, args):
"""Run the Publish command."""
client = message_buses.MessageBusClientV1()
message_bus_ref = args.CONCEPTS.message_bus.Parse()
log.debug(
'Publishing to message bus: {}'.format(message_bus_ref.messageBusesId)
)
destination_enrollment_ref = args.CONCEPTS.destination_enrollment.Parse()
if (
destination_enrollment_ref
and destination_enrollment_ref.locationsId
!= message_bus_ref.locationsId
):
raise calliope_exceptions.InvalidArgumentException(
'--destination-enrollment',
'Destination Enrollment and Message Bus must be in the same'
' location.',
)
client.Publish(
message_bus_ref,
args.json_message,
args.avro_message,
args.event_id,
args.event_type,
args.event_source,
args.event_data,
args.event_attributes,
destination_enrollment_ref,
)
return log.out.Print('Event published successfully')

View File

@@ -0,0 +1,97 @@
# -*- 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 to update the specified message bus."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import message_buses
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.eventarc import flags
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
_DETAILED_HELP = {
'DESCRIPTION': '{description}',
'EXAMPLES': """ \
To update the message bus `my-message-bus` in location `us-central1`, run:
$ {command} my-message-bus --location=us-central1
To configure the message bus `my-message-bus` in location `us-central1` with a Cloud KMS CryptoKey, run:
$ {command} my-message-bus --location=us-central1 --crypto-key=projects/PROJECT_ID/locations/KMS_LOCATION/keyRings/KEYRING/cryptoKeys/KEY
""",
}
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Update(base.UpdateCommand):
"""Update an Eventarc message bus."""
detailed_help = _DETAILED_HELP
@classmethod
def Args(cls, parser):
flags.AddMessageBusResourceArg(
parser, 'Message bus to update.', required=True
)
flags.AddLoggingConfigArg(parser, 'The logging config of the message bus.')
flags.AddCryptoKeyArg(parser, with_clear=True)
labels_util.AddUpdateLabelsFlags(parser)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run the update command."""
client = message_buses.MessageBusClientV1()
message_bus_ref = args.CONCEPTS.message_bus.Parse()
log.debug(
'Updating message bus {} for project {} in location {}'.format(
message_bus_ref.messageBusesId,
message_bus_ref.projectsId,
message_bus_ref.locationsId,
)
)
original_message_bus = client.Get(message_bus_ref)
labels_update_result = labels_util.Diff.FromUpdateArgs(args).Apply(
client.LabelsValueClass(), original_message_bus.labels
)
update_mask = client.BuildUpdateMask(
logging_config=args.IsSpecified('logging_config'),
crypto_key=args.IsSpecified('crypto_key'),
clear_crypto_key=args.clear_crypto_key,
labels=labels_update_result.needs_update,
)
operation = client.Patch(
message_bus_ref,
client.BuildMessageBus(
message_bus_ref=message_bus_ref,
logging_config=args.logging_config,
crypto_key_name=args.crypto_key,
labels=labels_update_result.GetOrNone(),
),
update_mask,
)
if args.async_:
return operation
return client.WaitFor(operation, 'Updating', message_bus_ref)