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,36 @@
# -*- 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.
"""The buckets command group for the Cloud Logging CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA
)
class Buckets(base.Group):
"""Manage Cloud Logging buckets.
Commands for managing Cloud Logging buckets. A bucket is a container of logs
that can be managed as a unit, for example by setting the retention period.
"""
category = base.MANAGEMENT_TOOLS_CATEGORY

View File

@@ -0,0 +1,201 @@
# -*- 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 buckets 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.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Create(base.CreateCommand):
"""Create a bucket.
After creating a bucket, use a log sink to route logs into the bucket.
## EXAMPLES
To create a bucket 'my-bucket' in location 'global', run:
$ {command} my-bucket --location=global --description="my custom bucket"
To create a bucket with extended retention, run:
$ {command} my-bucket --location=global --retention-days=365
To create a bucket in cloud region 'us-central1', run:
$ {command} my-bucket --location=us-central1
To create a bucket with custom index of 'jsonPayload.foo', run:
$ {command} my-bucket
--index=fieldPath=jsonPayload.foo,type=INDEX_TYPE_STRING
To create a bucket with custom CMEK, run:
$ {command} my-bucket --location=us-central1
--cmek-kms-key-name=CMEK_KMS_KEY_NAME
To asynchronously create a bucket enrolled into Log Analytics, run:
$ {command} my-bucket --location=global --async --enable-analytics
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('BUCKET_ID', help='ID of the bucket to create.')
parser.add_argument(
'--description', help='A textual description for the bucket.')
parser.add_argument(
'--restricted-fields',
help='Comma-separated list of field paths that require permission '
'checks in this bucket. The following fields and their children are '
'eligible: textPayload, jsonPayload, protoPayload, httpRequest, labels,'
' sourceLocation.',
type=arg_parsers.ArgList(),
metavar='RESTRICTED_FIELD',
)
parser.add_argument(
'--retention-days',
type=int,
help=arg_parsers.UniverseHelpText(
default=(
'The period logs will be retained, after which logs will'
' automatically be deleted. The default is 30 days.'
),
universe_help='This is not available.\n',
),
)
parser.add_argument(
'--index',
action='append',
type=arg_parsers.ArgDict(
spec={
'fieldPath': str,
'type': util.IndexTypeToEnum
},
required_keys=['fieldPath', 'type']),
metavar='KEY=VALUE, ...',
help=(
'Specify an index to be added to the log bucket. This flag can be '
'repeated. The ``fieldPath\'\' and ``type\'\' attributes are '
'required. For example: '
' --index=fieldPath=jsonPayload.foo,type=INDEX_TYPE_STRING. '
'The following keys are accepted:\n\n'
'*fieldPath*::: The LogEntry field path to index. '
'For example: jsonPayload.request.status. '
'Paths are limited to 800 characters and can include only '
'letters, digits, underscores, hyphens, and periods.\n\n'
'*type*::: The type of data in this index. '
'For example: INDEX_TYPE_STRING '
'Supported types are INDEX_TYPE_STRING and '
'INDEX_TYPE_INTEGER. \n\n '))
parser.add_argument(
'--cmek-kms-key-name',
help='A valid `kms_key_name` will enable CMEK for the bucket.')
parser.add_argument(
'--enable-analytics',
action='store_true',
default=None,
help=arg_parsers.UniverseHelpText(
default=(
'Whether to opt the bucket into Log Analytics. Once opted in,'
' the bucket cannot be opted out of Log Analytics.'
),
universe_help='This is not available.\n',
),
)
base.ASYNC_FLAG.AddToParser(parser)
util.AddBucketLocationArg(
parser, True,
'Location in which to create the bucket. Once the bucket is created, '
'the location cannot be changed.')
util.GetTagsArg().AddToParser(parser)
def _Run(self, args):
bucket_data = {}
if args.IsSpecified('retention_days'):
bucket_data['retentionDays'] = args.retention_days
if args.IsSpecified('description'):
bucket_data['description'] = args.description
if args.IsSpecified('restricted_fields'):
bucket_data['restrictedFields'] = args.restricted_fields
if args.IsSpecified('index'):
bucket_data['indexConfigs'] = args.index
if args.IsSpecified('enable_analytics'):
bucket_data['analyticsEnabled'] = args.enable_analytics
if args.IsSpecified('tags'):
tags = util.GetTagsFromArgs(args, util.GetMessages().LogBucket.TagsValue)
bucket_data['tags'] = tags
if args.IsSpecified('cmek_kms_key_name'):
console_io.PromptContinue(
'CMEK cannot be disabled on a bucket once enabled.',
cancel_on_no=True)
cmek_settings = util.GetMessages().CmekSettings(
kmsKeyName=args.cmek_kms_key_name)
bucket_data['cmekSettings'] = cmek_settings
if args.async_:
result = util.GetClient().projects_locations_buckets.CreateAsync(
util.GetMessages().LoggingProjectsLocationsBucketsCreateAsyncRequest(
bucketId=args.BUCKET_ID,
parent=util.CreateResourceName(
util.GetProjectResource(args.project).RelativeName(),
'locations',
args.location,
),
logBucket=util.GetMessages().LogBucket(**bucket_data),
)
)
log.CreatedResource(result.name, 'bucket', is_async=True)
return result
else:
return util.GetClient().projects_locations_buckets.Create(
util.GetMessages().LoggingProjectsLocationsBucketsCreateRequest(
bucketId=args.BUCKET_ID,
parent=util.CreateResourceName(
util.GetProjectResource(args.project).RelativeName(),
'locations',
args.location,
),
logBucket=util.GetMessages().LogBucket(**bucket_data),
)
)
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 bucket.
"""
return self._Run(args)

View File

@@ -0,0 +1,67 @@
# -*- 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 buckets 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 bucket.
## EXAMPLES
To delete bucket 'my-bucket' in location 'global', run:
$ {command} my-bucket --location=global
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument(
'BUCKET_ID', help='ID of the bucket to delete.')
util.AddBucketLocationArg(
parser, True, 'Location of the bucket.')
util.AddParentArgs(parser, 'bucket 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.
"""
console_io.PromptContinue(
'Really delete bucket [%s]? (You can undelete it within 7 days if you '
'change your mind later)' % args.BUCKET_ID,
cancel_on_no=True)
util.GetClient().projects_locations_buckets.Delete(
util.GetMessages().LoggingProjectsLocationsBucketsDeleteRequest(
name=util.CreateResourceName(
util.CreateResourceName(
util.GetParentFromArgs(args), 'locations', args.location),
'buckets', args.BUCKET_ID)))
log.DeletedResource(args.BUCKET_ID)

View File

@@ -0,0 +1,65 @@
# -*- 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 buckets 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
DETAILED_HELP = {
'DESCRIPTION': """
Display information about a bucket.
""",
'EXAMPLES': """
To describe a bucket in a project, run:
$ {command} my-bucket --location=global
""",
}
@base.UniverseCompatible
class Describe(base.DescribeCommand):
"""Display information about a bucket."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('BUCKET_ID', help='The id of the bucket to describe.')
util.AddParentArgs(parser, 'bucket to describe')
util.AddBucketLocationArg(parser, True, 'Location of the bucket.')
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 bucket.
"""
return util.GetClient().projects_locations_buckets.Get(
util.GetMessages().LoggingProjectsLocationsBucketsGetRequest(
name=util.CreateResourceName(
util.GetBucketLocationFromArgs(args), 'buckets',
args.BUCKET_ID)))
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,74 @@
# -*- 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 buckets 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
DETAILED_HELP = {
'DESCRIPTION': """
List the buckets for a project.
""",
'EXAMPLES': """
To list the buckets in a project, run:
$ {command}
""",
}
@base.UniverseCompatible
class List(base.ListCommand):
"""List the defined buckets."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
util.AddParentArgs(parser, 'buckets to list')
util.AddBucketLocationArg(
parser, False,
'Location from which to list buckets. By default, buckets in all '
'locations will be listed')
parser.display_info.AddFormat(
'table(name.segment(-3):label=LOCATION, '
'name.segment(-1):label=BUCKET_ID, retentionDays, '
'cmekSettings.yesno(yes="TRUE", no=""):label=CMEK, '
'restrictedFields, indexConfigs, lifecycle_state, locked, '
'create_time, update_time)'
)
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 buckets.
"""
result = util.GetClient().projects_locations_buckets.List(
util.GetMessages().LoggingProjectsLocationsBucketsListRequest(
parent=util.GetBucketLocationFromArgs(args)))
for bucket in result.buckets:
yield bucket
List.detailed_help = DETAILED_HELP

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.
"""'logging buckets move' 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.console import console_io
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.Hidden
class Move(base.Command):
"""Move a bucket.
In order to be movable, a bucket must satisfy the following restrictions:
- Be a ```_Default``` or ```_Required``` bucket
- Have a location of global
- Have a non-project parent when it is a ```_Default``` bucket
## EXAMPLES
To move the ```_Required``` bucket from `global` to another location, run:
$ {command} _Required --location=global --new-location=us-central1
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('BUCKET_ID', help='ID of the bucket to move.')
parser.add_argument(
'--new-location',
required=True,
help='New location to move the bucket to.')
util.AddBucketLocationArg(
parser, True, 'Location of the bucket.')
util.AddParentArgs(parser, 'bucket to move')
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:
A long running operation containing related information.
"""
parent_name = util.GetParentFromArgs(args)
source_bucket = util.CreateResourceName(
util.CreateResourceName(parent_name, 'locations', args.location),
'buckets', args.BUCKET_ID)
new_bucket = util.CreateResourceName(
util.CreateResourceName(parent_name, 'locations', args.new_location),
'buckets', args.BUCKET_ID)
console_io.PromptContinue(
'Really move bucket [%s] to [%s]? ' % (source_bucket, new_bucket),
cancel_on_no=True)
return util.GetClient().projects_locations_buckets.Move(
util.GetMessages().MoveBucketRequest(
name=source_bucket, newName=new_bucket))

View File

@@ -0,0 +1,58 @@
# -*- 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 buckets undelete' 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 Undelete(base.RestoreCommand):
"""Undelete a bucket.
## EXAMPLES
To undelete bucket 'my-bucket' in location 'global', run:
$ {command} my-bucket --location=global
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument(
'BUCKET_ID', help='ID of the bucket to undelete.')
util.AddBucketLocationArg(
parser, True, 'Location of the bucket.')
util.AddParentArgs(parser, 'bucket to undelete')
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.
"""
util.GetClient().projects_locations_buckets.Undelete(
util.GetMessages().LoggingProjectsLocationsBucketsUndeleteRequest(
name=util.CreateResourceName(
util.CreateResourceName(
util.GetParentFromArgs(args), 'locations', args.location),
'buckets', args.BUCKET_ID)))

View File

@@ -0,0 +1,332 @@
# -*- 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 buckets 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
DETAILED_HELP = {
'DESCRIPTION': """
Update the properties of a bucket.
""",
'EXAMPLES': """
To update a bucket in your project, run:
$ {command} my-bucket --location=global --description=my-new-description
To update a bucket in your project and remove all indexes, run:
$ {command} my-bucket --location=global --clear-indexes
To update a bucket in your project and remove an index, run:
$ {command} my-bucket --location=global --remove-indexes=jsonPayload.foo2
To update a bucket in your project and add an index, run:
$ {command} my-bucket --location=global --add-index=fieldPath=jsonPayload.foo2,type=INDEX_TYPE_STRING
To update a bucket in your project and update an existing index, run:
$ {command} my-bucket --location=global --update-index=fieldPath=jsonPayload.foo,type=INDEX_TYPE_INTEGER
To update a bucket in your project and update existing cmek, run:
$ {command} my-bucket --location=global --cmek-kms-key-name=CMEK_KEY_NAME
To asynchronously enroll a bucket in your project into Log Analytics, run:
$ {command} my-bucket --location=global --async --enable-analytics
""",
}
@base.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Update(base.UpdateCommand):
"""Update a bucket.
Changes one or more properties associated with a bucket.
"""
def __init__(self, *args, **kwargs):
super(Update, self).__init__(*args, **kwargs)
self._current_bucket = None
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('BUCKET_ID', help='The id of the bucket to update.')
parser.add_argument(
'--retention-days',
type=int,
help=arg_parsers.UniverseHelpText(
default='A new retention period for the bucket.',
universe_help='This is not available.\n',
),
)
parser.add_argument(
'--description', help='A new description for the bucket.')
util.AddParentArgs(parser, 'bucket to update')
util.AddBucketLocationArg(parser, True, 'Location of the bucket.')
parser.add_argument(
'--locked',
action='store_true',
help=('Lock the bucket and prevent it from being modified or deleted '
'(unless it is empty).'))
parser.add_argument(
'--restricted-fields',
help='A new set of restricted fields for the bucket.',
type=arg_parsers.ArgList(),
metavar='RESTRICTED_FIELD')
parser.add_argument(
'--clear-indexes',
action='store_true',
help=('Remove all logging indexes from the bucket.'))
parser.add_argument(
'--remove-indexes',
type=arg_parsers.ArgList(),
metavar='FIELD PATH',
help=('Specify the field path of the logging index(es) to delete.'))
parser.add_argument(
'--add-index',
action='append',
type=arg_parsers.ArgDict(
spec={
'fieldPath': str,
'type': util.IndexTypeToEnum
},
required_keys=['fieldPath', 'type']),
metavar='KEY=VALUE, ...',
help=('Add an index to be added to the log bucket. This flag can be '
'repeated. The ``fieldPath\'\' and ``type\'\' attributes are '
'required. For example: '
' --index=fieldPath=jsonPayload.foo,type=INDEX_TYPE_STRING. '
'The following keys are accepted:\n\n'
'*fieldPath*::: The LogEntry field path to index. '
'For example: jsonPayload.request.status. '
'Paths are limited to 800 characters and can include only '
'letters, digits, underscores, hyphens, and periods.\n\n'
'*type*::: The type of data in this index. '
'For example: INDEX_TYPE_STRING '
'Supported types are strings and integers. \n\n '))
parser.add_argument(
'--update-index',
action='append',
type=arg_parsers.ArgDict(
spec={
'fieldPath': str,
'type': util.IndexTypeToEnum
},
required_keys=['fieldPath', 'type']),
metavar='KEY=VALUE, ...',
help=(
'Update an index to be added to the log bucket. '
'This will update the type of the index, and also update its '
'createTime to the new update time. '
'This flag can be repeated. The ``fieldPath\'\' and ``type\'\' '
'attributes are required. For example: '
' --index=fieldPath=jsonPayload.foo,type=INDEX_TYPE_STRING. '
'The following keys are accepted:\n\n'
'*fieldPath*::: The LogEntry field path to index. '
'For example: jsonPayload.request.status. '
'Paths are limited to 800 characters and can include only '
'letters, digits, underscores, hyphens, and periods.\n\n'
'*type*::: The type of data in this index. '
'For example: INDEX_TYPE_STRING '
'Supported types are strings and integers. '))
parser.add_argument(
'--enable-analytics',
action='store_true',
default=None,
help=arg_parsers.UniverseHelpText(
default=(
'Whether to opt the bucket into Log Analytics. Once opted in,'
' the bucket cannot be opted out of Log Analytics.'
),
universe_help='This is not available.\n',
),
)
parser.add_argument(
'--cmek-kms-key-name',
help='A valid `kms_key_name` will enable CMEK for the bucket.')
base.ASYNC_FLAG.AddToParser(parser)
def GetCurrentBucket(self, args):
"""Returns a bucket specified by the arguments.
Loads the current bucket at most once. If called multiple times, the
previously-loaded bucket will be returned.
Args:
args: The argument set. This is not checked across GetCurrentBucket calls,
and must be consistent.
"""
if not self._current_bucket:
self._current_bucket = util.GetClient().projects_locations_buckets.Get(
util.GetMessages().LoggingProjectsLocationsBucketsGetRequest(
name=util.CreateResourceName(
util.CreateResourceName(
util.GetParentFromArgs(args), 'locations', args.location
),
'buckets',
args.BUCKET_ID,
)
)
)
return self._current_bucket
def _Run(self, args):
bucket_data = {}
update_mask = []
parameter_names = ['--retention-days', '--description', '--locked']
if args.IsSpecified('retention_days'):
bucket_data['retentionDays'] = args.retention_days
update_mask.append('retention_days')
if args.IsSpecified('description'):
bucket_data['description'] = args.description
update_mask.append('description')
if args.IsSpecified('locked'):
bucket_data['locked'] = args.locked
update_mask.append('locked')
if args.locked:
console_io.PromptContinue(
'WARNING: Locking a bucket cannot be undone.',
default=False,
cancel_on_no=True)
if args.IsSpecified('restricted_fields'):
bucket_data['restrictedFields'] = args.restricted_fields
update_mask.append('restricted_fields')
if args.IsSpecified('enable_analytics'):
bucket_data['analyticsEnabled'] = args.enable_analytics
update_mask.append('analytics_enabled')
if (args.IsSpecified('clear_indexes') or
args.IsSpecified('remove_indexes') or args.IsSpecified('add_index') or
args.IsSpecified('update_index')):
bucket = self.GetCurrentBucket(args)
bucket_data['indexConfigs'] = []
update_mask.append('index_configs')
indexes_to_remove = (
args.remove_indexes if args.IsSpecified('remove_indexes') else [])
indexes_to_update = (
args.update_index if args.IsSpecified('update_index') else [])
for index in bucket.indexConfigs:
if index.fieldPath in indexes_to_remove:
indexes_to_remove.remove(index.fieldPath)
else:
for i in range(len(indexes_to_update)):
if index.fieldPath == indexes_to_update[i]['fieldPath']:
for key, value in indexes_to_update[i].items():
if key == 'type':
index.type = value
indexes_to_update.pop(i)
break
bucket_data['indexConfigs'].append(index)
if indexes_to_remove:
raise calliope_exceptions.InvalidArgumentException(
'--remove-indexes',
'Indexes {0} do not exist'.format(','.join(indexes_to_remove)))
if indexes_to_update:
raise calliope_exceptions.InvalidArgumentException(
'--update-index', 'Indexes {0} do not exist'.format(','.join(
[index['fieldPath'] for index in indexes_to_update])))
if args.IsSpecified('clear_indexes'):
bucket_data['indexConfigs'] = []
if args.IsSpecified('add_index'):
bucket_data['indexConfigs'] += args.add_index
if args.IsSpecified('cmek_kms_key_name'):
bucket = self.GetCurrentBucket(args)
if not bucket.cmekSettings:
# This is the first time CMEK settings are being applied. Warn the user
# that this is irreversible.
console_io.PromptContinue(
'CMEK cannot be disabled on a bucket once enabled.',
cancel_on_no=True)
cmek_settings = util.GetMessages().CmekSettings(
kmsKeyName=args.cmek_kms_key_name)
bucket_data['cmekSettings'] = cmek_settings
update_mask.append('cmek_settings')
if not update_mask:
raise calliope_exceptions.MinimumArgumentException(
parameter_names, 'Please specify at least one property to update')
if args.async_:
result = util.GetClient().projects_locations_buckets.UpdateAsync(
util.GetMessages().LoggingProjectsLocationsBucketsUpdateAsyncRequest(
name=util.CreateResourceName(
util.CreateResourceName(
util.GetParentFromArgs(args),
'locations',
args.location,
),
'buckets',
args.BUCKET_ID,
),
logBucket=util.GetMessages().LogBucket(**bucket_data),
updateMask=','.join(update_mask),
)
)
log.UpdatedResource(result.name, 'bucket', is_async=True)
return result
else:
return util.GetClient().projects_locations_buckets.Patch(
util.GetMessages().LoggingProjectsLocationsBucketsPatchRequest(
name=util.CreateResourceName(
util.CreateResourceName(
util.GetParentFromArgs(args),
'locations',
args.location,
),
'buckets',
args.BUCKET_ID,
),
logBucket=util.GetMessages().LogBucket(**bucket_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 bucket.
"""
return self._Run(args)
Update.detailed_help = DETAILED_HELP