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,31 @@
# -*- 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 command group for the schemas CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.DefaultUniverseOnly
class Schemas(base.Group):
"""Manage Pub/Sub schemas.
The {command} group lets you create and manage Pub/Sub schemas. These
schemas can be attached to topics to enable validation of published messages.
Commands to validate schemas and messages against schemas are also available.
"""

View File

@@ -0,0 +1,91 @@
# -*- 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.
"""Cloud Pub/Sub schemas commit command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import exceptions as api_ex
from googlecloudsdk.api_lib.pubsub import schemas
from googlecloudsdk.api_lib.util import exceptions
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.pubsub import flags
from googlecloudsdk.command_lib.pubsub import resource_args
from googlecloudsdk.command_lib.pubsub import util
from googlecloudsdk.core import log
class Commit(base.Command):
"""Commit a Pub/Sub schema revision."""
detailed_help = {
'EXAMPLES': """\
To commit a PROTOCOL_BUFFER schema revision called "key-schema" that requires exactly one-string field named "key", run:
\
\n$ {command} key-schema --definition="syntax = 'proto3'; message Message { optional string key = 1; }" --type=protocol-buffer
\
To commit an equivalent AVRO schema revision, run:
\
\n$ {command} key-schema --definition="{ 'type': 'record', 'namespace': 'my.ns', 'name': 'KeyMsg', 'fields': [ { 'name': 'key', 'type': 'string' } ] }" --type=avro
"""
}
@staticmethod
def Args(parser):
# The flag name is 'schema'.
resource_args.AddSchemaResourceArg(parser, 'to revise.')
flags.AddCommitSchemaFlags(parser)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
A serialized object (dict) describing the results of the operation.
This description fits the Resource described in the ResourceRegistry under
'pubsub.projects.schemas'.
Raises:
util.RequestFailedError: if any of the requests to the API failed.
"""
client = schemas.SchemasClient()
schema_ref = util.ParseSchemaName(args.schema)
if args.definition_file:
definition = args.definition_file
else:
definition = args.definition
try:
result = client.Commit(
schema_ref=schema_ref,
schema_definition=definition,
schema_type=args.type,
)
except api_ex.HttpError as error:
exc = exceptions.HttpException(error)
log.CreatedResource(
schema_ref,
kind='schema revision',
failed=util.CreateFailureErrorMessage(exc.payload.status_message),
)
return
log.CreatedResource(result.name, kind='schema revision')
return result

View File

@@ -0,0 +1,61 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Create a Pub/Sub schema.
description: |
Create a new Pub/Sub schema.
examples: |
To create a PROTOCOL_BUFFER schema called "key-schema" that requires exactly one string field named "key", run:
$ {command} key-schema --definition="syntax = 'proto3'; message Message { optional string key = 1; }" --type=PROTOCOL_BUFFER
To create an equivalent AVRO schema, run:
$ {command} key-schema --definition='{ "type": "record", "namespace": "my.ns", "name": "KeyMsg", "fields": [ { "name": "key", "type": "string" } ] }' --type=AVRO
request:
collection: pubsub.projects.schemas
api_version: v1
arguments:
resource:
help_text: Pub/Sub schema to create.
spec: !REF googlecloudsdk.command_lib.pubsub.resources:schema
params:
- group:
help_text: |
Schema definition.
mutex: true
required: true
params:
- arg_name: definition
api_field: schema.definition
help_text: |
Inline schema definition.
- arg_name: definition-file
api_field: schema.definition
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
help_text: |
File containing schema definition.
- arg_name: type
api_field: schema.type
required: true
help_text: |
Type of the schema.
choices:
- arg_value: avro
enum_value: AVRO
- arg_value: protocol-buffer
enum_value: PROTOCOL_BUFFER
- arg_name: tags
release_tracks: [ALPHA]
hidden: true
api_field: schema.tags.additionalProperties
metavar: KEY=VALUE
help_text: |
List of tag KEY=VALUE pairs to add.
type:
arg_dict:
flatten: true
spec:
- api_field: key
- api_field: value

View File

@@ -0,0 +1,19 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Delete a Pub/Sub schema.
description: |
Delete a Pub/Sub schema.
examples: |
To delete a schema called `my-schema`, run:
$ {command} my-schema
request:
collection: pubsub.projects.schemas
api_version: v1
arguments:
resource:
help_text: Pub/Sub schema to delete.
spec: !REF googlecloudsdk.command_lib.pubsub.resources:schema

View File

@@ -0,0 +1,76 @@
# -*- 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.
"""Cloud Pub/Sub schemas delete revision command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import exceptions as api_ex
from googlecloudsdk.api_lib.pubsub import schemas
from googlecloudsdk.api_lib.util import exceptions
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.pubsub import resource_args
from googlecloudsdk.command_lib.pubsub import util
from googlecloudsdk.core import log
class DeleteRevision(base.Command):
"""Delete a Pub/Sub schema revision."""
detailed_help = {
'EXAMPLES': """\
To roll back to an existing schema revision called "key-schema" with revision_id: "0a0b0c0d", run:
\
\n$ {command} key-schema@0a0b0c0d
"""
}
@staticmethod
def Args(parser):
# The flag name is 'schema'.
resource_args.AddSchemaResourceArg(parser, 'revision to delete.')
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
A serialized object (dict) describing the results of the operation.
This description fits the Resource described in the ResourceRegistry under
'pubsub.projects.schemas'.
Raises:
util.RequestFailedError: if any of the requests to the API failed.
"""
client = schemas.SchemasClient()
schema_ref = util.ParseSchemaName(args.schema)
try:
result = client.DeleteRevision(schema_ref=schema_ref)
except api_ex.HttpError as error:
exc = exceptions.HttpException(error)
log.DeletedResource(
schema_ref,
kind='schema revision',
failed=util.CreateFailureErrorMessage(exc.payload.status_message),
)
return
log.DeletedResource(result.name, kind='schema revision')
return result

View File

@@ -0,0 +1,21 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Show details of a Pub/Sub schema.
description: Show details of a Pub/Sub schema.
examples: |
To show details about a schema named `my-schema`, run:
$ {command} my-schema
request:
collection: pubsub.projects.schemas
api_version: v1
# Ask for the full schema view, which returns the schema definition, too.
static_fields:
view: FULL
arguments:
resource:
help_text: The schema you want to describe.
spec: !REF googlecloudsdk.command_lib.pubsub.resources:schema

View File

@@ -0,0 +1,47 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: List Pub/Sub schemas.
description: |
List Pub/Sub schemas.
examples: |
To list the schemas, run:
$ {command}
request:
collection: pubsub.projects.schemas
api_version: v1
response:
id_field: name
arguments:
resource:
help_text: Parent Pub/Sub project to list all contained Pubsub schemas.
spec: !REF googlecloudsdk.command_lib.pubsub.resources:project
params:
- arg_name: view
api_field: view
help_text: |
There are two possible views, 'basic' and 'full', default is 'basic'
choices:
- enum_value: BASIC
arg_value: basic
help_text: |
Include the name and type of the schema, but not the definition.
- enum_value: FULL
arg_value: full
help_text: |
Include all Schema object fields.
default: basic
output:
format: |
table(
name.basename(),
type,
revisionId,
revisionCreateTime:label=CREATE_TIME,
definition:optional
)

View File

@@ -0,0 +1,48 @@
- release_tracks: [GA, ALPHA, BETA]
help_text:
brief: List revisions of a Pub/Sub schema.
description: |
List revisions of a Pub/Sub schema.
examples: |
To list the revisions for a schema, run:
$ {command} my-schema
command_type: LIST
request:
collection: pubsub.projects.schemas
api_version: v1
method: listRevisions
disable_pagination: true
response:
id_field: name
result_attribute: schemas
arguments:
resource:
help_text: Parent Pub/Sub schema to list all contained revisions.
spec: !REF googlecloudsdk.command_lib.pubsub.resources:schema
params:
- arg_name: view
api_field: view
help_text: |
There are two possible views, 'basic' and 'full', default is 'basic'
choices:
- enum_value: BASIC
arg_value: basic
help_text: |
Include the name and type of the schema, but not the definition.
- enum_value: FULL
arg_value: full
help_text: |
Include all Schema object fields.
default: basic
output:
format: |
table(
revisionId,
revisionCreateTime:label=CREATE_TIME,
type:label=TYPE,
definition:optional
)

View File

@@ -0,0 +1,83 @@
# -*- 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.
"""Cloud Pub/Sub schemas rollback command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import exceptions as api_ex
from googlecloudsdk.api_lib.pubsub import schemas
from googlecloudsdk.api_lib.util import exceptions
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.pubsub import resource_args
from googlecloudsdk.command_lib.pubsub import util
from googlecloudsdk.core import log
class Rollback(base.Command):
"""Roll back a Pub/Sub schema to a specified revision."""
detailed_help = {
'EXAMPLES': """\
To roll back to an existing schema revision called "key-schema" with revision_id: "0a0b0c0d", run:
\
\n$ {command} key-schema --revision-id=0a0b0c0d
"""
}
@staticmethod
def Args(parser):
# The flag name is 'schema'.
resource_args.AddSchemaResourceArg(parser, 'to rollback.')
parser.add_argument(
'--revision-id',
type=str,
help='The revision to roll back to.',
required=True,
)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
A serialized object (dict) describing the results of the operation.
This description fits the Resource described in the ResourceRegistry under
'pubsub.projects.schemas'.
Raises:
util.RequestFailedError: if any of the requests to the API failed.
"""
client = schemas.SchemasClient()
schema_ref = util.ParseSchemaName(args.schema)
revision_id = getattr(args, 'revision_id', None)
try:
result = client.Rollback(schema_ref=schema_ref, revision_id=revision_id)
except api_ex.HttpError as error:
exc = exceptions.HttpException(error)
log.CreatedResource(
schema_ref,
kind='schema revision',
failed=util.CreateFailureErrorMessage(exc.payload.status_message),
)
return
log.CreatedResource(result.name, kind='schema revision')
return result

View File

@@ -0,0 +1,83 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Validate a message against a Pub/Sub schema.
description: |
Validate a message against a Pub/Sub schema.
examples: |
To validate message against provided PROTOCOL_BUFFER schema, run:
$ {command} --message="{\"key\": \"my-key\"}" --message-encoding=JSON --definition="syntax = 'proto3'; message Message { optional string key = 1; }" --type=PROTOCOL_BUFFER
To validate an equivalent AVRO schema, run:
$ {command} --definition='{ "type": "record", "namespace": "my.ns", "name": "KeyMsg", "fields": [ { "name": "key", "type": "string" } ] }' --type=AVRO
request:
collection: pubsub.projects.schemas
api_version: v1
method: validateMessage
arguments:
resource:
help_text: Parent Pub/Sub project in which to validate the message.
spec: !REF googlecloudsdk.command_lib.pubsub.resources:project
is_parent_resource: true
params:
- arg_name: message
api_field: validateMessageRequest.message
required: true
help_text: |
The message to validate against the schema.
- arg_name: message-encoding
api_field: validateMessageRequest.encoding
required: true
help_text: |
The encoding of the message.
choices:
- arg_value: json
enum_value: JSON
- arg_value: binary
enum_value: BINARY
- group:
help_text: |
Schema definition.
mutex: true
required: true
params:
- arg_name: schema-name
api_field: validateMessageRequest.name
processor: googlecloudsdk.command_lib.pubsub.util:ParseSchemaName
help_text: |
Name or full path of an existing schema.
- group:
params:
- group:
help_text: |
Schema specification.
mutex: true
required: true
params:
- arg_name: definition
api_field: validateMessageRequest.schema.definition
help_text: |
Inline schema definition.
- arg_name: definition-file
api_field: validateMessageRequest.schema.definition
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
help_text: |
File containing schema definition.
- arg_name: type
api_field: validateMessageRequest.schema.type
help_text: |
Type of inline schema.
required: true
choices:
- arg_value: avro
enum_value: AVRO
- arg_value: protocol-buffer
enum_value: PROTOCOL_BUFFER
response:
modify_response_hooks:
- googlecloudsdk.command_lib.pubsub.util:OutputMessageValidated

View File

@@ -0,0 +1,56 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Validate a Pub/Sub schema.
description: |
Validate a new Pub/Sub schema.
examples: |
To validate a PROTOCOL_BUFFER schema, run:
$ {command} --definition="syntax = 'proto3'; message Message { optional string key = 1; }" --type=PROTOCOL_BUFFER
To validate an equivalent AVRO schema, run:
$ {command} --definition='{ "type": "record", "namespace": "my.ns", "name": "KeyMsg", "fields": [ { "name": "key", "type": "string" } ] }' --type=AVRO
request:
collection: pubsub.projects.schemas
api_version: v1
method: validate
arguments:
resource:
help_text: |
Parent Pub/Sub project in which to validate the schema.
spec: !REF googlecloudsdk.command_lib.pubsub.resources:project
is_parent_resource: true
params:
- group:
help_text: |
Schema definition.
mutex: true
required: true
params:
- arg_name: definition
api_field: validateSchemaRequest.schema.definition
help_text: |
Inline schema definition.
- arg_name: definition-file
api_field: validateSchemaRequest.schema.definition
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
help_text: |
File containing schema definition.
- arg_name: type
api_field: validateSchemaRequest.schema.type
required: true
help_text: |
Type of the schema.
choices:
- arg_value: avro
enum_value: AVRO
- arg_value: protocol-buffer
enum_value: PROTOCOL_BUFFER
response:
modify_response_hooks:
- googlecloudsdk.command_lib.pubsub.util:OutputSchemaValidated