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.
"""Stream objects command group for Datastream."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA)
class StreamObjects(base.Group):
"""Manage Datastream stream objects.
Commands for managing Datastream stream objects.
"""

View File

@@ -0,0 +1,20 @@
release_tracks: [GA]
help_text:
brief: Show details about a Stream object.
description: Show details about a Stream object.
examples: |
To show details about a stream object, run:
$ {command} my-object --stream=my-stream --location=us-central1
request:
collection: datastream.projects.locations.streams.objects
api_version: v1
arguments:
resource:
help_text: The Stream object you want to describe.
# The following should point to the resource argument definition under your
# surface's command_lib directory:
spec: !REF googlecloudsdk.command_lib.datastream.resources:stream_object

View File

@@ -0,0 +1,120 @@
# -*- 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.
"""Implementation of connection profile list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.datastream import stream_objects
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.datastream import resource_args
from googlecloudsdk.core import properties
class _StreamObjectInfo:
"""Container for stream object data using in list display."""
def __init__(self, message, source_object):
self.display_name = message.displayName
self.name = message.name
self.source_object = source_object
self.backfill_job_state = (
message.backfillJob.state if message.backfillJob is not None else None
)
self.backfill_job_trigger = (
message.backfillJob.trigger if message.backfillJob is not None else None
)
self.last_backfill_job_start_time = (
message.backfillJob.lastStartTime
if message.backfillJob is not None
else None
)
self.last_backfill_job_end_time = (
message.backfillJob.lastEndTime
if message.backfillJob is not None
else None
)
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List a Datastream stream objects.
List stream objects.
## API REFERENCE
This command uses the datastream/v1 API. The full documentation
for this API can be found at: https://cloud.google.com/datastream/
## EXAMPLES
To list all objects in a stream and location 'us-central1',
run:
$ {command} --stream=my-stream --location=us-central1
"""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
resource_args.AddStreamObjectResourceArg(parser)
parser.display_info.AddFormat("""
table(
display_name,
name.basename():label=NAME,
source_object,
backfill_job_state:label=BACKFILL_JOB_STATE,
backfill_job_trigger:label=BACKFILL_JOB_TRIGGER,
last_backfill_job_start_time:label=LAST_BACKFILL_JOB_START_TIME,
last_backfill_job_end_time:label=LAST_BACKFILL_JOB_END_TIME
)
""")
def Run(self, args):
"""Runs the command.
Args:
args: All the arguments that were provided to this command invocation.
Returns:
An iterator over objects containing stream objects data.
"""
so_client = stream_objects.StreamObjectsClient()
project_id = properties.VALUES.core.project.Get(required=True)
stream_ref = args.CONCEPTS.stream.Parse()
objects = so_client.List(project_id, stream_ref.streamsId, args)
return [_StreamObjectInfo(o, self._GetSourceObject(o)) for o in objects]
def _GetSourceObject(self, stream_object):
if stream_object.sourceObject.mysqlIdentifier:
identifier = stream_object.sourceObject.mysqlIdentifier
return "%s.%s" % (identifier.database, identifier.table)
elif stream_object.sourceObject.oracleIdentifier:
identifier = stream_object.sourceObject.oracleIdentifier
return "%s.%s" % (identifier.schema, identifier.table)
elif stream_object.sourceObject.postgresqlIdentifier:
identifier = stream_object.sourceObject.postgresqlIdentifier
return "%s.%s" % (identifier.schema, identifier.table)
elif stream_object.sourceObject.sqlServerIdentifier:
identifier = stream_object.sourceObject.sqlServerIdentifier
return "%s.%s" % (identifier.schema, identifier.table)
elif stream_object.sourceObject.salesforceIdentifier:
identifier = stream_object.sourceObject.salesforceIdentifier
return identifier.objectName
else:
return None

View File

@@ -0,0 +1,90 @@
# -*- 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 lookup a stream object for a datastream."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.datastream import stream_objects
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.datastream import resource_args
from googlecloudsdk.command_lib.datastream.objects import flags as so_flags
from googlecloudsdk.core import properties
DESCRIPTION = (
'Lookup a stream object by its source object identifier (e.g. schema.table)'
)
EXAMPLES = """\
To lookup an existing Mysql stream object:
$ {command} --stream=my-stream --location=us-central1 --mysql-database=my-db --mysql-table=my-table
To lookup an existing Oracle stream object:
$ {command} --stream=my-stream --location=us-central1 --oracle-schema=my-schema --oracle-table=my-table
To lookup an existing PostgreSQL stream object:
$ {command} --stream=my-stream --location=us-central1 --postgresql-schema=my-schema --postgresql-table=my-table
To lookup an existing SQL Server stream object:
$ {command} --stream=my-stream --location=us-central1 --sqlserver-schema=my-schema --sqlserver-table=my-table
To lookup an existing Salesforce stream object:
$ {command} --stream=my-stream --location=us-central1 --salesforce-object-name=my-object
"""
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Lookup(base.Command):
"""Lookup a Datastream stream object."""
detailed_help = {'DESCRIPTION': DESCRIPTION, 'EXAMPLES': EXAMPLES}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
resource_args.AddStreamObjectResourceArg(parser)
object_identifier_parser = parser.add_group(required=True, mutex=True)
so_flags.AddOracleObjectIdentifier(object_identifier_parser)
so_flags.AddMysqlObjectIdentifier(object_identifier_parser)
so_flags.AddPostgresqlObjectIdentifier(object_identifier_parser)
so_flags.AddSqlServerObjectIdentifier(object_identifier_parser)
so_flags.AddSalesforceObjectIdentifier(object_identifier_parser)
def Run(self, args):
"""Lookup a Datastream stream object.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
A dict object representing the looked up stream object if the lookup was
successful.
"""
project_id = properties.VALUES.core.project.Get(required=True)
stream_id = args.CONCEPTS.stream.Parse().streamsId
so_client = stream_objects.StreamObjectsClient()
return so_client.Lookup(project_id, stream_id, args)

View File

@@ -0,0 +1,21 @@
release_tracks: [GA]
help_text:
brief: Start a backfill job for a Stream object.
description: Start a backfill job for a Stream object.
examples: |
To start a stream object backfill job, run:
$ {command} my-object --stream=my-stream --location=us-central1
request:
collection: datastream.projects.locations.streams.objects
method: startBackfillJob
api_version: v1
arguments:
resource:
help_text: The Stream object you want to start backfill for.
# The following should point to the resource argument definition under your
# surface's command_lib directory:
spec: !REF googlecloudsdk.command_lib.datastream.resources:stream_object

View File

@@ -0,0 +1,21 @@
release_tracks: [GA]
help_text:
brief: Stop a backfill job for a Stream object.
description: Stop a backfill job for a Stream object.
examples: |
To stop a stream object backfill job, run:
$ {command} my-object --stream=my-stream --location=us-central1
request:
collection: datastream.projects.locations.streams.objects
method: stopBackfillJob
api_version: v1
arguments:
resource:
help_text: The Stream object you want to stop backfill for.
# The following should point to the resource argument definition under your
# surface's command_lib directory:
spec: !REF googlecloudsdk.command_lib.datastream.resources:stream_object