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,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Stackdriver trace sinks group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Sinks(base.Group):
"""Manages sinks used to export Stackdriver trace data."""

View File

@@ -0,0 +1,108 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""'trace sinks create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.trace import util
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
DETAILED_HELP = {
'DESCRIPTION':
"""
Creates a sink used to export trace spans to a destination.
The sink's destination must be a BigQuery dataset.
The destination must already exist. The identity created with the sink
will need permission to write to the destination dataset. After creating
a sink look for the *[writer_identity]* to be populated in the response.
With that identity run the following command to give it permission:
gcloud projects add-iam-policy-binding {bigquery_project_id} \\
--member serviceAccount:{writer_identity from trace_sink} \\
--role roles/bigquery.dataEditor
You may also find an existing writer identity by describing a sink.
It may take several minutes before trace spans are exported after the
sink is created.
""",
'EXAMPLES':
"""
$ {command} my-sink
bigquery.googleapis.com/projects/my-project/datasets/my_dataset
"""
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.CreateCommand):
# pylint: disable=line-too-long
"""Creates a sink."""
# pylint: enable=line-too-long
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('sink_name', help='The name for the sink.')
parser.add_argument(
'destination',
help='The destination must be a fully qualified BigQuery resource name.'
' The destination can be for the same Google Cloud project or for a'
' different Google Cloud project in the same organization.')
parser.add_argument(
'--project',
help='Create a sink associated with this project.'
' This will override the default project.')
parser.display_info.AddCacheUpdater(None)
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:
The created sink with its destination.
"""
sink_resource_name = util.GetTraceSinkResource(args.sink_name,
args.project).RelativeName()
sink_data = {
'name': sink_resource_name,
'outputConfig': {
'destination': args.destination
}
}
result_sink = util.GetClient().projects_traceSinks.Create(
util.GetMessages().CloudtraceProjectsTraceSinksCreateRequest(
parent=util.GetProjectResource(args.project).RelativeName(),
traceSink=util.GetMessages().TraceSink(**sink_data)))
log.status.Print(
'You can give permission to the service account by running the '
'following command.\ngcloud projects add-iam-policy-binding '
'bigquery-project \\\n--member serviceAccount:{0} \\\n--role '
'roles/bigquery.dataEditor'.format(result_sink.writerIdentity))
return util.FormatTraceSink(result_sink)
Create.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""'logging sinks delete' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.trace import util
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
DETAILED_HELP = {
'DESCRIPTION':
"""/
Deletes a sink and halts the export of traces associated with that sink.
Deleting a sink does not affect traces already exported through
the deleted sink, and will not affect other sinks that are exporting
the same traces.
""",
'EXAMPLES':
"""/
$ {command} my-sink
""",
}
class Delete(base.DeleteCommand):
"""Deletes a sink."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('sink_name', help='The name of the sink to delete.')
parser.add_argument(
'--project',
help='Delete a sink associated with this project.'
' This will override the default project.')
parser.display_info.AddCacheUpdater(None)
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.
"""
console_io.PromptContinue(
'Really delete sink [%s]?' % args.sink_name,
cancel_on_no=True,
default=False)
sink_ref = util.GetTraceSinkResource(args.sink_name, args.project)
sink_resource_name = sink_ref.RelativeName()
util.GetClient().projects_traceSinks.Delete(
util.GetMessages().CloudtraceProjectsTraceSinksDeleteRequest(
name=sink_resource_name))
log.DeletedResource(sink_ref)
Delete.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""'trace sinks describe' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.trace import util
from googlecloudsdk.calliope import base
DETAILED_HELP = {
'DESCRIPTION': """
Displays information about a sink.
""",
'EXAMPLES': """/
$ {command} my-sink
""",
}
class Describe(base.DescribeCommand):
"""Displays information about a sink."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('sink_name', help='The name of the sink to describe.')
parser.add_argument(
'--project',
help='Describe a sink associated with this project.'
' This will override the default project.')
parser.display_info.AddCacheUpdater(None)
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:
The specified sink with its destination.
"""
sink_resource_name = util.GetTraceSinkResource(args.sink_name,
args.project).RelativeName()
result_sink = util.GetClient().projects_traceSinks.Get(
util.GetMessages().CloudtraceProjectsTraceSinksGetRequest(
name=sink_resource_name))
return util.FormatTraceSink(result_sink)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""'trace sinks list' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.trace import util
from googlecloudsdk.calliope import base
DETAILED_HELP = {
'DESCRIPTION': """
Lists the defined sinks for the project.
""",
'EXAMPLES': """/
$ {command}
""",
}
class List(base.ListCommand):
"""Lists the defined sinks for the project."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.LIMIT_FLAG.RemoveFromParser(parser)
base.SORT_BY_FLAG.RemoveFromParser(parser)
base.FILTER_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
parser.add_argument(
'--project',
help='List all sinks associated with this project.'
' This will override the default project.')
parser.display_info.AddFormat('table(name, destination, writer_identity)')
parser.display_info.AddCacheUpdater(None)
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.
Yields:
The list of sinks.
"""
result = util.GetClient().projects_traceSinks.List(
util.GetMessages().CloudtraceProjectsTraceSinksListRequest(
parent=util.GetProjectResource(args.project).RelativeName()))
for sink in result.sinks:
yield util.FormatTraceSink(sink)
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""'trace sinks update' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.trace import util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions as calliope_exceptions
from googlecloudsdk.core import log
DETAILED_HELP = {
'DESCRIPTION':
"""/
Changes the *[destination]* associated with a sink.
The new destination must already exist and Stackdriver Trace must have
permission to write to it.
Trace spans are exported to the new destination in a few minutes.
""",
'EXAMPLES':
"""/
$ {command} my-sink bigquery.googleapis.com/projects/my-project/datasets/my_new_dataset
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Update(base.UpdateCommand):
"""Updates a sink."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('sink_name', help='The name of the sink to update.')
parser.add_argument(
'destination',
help='The new destination for the sink. The destination must be a fully'
' qualified BigQuery resource name. The destination can be for the same'
' Google Cloud project or for a different Google Cloud project in the'
' same organization.')
parser.add_argument(
'--project',
help='Update a sink associated with this project.'
' This will override the default project.')
parser.display_info.AddFormat('yaml')
parser.display_info.AddCacheUpdater(None)
def PatchSink(self, sink_name, sink_data, update_mask):
"""Patches a sink specified by the arguments."""
messages = util.GetMessages()
return util.GetClient().projects_traceSinks.Patch(
messages.CloudtraceProjectsTraceSinksPatchRequest(
name=sink_name,
traceSink=messages.TraceSink(**sink_data),
updateMask=','.join(update_mask)))
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:
The updated sink with its new destination.
"""
sink_ref = util.GetTraceSinkResource(args.sink_name, args.project)
sink_resource_name = sink_ref.RelativeName()
sink_data = {'name': sink_resource_name}
update_mask = []
if args.IsSpecified('destination'):
sink_data['outputConfig'] = {'destination': args.destination}
update_mask.append('output_config.destination')
if not update_mask:
raise calliope_exceptions.MinimumArgumentException(
'Please specify the destination to update')
result = self.PatchSink(sink_resource_name, sink_data, update_mask)
log.UpdatedResource(sink_ref)
return util.FormatTraceSink(result)
Update.detailed_help = DETAILED_HELP