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 2014 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 Logging sinks group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.UniverseCompatible
class Sinks(base.Group):
"""Manages sinks used to route logs to storage or export destinations."""
category = base.MANAGEMENT_TOOLS_CATEGORY

View File

@@ -0,0 +1,256 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 create' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
@base.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA
)
class Create(base.CreateCommand):
# pylint: disable=line-too-long
"""Create a log sink.
Create a log sink used to route log entries to a destination. The sink routes
all log entries that match its *--log-filter* flag.
An empty filter matches all logs.
Detailed information about filters can be found at:
[](https://cloud.google.com/logging/docs/view/logging-query-language)
The sink's destination can be a Cloud Logging log bucket, a Cloud Storage
bucket, a BigQuery dataset, a Cloud Pub/Sub topic, or a Google Cloud project.
The destination must already exist.
If creating a log sink to route logs to a destination outside of Cloud Logging
or to a Cloud Logging log bucket in another project, the log sink's service
account must be granted permission to write to the destination.
For more information about destination permissions, see:
https://cloud.google.com/logging/docs/export/configure_export_v2#dest-auth
Matching log entries are routed to the destination after the sink is created.
## EXAMPLES
To route all Google Compute Engine logs to BigQuery, run:
$ {command} my-bq-sink
bigquery.googleapis.com/projects/my-project/datasets/my_dataset --log-filter='resource.type="gce_instance"'
To route "syslog" from App Engine Flexible to a Cloud Storage bucket, run:
$ {command} my-gcs-sink storage.googleapis.com/my-bucket --log-filter='logName="projects/my-project/appengine.googleapis.com%2Fsyslog"'
To route Google App Engine logs with ERROR severity, run:
$ {command} my-error-logs
bigquery.googleapis.com/projects/my-project/datasets/my_dataset --log-filter='resource.type="gae_app" AND severity=ERROR'
To route all logs to a log bucket in a different project, run:
$ {command} my-sink
logging.googleapis.com/projects/my-central-project/locations/global/buckets/my-central-bucket
To route all logs to another project, run:
$ {command} my-sink
logging.googleapis.com/projects/my-destination-project
"""
# 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=arg_parsers.UniverseHelpText(
default='The destination for the sink.',
universe_help='Some destination types are not supported\n.',
),
)
parser.add_argument(
'--log-filter',
required=False,
help=('A filter expression for the sink. If present, the filter '
'specifies which log entries to export.'))
parser.add_argument(
'--include-children',
required=False,
action='store_true',
help=('Whether to export logs from all child projects and folders. '
'Only applies to sinks for organizations and folders.'))
parser.add_argument(
'--intercept-children',
required=False,
action='store_true',
help=(
'Whether to intercept logs from all child projects and folders. '
'Only applies to sinks for organizations and folders.'
),
)
parser.add_argument(
'--custom-writer-identity',
metavar='SERVICE_ACCOUNT_EMAIL',
help=(
'Writer identity for the sink. This flag can only be used if the '
'destination is a log bucket in a different project. The writer '
'identity is automatically generated when it is not provided for '
'a sink.'
),
)
bigquery_group = parser.add_argument_group(
help='Settings for sink exporting data to BigQuery.')
bigquery_group.add_argument(
'--use-partitioned-tables',
required=False,
action='store_true',
help=('If specified, use BigQuery\'s partitioned tables. By default, '
'Logging creates dated tables based on the log entries\' '
'timestamps, e.g. \'syslog_20170523\'. Partitioned tables remove '
'the suffix and special query syntax '
'(https://cloud.google.com/bigquery/docs/'
'querying-partitioned-tables) must be used.'))
parser.add_argument(
'--exclusion',
action='append',
type=arg_parsers.ArgDict(
spec={
'name': str,
'description': str,
'filter': str,
'disabled': bool
},
required_keys=['name', 'filter']),
help=('Specify an exclusion filter for a log entry that is not to be '
'exported. This flag can be repeated.\n\n'
'The ``name\'\' and ``filter\'\' attributes are required. The '
'following keys are accepted:\n\n'
'*name*::: An identifier, such as ``load-balancer-exclusion\'\'. '
'Identifiers are limited to 100 characters and can include only '
'letters, digits, underscores, hyphens, and periods.\n\n'
'*description*::: A description of this exclusion.\n\n'
'*filter*::: An advanced log filter that matches the log entries '
'to be excluded.\n\n'
'*disabled*::: If this exclusion should be disabled and not '
'exclude the log entries.'))
parser.add_argument('--description', help='Description of the sink.')
parser.add_argument(
'--disabled',
action='store_true',
help=('Sink will be disabled. Disabled sinks do not export logs.'))
util.AddParentArgs(parser, 'sink to create')
parser.display_info.AddCacheUpdater(None)
def CreateSink(self, parent, sink_data, custom_writer_identity):
"""Creates a v2 sink specified by the arguments."""
messages = util.GetMessages()
return util.GetClient().projects_sinks.Create(
messages.LoggingProjectsSinksCreateRequest(
parent=parent,
logSink=messages.LogSink(**sink_data),
uniqueWriterIdentity=True,
customWriterIdentity=custom_writer_identity))
def _Run(self, args):
if not args.log_filter:
# Attempt to create a sink with an empty filter.
console_io.PromptContinue(
'Sink with empty filter matches all entries.', cancel_on_no=True)
if not (args.organization or args.folder):
if args.include_children:
log.warning(
'include-children only has an effect for sinks at the folder '
'or organization level'
)
if args.intercept_children:
log.warning(
'intercept-children only has an effect for sinks at the folder '
'or organization level'
)
sink_ref = util.GetSinkReference(args.sink_name, args)
sink_data = {
'name': sink_ref.sinksId,
'destination': args.destination,
}
if args.IsSpecified('include_children'):
sink_data['includeChildren'] = args.include_children
if args.IsSpecified('intercept_children'):
sink_data['interceptChildren'] = args.intercept_children
if args.IsSpecified('log_filter'):
sink_data['filter'] = args.log_filter
if args.IsSpecified('use_partitioned_tables'):
bigquery_options = {}
bigquery_options['usePartitionedTables'] = args.use_partitioned_tables
sink_data['bigqueryOptions'] = bigquery_options
if args.IsSpecified('exclusion'):
sink_data['exclusions'] = args.exclusion
if args.IsSpecified('description'):
sink_data['description'] = args.description
if args.IsSpecified('disabled'):
sink_data['disabled'] = args.disabled
custom_writer_identity = None
if args.IsSpecified('custom_writer_identity'):
custom_writer_identity = args.custom_writer_identity
result = self.CreateSink(
util.GetParentFromArgs(args), sink_data, custom_writer_identity)
log.CreatedResource(sink_ref)
self._epilog_result_destination = result.destination
self._epilog_writer_identity = result.writerIdentity
return result
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.
"""
return self._Run(args)
def Epilog(self, unused_resources_were_displayed):
util.PrintPermissionInstructions(self._epilog_result_destination,
self._epilog_writer_identity)

View File

@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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.logging import util
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
@base.UniverseCompatible
class Delete(base.DeleteCommand):
"""Delete a sink.
Delete a sink and halt the export of log entries associated with that sink.
Deleting a sink does not affect log entries already exported through
the deleted sink, and will not affect other sinks that are exporting
the same log(s).
## EXAMPLES
To delete a sync 'my-bq-sync':
$ {command} my-bq-sink
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('sink_name', help='The name of the sink to delete.')
util.AddParentArgs(parser, 'sink to delete')
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.
"""
sink_ref = util.GetSinkReference(args.sink_name, args)
sink_resource = util.CreateResourceName(util.GetParentFromArgs(args),
'sinks', sink_ref.sinksId)
console_io.PromptContinue('Really delete sink [%s]?' % sink_ref.sinksId,
cancel_on_no=True)
util.GetClient().projects_sinks.Delete(
util.GetMessages().LoggingProjectsSinksDeleteRequest(
sinkName=sink_resource))
log.DeletedResource(sink_ref)

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 describe' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import base
@base.UniverseCompatible
class Describe(base.DescribeCommand):
"""Display information about a sink.
Display information about a sink.
## EXAMPLES
To describe a sync 'my-bq-sync':
$ {command} my-bq-sink
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('sink_name', help='The name of the sink to describe.')
util.AddParentArgs(parser, 'sink to describe')
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_ref = util.GetSinkReference(args.sink_name, args)
sink_resource = util.CreateResourceName(util.GetParentFromArgs(args),
'sinks', sink_ref.sinksId)
return util.GetClient().projects_sinks.Get(
util.GetMessages().LoggingProjectsSinksGetRequest(
sinkName=sink_resource))

View File

@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 list' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import base
@base.UniverseCompatible
class List(base.ListCommand):
"""List the defined sinks.
List the defined sinks.
## EXAMPLES
To list all defined sinks:
$ {command} --limit=10
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
util.AddParentArgs(parser, 'sinks to list')
parser.add_argument(
'--sink-filter',
help=(
'A filter expression passed to the Logging API to constrain the '
'sinks returned. For information on accepted values, see '
'https://cloud.google.com/logging/docs/reference/v2/rpc/google.logging.v2#listsinksrequest'
),
)
parser.display_info.AddFormat('table(name, destination, filter)')
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 list of sinks.
"""
result = util.GetClient().projects_sinks.List(
util.GetMessages().LoggingProjectsSinksListRequest(
parent=util.GetParentFromArgs(args), filter=args.sink_filter
)
)
for sink in result.sinks:
if not sink.filter:
sink.filter = '(empty filter)'
return result.sinks

View File

@@ -0,0 +1,342 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 update' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions as calliope_exceptions
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
@base.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA
)
class Update(base.UpdateCommand):
"""Update a sink.
Change the *[DESTINATION]* or *--log-filter* associated with a sink.
The new destination must already exist and Cloud Logging must have
permission to write to it.
Log entries are exported to the new destination immediately.
## EXAMPLES
To only update a sink filter, run:
$ {command} my-sink --log-filter='severity>=ERROR'
Detailed information about filters can be found at:
[](https://cloud.google.com/logging/docs/view/logging-query-language)
"""
@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',
nargs='?',
help=arg_parsers.UniverseHelpText(
default=(
"A new destination for the sink. If omitted, the sink's"
' existing destination is unchanged.'
),
universe_help='Some destination types are not supported\n.',
),
)
parser.add_argument(
'--log-filter',
help=('A new filter expression for the sink. '
'If omitted, the sink\'s existing filter (if any) is unchanged.'))
parser.add_argument(
'--include-children',
required=False,
action='store_true',
help=(
'Whether to export logs from all child projects and folders. '
'Only applies to sinks for organizations and folders.'
),
)
parser.add_argument(
'--intercept-children',
required=False,
action='store_true',
help=(
'Whether to intercept logs from all child projects and folders. '
'Only applies to sinks for organizations and folders.'
),
)
parser.add_argument(
'--custom-writer-identity',
metavar='SERVICE_ACCOUNT_EMAIL',
help=(
'Writer identity for the sink. This flag can only be used if the '
'destination is a log bucket in a different project. The writer '
'identity is automatically generated when it is not provided for '
'a sink.'
),
)
util.AddParentArgs(parser, 'sink to update')
bigquery_group = parser.add_argument_group(
help='Settings for sink exporting data to BigQuery.')
bigquery_group.add_argument(
'--use-partitioned-tables',
action='store_true',
help=('If specified, use BigQuery\'s partitioned tables. By default, '
'Logging creates dated tables based on the log entries\' '
'timestamps, e.g. \'syslog_20170523\'. Partitioned tables remove '
'the suffix and special query syntax '
'(https://cloud.google.com/bigquery/docs/'
'querying-partitioned-tables) must be used.'))
parser.add_argument(
'--clear-exclusions',
action='store_true',
help=('Remove all logging exclusions from the sink.'))
parser.add_argument(
'--remove-exclusions',
type=arg_parsers.ArgList(),
metavar='EXCLUSION ID',
help=('Specify the name of the Logging exclusion(s) to delete.'))
parser.add_argument(
'--add-exclusion',
action='append',
type=arg_parsers.ArgDict(
spec={
'name': str,
'filter': str,
'description': str,
'disabled': bool
},
required_keys=['name', 'filter']),
help=('Add an exclusion filter for log entries that are not to be '
'routed to the sink\' destination. This flag can be repeated.\n\n'
'The ``name\'\' and ``filter\'\' attributes are required. The '
'following keys are accepted:\n\n'
'*name*::: Required. An identifier, such as '
'``load-balancer-exclusion\'\'. '
'Identifiers are limited to 100 characters and can include only '
'letters, digits, underscores, hyphens, and periods.\n\n'
'*description*::: Optional. A description of this exclusion.\n\n'
'*filter*::: Required. Entries that match this advanced log '
'filter will be excluded. Filter cannot be empty.\n\n'
'*disabled*::: Optional. By default, an exclusion is not '
'disabled. To disable an exclusion, include this key and specify '
'any value.\n\n'))
parser.add_argument(
'--update-exclusion',
action='append',
type=arg_parsers.ArgDict(
spec={
'name': str,
'filter': str,
'description': str,
'disabled': bool
},
required_keys=['name']),
help=('Update an exclusion filter for a log entry that is not to be '
'exported. This flag can be repeated.\n\n'
'The ``name\'\' attribute is required. The '
'following keys are accepted:\n\n'
'*name*::: Required. An identifier, such as '
'``load-balancer-exclusion\'\'. '
'Identifiers are limited to 100 characters and can include only '
'letters, digits, underscores, hyphens, and periods.\n\n'
'*description*::: Optional. A description of this exclusion.\n\n'
'*filter*::: Optional. Entries that match this advanced log '
'filter will be excluded. Filter cannot be empty.\n\n'
'*disabled*::: Optional. To disable an exclusion, include this '
'key and specify any value. To enable a disabled exclusion, '
'include this key, but do not specify any value. Do not include '
'this key unless you want to change its value.\n\n'))
parser.add_argument('--description', help='Description of the sink.')
parser.add_argument(
'--disabled',
action='store_true',
help=('Disable the sink. Disabled sinks do not route logs to the sink '
'destination. Specify --no-disabled to enable a disabled sink. '
'If this flag is not specified, the value will not be updated.'))
def GetSink(self, parent, sink_ref):
"""Returns a sink specified by the arguments."""
return util.GetClient().projects_sinks.Get(
util.GetMessages().LoggingProjectsSinksGetRequest(
sinkName=util.CreateResourceName(parent, 'sinks',
sink_ref.sinksId)))
def PatchSink(self, parent, sink_data, update_mask, custom_writer_identity):
"""Patches a sink specified by the arguments."""
messages = util.GetMessages()
return util.GetClient().projects_sinks.Patch(
messages.LoggingProjectsSinksPatchRequest(
sinkName=util.CreateResourceName(parent, 'sinks',
sink_data['name']),
logSink=messages.LogSink(**sink_data),
uniqueWriterIdentity=True,
updateMask=','.join(update_mask),
customWriterIdentity=custom_writer_identity))
def _Run(self, args):
sink_ref = util.GetSinkReference(args.sink_name, args)
sink = self.GetSink(util.GetParentFromArgs(args), sink_ref)
sink_data = {'name': sink_ref.sinksId}
update_mask = []
if args.IsSpecified('destination'):
sink_data['destination'] = args.destination
update_mask.append('destination')
if args.IsSpecified('include_children'):
sink_data['includeChildren'] = args.include_children
update_mask.append('include_children')
if args.include_children and not (args.organization or args.folder):
log.warning(
'include-children only has an effect for sinks at the folder '
'or organization level'
)
if args.IsSpecified('intercept_children'):
sink_data['interceptChildren'] = args.intercept_children
update_mask.append('intercept_children')
if args.intercept_children and not (args.organization or args.folder):
log.warning(
'intercept-children only has an effect for sinks at the folder '
'or organization level'
)
if args.IsSpecified('log_filter'):
sink_data['filter'] = args.log_filter
update_mask.append('filter')
parameter_names = ['[destination]', '--log-filter']
parameter_names.extend(['--use-partitioned-tables', '--clear-exclusions'])
if args.IsSpecified('use_partitioned_tables'):
bigquery_options = {}
bigquery_options['usePartitionedTables'] = args.use_partitioned_tables
sink_data['bigqueryOptions'] = bigquery_options
update_mask.append('bigquery_options.use_partitioned_tables')
if args.IsSpecified('description'):
sink_data['description'] = args.description
update_mask.append('description')
if args.IsSpecified('disabled'):
sink_data['disabled'] = args.disabled
update_mask.append('disabled')
if (args.IsSpecified('clear_exclusions') or
args.IsSpecified('remove_exclusions') or
args.IsSpecified('add_exclusion') or
args.IsSpecified('update_exclusion')):
sink_data['exclusions'] = []
update_mask.append('exclusions')
exclusions_to_remove = (
args.remove_exclusions
if args.IsSpecified('remove_exclusions') else [])
exclusions_to_update = (
args.update_exclusion if args.IsSpecified('update_exclusion') else [])
for exclusion in sink.exclusions:
if exclusion.name in exclusions_to_remove:
exclusions_to_remove.remove(exclusion.name)
else:
for i in range(len(exclusions_to_update)):
if exclusion.name == exclusions_to_update[i]['name']:
for key, value in exclusions_to_update[i].items():
if key == 'description':
exclusion.description = value
if key == 'filter':
exclusion.filter = value
if key == 'disabled':
exclusion.disabled = value
exclusions_to_update.pop(i)
break
sink_data['exclusions'].append(exclusion)
if exclusions_to_remove:
raise calliope_exceptions.InvalidArgumentException(
'--remove-exclusions', 'Exclusions {0} do not exist'.format(
','.join(exclusions_to_remove)))
if exclusions_to_update:
raise calliope_exceptions.InvalidArgumentException(
'--update-exclusion', 'Exclusions {0} do not exist'.format(','.join(
[exclusion['name'] for exclusion in exclusions_to_update])))
if args.IsSpecified('clear_exclusions'):
sink_data['exclusions'] = []
if args.IsSpecified('add_exclusion'):
sink_data['exclusions'] += args.add_exclusion
custom_writer_identity = None
if args.IsSpecified('custom_writer_identity'):
custom_writer_identity = args.custom_writer_identity
parameter_names.extend(['--custom_writer_identity'])
if not update_mask:
raise calliope_exceptions.MinimumArgumentException(
parameter_names, 'Please specify at least one property to update')
# Check for legacy configuration, and let users decide if they still want
# to update the sink with new settings.
if sink.writerIdentity and 'cloud-logs@' in sink.writerIdentity:
console_io.PromptContinue(
'This update will create a new writerIdentity (service account) for '
'the sink. In order for the sink to continue working, grant that '
'service account correct permission on the destination. The service '
'account will be displayed after a successful update operation.',
cancel_on_no=True,
default=False)
result = self.PatchSink(
util.GetParentFromArgs(args), sink_data, update_mask,
custom_writer_identity)
log.UpdatedResource(sink_ref)
if args.IsSpecified('destination'):
self._epilog_result_destination = result.destination
self._epilog_writer_identity = result.writerIdentity
return result
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.
"""
return self._Run(args)
def Epilog(self, unused_resources_were_displayed):
if hasattr(self, '_epilog_result_destination'):
util.PrintPermissionInstructions(self._epilog_result_destination,
self._epilog_writer_identity)