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,28 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Managed Service for Apache Kafka schema-registries operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class SchemaRegistries(base.Group):
"""Administer Managed Service for Apache Kafka schema-registries."""
category = base.DATA_ANALYTICS_CATEGORY

View File

@@ -0,0 +1,21 @@
release_tracks: [ALPHA, BETA]
help_text:
brief: |
Create a Managed Service for Apache Kafka schema registry.
description: |
Create a Managed Service for Apache Kafka schema registry.
examples: |
To create a schema registry, run the following:
$ {command} myschemaregistry \
--location=us-central1
request:
collection: managedkafka.projects.locations.schemaRegistries
arguments:
resource:
help_text: Identifies the schema registry for which the command runs.
spec: !REF googlecloudsdk.command_lib.managed_kafka.resources:schema_registry

View File

@@ -0,0 +1,22 @@
release_tracks: [ALPHA, BETA]
help_text:
brief: |
Delete a Managed Service for Apache Kafka schema registry.
description: |
Delete a Managed Service for Apache Kafka schema registry.
examples: |
To delete a schema registry named myschemaregistry located in us-central1,
run the following:
$ {command} myschemaregistry \
--location=us-central1
request:
collection: managedkafka.projects.locations.schemaRegistries
arguments:
resource:
help_text: Identifies the schema registry for deletion.
spec: !REF googlecloudsdk.command_lib.managed_kafka.resources:schema_registry

View File

@@ -0,0 +1,139 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Implementation of gcloud managed kafka schema registries describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.managed_kafka import arguments
from googlecloudsdk.command_lib.managed_kafka import util
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
PROJECTS_RESOURCE_PATH = 'projects/'
LOCATIONS_RESOURCE_PATH = 'locations/'
SCHEMA_REGISTRIES_RESOURCE_PATH = 'schemaRegistries/'
SCHEMA_REGISTRY_FORMAT = """
table(
schema_registry:format='yaml(compatibility, schema_registry.compatibility, mode, schema_registry.mode, name, schema_registry.name, contexts, schema_registry.contexts)'
)
"""
class _Results(object):
"""Encapsulate results into a single object to fit the Run() model."""
def __init__(self, schema_registry):
self.schema_registry = schema_registry
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Describe a schema registry with all of its fields.
## EXAMPLES
Describe the schema registry with all of its fields:
$ {command} --project=PROJECT_ID --location=LOCATION_ID
--schema_registry=SCHEMA_REGISTRY_ID
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.display_info.AddFormat(SCHEMA_REGISTRY_FORMAT)
arguments.AddSchemaRegistryArgToParser(parser)
def Run(self, args):
"""Called when the user runs gcloud managed-kafka schema-registries describe ...
Args:
args: all the arguments that were provided to this command invocation.
Returns:
The schema registry.
"""
client = apis.GetClientInstance('managedkafka', 'v1')
message = client.MESSAGES_MODULE
project_id = util.ParseProject(args.project)
location = args.location
schema_registry_id = args.schema_registry
schema_registry_resource = resources.REGISTRY.Parse(
schema_registry_id,
collection='managedkafka.projects.locations.schemaRegistries',
params={
'projectsId': project_id,
'locationsId': location,
'schemaRegistriesId': schema_registry_id,
},
)
schema_registry_path = schema_registry_resource.RelativeName()
log.status.Print(
'Describing schema registry [{}].'.format(schema_registry_id) + '\n'
)
schema_registry_request = (
message.ManagedkafkaProjectsLocationsSchemaRegistriesGetRequest(
name=schema_registry_path
)
)
schema_registry_mode_request = (
message.ManagedkafkaProjectsLocationsSchemaRegistriesModeGetRequest(
name=f'{schema_registry_path}/mode'
)
)
schema_registry_config_request = (
message.ManagedkafkaProjectsLocationsSchemaRegistriesConfigGetRequest(
name=f'{schema_registry_path}/config'
)
)
schema_registry = client.projects_locations_schemaRegistries.Get(
request=schema_registry_request
)
schema_registry_mode = client.projects_locations_schemaRegistries_mode.Get(
request=schema_registry_mode_request
)
schema_registry_config = (
client.projects_locations_schemaRegistries_config.Get(
request=schema_registry_config_request,
)
)
mode = util.ParseMode(schema_registry_mode.mode)
compatibility = util.ParseCompatibility(
schema_registry_config.compatibility
)
schema_registry = {
'name': schema_registry.name,
'contexts': schema_registry.contexts,
'mode': mode,
'compatibility': compatibility,
}
return _Results(schema_registry)

View File

@@ -0,0 +1,22 @@
release_tracks: [ALPHA, BETA]
help_text:
brief: |
List all Managed Service for Apache Kafka schema registries in a given location.
description: |
List all Managed Service for Apache Kafka schema registries in a given location.
To specify the maximum number of clusters to list, use the --limit flag.
examples: |
To list all schema registries in a given location, such as us-central1, run the following:
$ {command} --location=us-central1
request:
collection: managedkafka.projects.locations.schemaRegistries
arguments:
resource:
help_text: |
Identifies the region which contains all the schema registries to be listed.
spec: !REF googlecloudsdk.command_lib.managed_kafka.resources:location

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Managed Service for Apache Kafka schema-registries operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class SchemaRegistries(base.Group):
"""Administer Managed Service for Apache Kafka schema-registries."""
category = base.DATA_ANALYTICS_CATEGORY

View File

@@ -0,0 +1,183 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Implementation of gcloud managed kafka schema registries subjects describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import exceptions as apitools_exceptions
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.managed_kafka import arguments
from googlecloudsdk.command_lib.managed_kafka import util
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
PROJECTS_RESOURCE_PATH = 'projects/'
LOCATIONS_RESOURCE_PATH = 'locations/'
SCHEMA_REGISTRIES_RESOURCE_PATH = 'schemaRegistries/'
SUBJECTS_RESOURCE_PATH = '/subjects/'
CONTEXTS_RESOURCE_PATH = '/contexts/'
SUBJECT_FORMAT = """
table(
subject:format='yaml(compatibility, subject.compatibility, mode, subject.mode, name, subject.name)'
)
"""
class _Results(object):
"""Encapsulate results into a single object to fit the Run() model."""
def __init__(self, subject):
self.subject = subject
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Describe a subject in a schema registry with all of its fields.
## EXAMPLES
Describe the subject in a schema registry with all of its fields:
$ {command} --project=PROJECT_ID --location=LOCATION_ID
--registry=SCHEMA_REGISTRY_ID
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.display_info.AddFormat(SUBJECT_FORMAT)
parser.add_argument(
'--context',
type=str,
help='The context of the subject.',
)
arguments.AddSubjectArgToParser(parser)
def Run(self, args):
"""Called when the user runs gcloud managed-kafka schema-registries subjects describe ...
Args:
args: all the arguments that were provided to this command invocation.
Returns:
The subject.
"""
client = apis.GetClientInstance('managedkafka', 'v1')
message = client.MESSAGES_MODULE
project_id = util.ParseProject(args.project)
location = args.location
schema_registry_id = args.registry
subject = args.CONCEPTS.subject.Parse().subjectsId
subject_run_resource = resources.REGISTRY.Parse(
args.subject,
collection='managedkafka.projects.locations.schemaRegistries.subjects',
params={
'projectsId': project_id,
'locationsId': location,
'schemaRegistriesId': schema_registry_id,
'subjectsId': subject,
},
)
schema_registry_resource = subject_run_resource.Parent().RelativeName()
subject_resource_path = subject_run_resource.RelativeName()
if args.context:
subject_resource_path = f'{schema_registry_resource}{CONTEXTS_RESOURCE_PATH}{args.context}{SUBJECTS_RESOURCE_PATH}{subject}'
schema_registry_resource = (
f'{schema_registry_resource}{CONTEXTS_RESOURCE_PATH}{args.context}'
)
log.status.Print('Describing subject [{}].'.format(subject) + '\n')
subject_mode_request = (
message.ManagedkafkaProjectsLocationsSchemaRegistriesModeGetRequest(
name=f'{schema_registry_resource}/mode/{subject}'
)
)
subject_config_request = (
message.ManagedkafkaProjectsLocationsSchemaRegistriesConfigGetRequest(
name=f'{schema_registry_resource}/config/{subject}'
)
)
mode = 'None'
compatibility = 'None'
try:
subject_mode = client.projects_locations_schemaRegistries_mode.Get(
request=subject_mode_request
)
mode = util.ParseMode(subject_mode.mode)
except apitools_exceptions.HttpNotFoundError as e:
api_error = exceptions.HttpException(e, util.HTTP_ERROR_FORMAT)
if 'Resource not found' in api_error.message:
raise exceptions.HttpException(
e, error_format='Subject {} not found.'.format(subject)
)
try:
schema_registry_mode_request = (
message.ManagedkafkaProjectsLocationsSchemaRegistriesModeGetRequest(
name=f'{schema_registry_resource}/mode'
)
)
schema_registry_mode = (
client.projects_locations_schemaRegistries_mode.Get(
request=schema_registry_mode_request
)
)
mode = util.ParseMode(schema_registry_mode.mode)
mode = f'{mode} (from registry)'
except apitools_exceptions.HttpNotFoundError as inner_e:
# Should not happen.
raise exceptions.HttpException(inner_e)
try:
subject_config = client.projects_locations_schemaRegistries_config.Get(
request=subject_config_request,
)
compatibility = util.ParseCompatibility(subject_config.compatibility)
except apitools_exceptions.HttpNotFoundError:
try:
schema_registry_config_request = message.ManagedkafkaProjectsLocationsSchemaRegistriesConfigGetRequest(
name=f'{schema_registry_resource}/config'
)
schema_registry_config = (
client.projects_locations_schemaRegistries_config.Get(
request=schema_registry_config_request,
)
)
compatibility = util.ParseCompatibility(
schema_registry_config.compatibility
)
compatibility = f'{compatibility} (from registry)'
except apitools_exceptions.HttpNotFoundError as inner_e:
# Should not happen.
raise exceptions.HttpException(inner_e)
verbose_subject = {
'name': subject_resource_path,
'mode': mode,
'compatibility': compatibility,
}
return _Results(verbose_subject)

View File

@@ -0,0 +1,191 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Implementation of gcloud managed kafka schema registries subjects update command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.managed_kafka import arguments
from googlecloudsdk.command_lib.managed_kafka import util
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
from googlecloudsdk.generated_clients.apis.managedkafka.v1 import managedkafka_v1_messages
PROJECTS_RESOURCE_PATH = 'projects/'
LOCATIONS_RESOURCE_PATH = 'locations/'
SCHEMA_REGISTRIES_RESOURCE_PATH = 'schemaRegistries/'
SUBJECTS_RESOURCE_PATH = 'subjects/'
CONTEXTS_RESOURCE_PATH = '/contexts/'
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.DefaultUniverseOnly
class Update(base.UpdateCommand):
"""Update the mode and compatibility of a subject.
## EXAMPLES
Modify the mode of the subject to READONLY:
$ {command} --registry=SCHEMA_REGISTRY --context=CONTEXT
--project=PROJECT_ID --location=LOCATION_ID --mode=READONLY
Modify the compatibility of the subject to BACKWARDS:
$ {command} --registry=SCHEMA_REGISTRY --context=CONTEXT
--project=PROJECT_ID --location=LOCATION_ID --compatibility=BACKWARDS
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddSubjectArgToParser(parser)
parser.add_argument(
'--context',
type=str,
help='The context of the subject.',
)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
'--mode',
type=str,
help='The mode of the subject to update.',
)
group.add_argument(
'--compatibility',
type=str,
help='The compatibility of the subject to update.',
)
group.add_argument(
'--delete-mode',
action='store_true',
help='Delete the mode of the subject.',
)
group.add_argument(
'--delete-config',
action='store_true',
help='Delete the config of the subject.',
)
def Run(self, args):
"""Called when the user runs gcloud managed-kafka schema-registries subjects update ...
Args:
args: all the arguments that were provided to this command invocation.
Returns:
The updated subject.
"""
client = apis.GetClientInstance('managedkafka', 'v1')
message = client.MESSAGES_MODULE
project_id = util.ParseProject(args.project)
location = args.location
schema_registry_id = args.registry
subject = args.CONCEPTS.subject.Parse().subjectsId
subject_run_resource = resources.REGISTRY.Parse(
args.subject,
collection='managedkafka.projects.locations.schemaRegistries.subjects',
params={
'projectsId': project_id,
'locationsId': location,
'schemaRegistriesId': schema_registry_id,
'subjectsId': subject,
},
)
schema_registry_resource = subject_run_resource.Parent().RelativeName()
if args.context:
schema_registry_resource = (
f'{schema_registry_resource}{CONTEXTS_RESOURCE_PATH}{args.context}'
)
if args.delete_config:
util.DeleteSubjectConfig(subject, schema_registry_resource, args.context)
if args.delete_mode:
util.DeleteSubjectMode(subject, schema_registry_resource, args.context)
if args.mode:
mode = args.mode.upper()
name = f'{schema_registry_resource}/mode/{args.CONCEPTS.subject.Parse().subjectsId}'
updatemoderequest = message.UpdateSchemaModeRequest()
updatemoderequest.mode = (
managedkafka_v1_messages.UpdateSchemaModeRequest.ModeValueValuesEnum(
mode
)
)
# Check if context is provided.
if args.context:
request = message.ManagedkafkaProjectsLocationsSchemaRegistriesContextsModeUpdateRequest(
name=name, updateSchemaModeRequest=updatemoderequest
)
response = (
client.projects_locations_schemaRegistries_contexts_mode.Update(
request=request
)
)
else:
request = message.ManagedkafkaProjectsLocationsSchemaRegistriesModeUpdateRequest(
name=name, updateSchemaModeRequest=updatemoderequest
)
response = client.projects_locations_schemaRegistries_mode.Update(
request=request
)
log.UpdatedResource(subject, details='mode to %s' % response.mode)
if args.compatibility:
compatibility = args.compatibility.upper()
name = f'{schema_registry_resource}/config/{args.CONCEPTS.subject.Parse().subjectsId}'
updateconfigrequest = message.UpdateSchemaConfigRequest()
updateconfigrequest.compatibility = managedkafka_v1_messages.UpdateSchemaConfigRequest.CompatibilityValueValuesEnum(
compatibility
)
# Check if context is provided.
if args.context:
request = message.ManagedkafkaProjectsLocationsSchemaRegistriesContextsConfigUpdateRequest(
name=name, updateSchemaConfigRequest=updateconfigrequest
)
response = (
client.projects_locations_schemaRegistries_contexts_config.Update(
request=request
)
)
else:
request = message.ManagedkafkaProjectsLocationsSchemaRegistriesConfigUpdateRequest(
name=name, updateSchemaConfigRequest=updateconfigrequest
)
response = client.projects_locations_schemaRegistries_config.Update(
request=request
)
log.UpdatedResource(
subject, details='compatibility to %s' % response.compatibility
)
# TODO: b/418768300 - Add normalize and alias to the output once they
# are supported.
log.status.Print(
'Current subject config: \n - compatibility: %s'
% (response.compatibility)
)

View File

@@ -0,0 +1,137 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Implementation of gcloud managed kafka schema registries update command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.managed_kafka import arguments
from googlecloudsdk.command_lib.managed_kafka import util
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
from googlecloudsdk.generated_clients.apis.managedkafka.v1 import managedkafka_v1_messages
PROJECTS_RESOURCE_PATH = 'projects/'
LOCATIONS_RESOURCE_PATH = 'locations/'
SCHEMA_REGISTRIES_RESOURCE_PATH = 'schemaRegistries/'
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.DefaultUniverseOnly
class Update(base.UpdateCommand):
"""Update the mode and compatibility of a schema registry.
## EXAMPLES
Modify the mode of the schema registry to READONLY:
$ {command} --mode=READONLY
Modify the compatibility of the schema registry to BACKWARDS:
$ {command} --compatibility=BACKWARDS
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddSchemaRegistryArgToParser(parser)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
'--mode',
type=str,
help='The mode of the schema registry to update.',
)
group.add_argument(
'--compatibility',
type=str,
help='The compatibility of the schema registry to update.',
)
def Run(self, args):
"""Called when the user runs gcloud managed-kafka schema-registries update ...
Args:
args: all the arguments that were provided to this command invocation.
Returns:
The updated schema registry.
"""
client = apis.GetClientInstance('managedkafka', 'v1')
message = client.MESSAGES_MODULE
project_id = util.ParseProject(args.project)
location = args.location
schema_registry_resource = resources.REGISTRY.Parse(
args.schema_registry,
collection='managedkafka.projects.locations.schemaRegistries',
params={
'projectsId': project_id,
'locationsId': location,
'schemaRegistriesId': args.schema_registry,
},
)
schema_registry_path = schema_registry_resource.RelativeName()
if args.mode:
name = schema_registry_path + '/mode'
updatemoderequest = message.UpdateSchemaModeRequest()
updatemoderequest.mode = (
managedkafka_v1_messages.UpdateSchemaModeRequest.ModeValueValuesEnum(
args.mode
)
)
request = message.ManagedkafkaProjectsLocationsSchemaRegistriesContextsModeUpdateRequest(
name=name, updateSchemaModeRequest=updatemoderequest
)
response = (
client.projects_locations_schemaRegistries_contexts_mode.Update(
request=request
)
)
log.UpdatedResource(
args.schema_registry, details='mode to %s' % response.mode
)
if args.compatibility:
name = schema_registry_path + '/config'
updateconfigrequest = message.UpdateSchemaConfigRequest()
updateconfigrequest.compatibility = managedkafka_v1_messages.UpdateSchemaConfigRequest.CompatibilityValueValuesEnum(
args.compatibility
)
request = message.ManagedkafkaProjectsLocationsSchemaRegistriesContextsConfigUpdateRequest(
name=name, updateSchemaConfigRequest=updateconfigrequest
)
response = (
client.projects_locations_schemaRegistries_contexts_config.Update(
request=request
)
)
log.UpdatedResource(
args.schema_registry,
details='compatibility to %s' % response.compatibility,
)
# TODO: b/418768300 - Add normalize and alias to the output once they
# are supported.
log.status.Print(
'Current schema registry config: \n - compatibility: %s'
% (response.compatibility)
)