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 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 channels 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.GA)
@base.DefaultUniverseOnly
class Channels(base.Group):
"""Manage Eventarc channels."""
category = base.SERVERLESS_CATEGORY

View File

@@ -0,0 +1,80 @@
# -*- 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 to create a channel."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import channels
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
# TODO(b/188207212): Update documentation when provider will be a resource
_DETAILED_HELP = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
""" \
To create a new channel `my-channel` in location `us-central1`, run:
$ {command} my-channel --location=us-central1
To create a new channel `my-channel` in location `us-central1` with a Cloud KMS CryptoKey, run:
$ {command} my-channel --location=us-central1 --crypto-key=projects/PROJECT_ID/locations/KMS_LOCATION/keyRings/KEYRING/cryptoKeys/KEY
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Create(base.CreateCommand):
"""Create an Eventarc channel."""
detailed_help = _DETAILED_HELP
@classmethod
def Args(cls, parser):
flags.AddCreateChannelArg(parser)
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 = channels.ChannelClientV1()
channel_ref = args.CONCEPTS.channel.Parse()
project_name = channel_ref.Parent().Parent().Name()
location_name = channel_ref.Parent().Name()
log.debug('Creating channel {} for project {} in location {}'.format(
channel_ref.Name(), project_name, location_name))
provider_ref = args.CONCEPTS.provider.Parse()
operation = client.Create(
channel_ref,
client.BuildChannel(
channel_ref,
provider_ref,
args.crypto_key,
labels_util.ParseCreateArgs(args, client.LabelsValueCls()),
),
)
if args.async_:
return operation
return client.WaitFor(operation, 'Creating', channel_ref)

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 to delete the specified channel."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import channels
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 channel `my-channel` in location `us-central1`, run:
$ {command} my-channel --location=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Delete an Eventarc channel."""
detailed_help = _DETAILED_HELP
@classmethod
def Args(cls, parser):
flags.AddChannelResourceArg(parser, 'Channel to delete.', required=True)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run the delete command."""
client = channels.ChannelClientV1()
channel_ref = args.CONCEPTS.channel.Parse()
location_name = channel_ref.Parent().Name()
console_io.PromptContinue(
message=('The following channel will be deleted.\n'
'[{name}] in location [{location}]'
.format(
name=channel_ref.Name(),
location=location_name)),
throw_if_unattended=True,
cancel_on_no=True)
operation = client.Delete(channel_ref)
if args.async_:
return operation
return client.WaitFor(operation, 'Deleting', channel_ref)

View File

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

View File

@@ -0,0 +1,78 @@
# -*- 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 to list all channels 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 channels
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.eventarc import flags
_DETAILED_HELP = {
"DESCRIPTION":
"{description}",
"EXAMPLES":
""" \
To list all channels in location `us-central1`, run:
$ {command} --location=us-central1
To list all channels in all locations, run:
$ {command} --location=-
or
$ {command}
""",
}
_FORMAT = """ \
table(
name.scope("channels"):label=NAME,
provider:label=PROVIDER,
state:label=STATE,
pubsubTopic.scope("topics"):label=PUBSUB_TOPIC
)
"""
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class List(base.ListCommand):
"""List Eventarc channels."""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
flags.AddLocationResourceArg(
parser,
"Location for which to list channels. 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(channels.GetChannelURI)
def Run(self, args):
client = channels.ChannelClientV1()
args.CONCEPTS.project.Parse()
location_ref = args.CONCEPTS.location.Parse()
return client.List(location_ref, args.limit, args.page_size)

View File

@@ -0,0 +1,71 @@
# -*- 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 to publish channels."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import channels
from googlecloudsdk.api_lib.eventarc import common_publishing
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.eventarc import flags
from googlecloudsdk.core import log
_DETAILED_HELP = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
""" \
To publish an event to the channel `my-channel`
with event id `1234`
with event type `event-provider.event.v1.eventType`
with event source `//event-provider/event/source`
with event data `{ "key": "value" }`
and event attributes of `attribute1=value`, run:
$ {command} my-channel --event-id=1234 --event-type=event-provider.event.v1.eventType --event-source="//event-provider/event/source" --event-data='{"key": "value"}' --event-attributes=attribute1=value
""",
}
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Publish(base.Command):
"""Publish to an Eventarc channel."""
detailed_help = _DETAILED_HELP
@classmethod
def Args(cls, parser):
flags.AddChannelResourceArg(parser, 'Channel to Publish to.', required=True)
flags.AddEventPublishingArgs(parser)
def Run(self, args):
"""Run the Publish command."""
client = channels.ChannelClientV1()
channel_ref = args.CONCEPTS.channel.Parse()
name = channel_ref.Name()
log.debug('Publishing event with id: {} to channel: {}'.format(
args.event_id, name))
client.Publish(
channel_ref,
common_publishing.CreateCloudEvent(args.event_id, args.event_type,
args.event_source, args.event_data,
args.event_attributes))
return log.out.Print('Event published successfully')

View File

@@ -0,0 +1,93 @@
# -*- 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 to update the specified channel."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.eventarc import channels
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 channel `my-channel` in location `us-central1`, run:
$ {command} my-channel --location=us-central1
To configure the channel `my-channel` in location `us-central1` with a Cloud KMS CryptoKey, run:
$ {command} my-channel --location=us-central1 --crypto-key=projects/PROJECT_ID/locations/KMS_LOCATION/keyRings/KEYRING/cryptoKeys/KEY
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Update(base.UpdateCommand):
"""Update an Eventarc channel."""
detailed_help = _DETAILED_HELP
@classmethod
def Args(cls, parser):
flags.AddChannelResourceArg(parser, 'Channel to update.', required=True)
flags.AddCryptoKeyArg(parser, with_clear=True)
labels_util.AddUpdateLabelsFlags(parser)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run the update command."""
client = channels.ChannelClientV1()
channel_ref = args.CONCEPTS.channel.Parse()
project_name = channel_ref.Parent().Parent().Name()
location_name = channel_ref.Parent().Name()
log.debug('Updating channel {} for project {} in location {}'.format(
channel_ref.Name(), project_name, location_name))
original_channel = client.Get(channel_ref)
labels_update_result = labels_util.Diff.FromUpdateArgs(args).Apply(
client.LabelsValueCls(), original_channel.labels
)
update_mask = client.BuildUpdateMask(
crypto_key=args.IsSpecified('crypto_key'),
clear_crypto_key=args.clear_crypto_key,
labels=labels_update_result.needs_update,
)
crypto_key_name = ''
if args.IsSpecified('crypto_key'):
crypto_key_name = args.crypto_key
operation = client.Patch(
channel_ref,
client.BuildChannel(
channel_ref, None, crypto_key_name, labels_update_result.GetOrNone()
),
update_mask,
)
if args.async_:
return operation
return client.WaitFor(operation, 'Updating', channel_ref)