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,34 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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 scopes 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)
class Scopes(base.Group):
"""Manages Cloud Logging log scopes.
Commands for managing Cloud Logging log scopes. A scope is used to describe a
group of resources to read log entries from.
"""
category = base.MANAGEMENT_TOOLS_CATEGORY

View File

@@ -0,0 +1,109 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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 scopes 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
@base.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Create(base.CreateCommand):
"""Create a log scope.
After creating a log scope, you can use it to view logs in 1 or more
resources.
## EXAMPLES
To create a log scope in a project, run:
$ {command} my-scope --resource-names=projects/my-project
To create a log scope in a project with a description, run:
$ {command} my-scope --resource-names=projects/my-project --description="my
custom log scope"
To create a log scope that contains more than 1 resource, such as projects and
views, run:
$ {command} my-scope
--resource-names=projects/my-project,projects/my-project2,
projects/my-project/locations/global/buckets/my-bucket/views/my-view1,
projects/my-project/locations/global/buckets/my-bucket/views/my-view2,
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('LOG_SCOPE_ID', help='ID of the log scope to create.')
parser.add_argument(
'--description', help='A textual description for the log scope.'
)
parser.add_argument(
'--resource-names',
help=(
' Comma-separated list of resource names in this log scope. It'
' could be one or more parent resources or one or more views. '
' A log scope can include a maximum of 50 projects and a maximum of'
' 100 resources in total. For example, projects/[PROJECT_ID],'
' projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`'
),
metavar='RESOURCE_NAMES',
required=True,
type=arg_parsers.ArgList(),
)
util.AddParentArgs(
parser, 'log scope to create', exclude_billing_account=True
)
def _Run(self, args):
scope_data = {}
if args.IsSpecified('description'):
scope_data['description'] = args.description
if args.IsSpecified('resource_names'):
scope_data['resourceNames'] = args.resource_names
return util.GetClient().projects_locations_logScopes.Create(
util.GetMessages().LoggingProjectsLocationsLogScopesCreateRequest(
logScope=util.GetMessages().LogScope(**scope_data),
logScopeId=args.LOG_SCOPE_ID,
parent=util.CreateResourceName(
util.GetProjectResource(args.project).RelativeName(),
'locations',
'global',
),
)
)
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 log scope.
"""
return self._Run(args)

View File

@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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 scopes 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 log scope.
## EXAMPLES
To delete a log scope, run:
$ {command} my-scope
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('LOG_SCOPE_ID', help='ID of the log scope to delete.')
util.AddParentArgs(
parser, 'log scope to delete', exclude_billing_account=True
)
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 log scope [%s]? (You can not recover it after deletion)'
% args.LOG_SCOPE_ID,
cancel_on_no=True,
)
util.GetClient().projects_locations_logScopes.Delete(
util.GetMessages().LoggingProjectsLocationsLogScopesDeleteRequest(
name=util.CreateResourceName(
util.CreateResourceName(
util.GetParentFromArgs(args, exclude_billing_account=True),
'locations',
'global',
),
'logScopes',
args.LOG_SCOPE_ID,
)
)
)
log.DeletedResource(args.LOG_SCOPE_ID)

View File

@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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 scopes 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 log scope.
""",
'EXAMPLES': """
To describe a log scope in a project, run:
$ {command} my-scope --project=my-project
""",
}
@base.UniverseCompatible
class Describe(base.DescribeCommand):
"""Display information about a log scope."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument(
'LOG_SCOPE_ID', help='The ID of the log scope to describe.'
)
util.AddParentArgs(
parser, 'log scope to describe', exclude_billing_account=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:
The specified log scope.
"""
return util.GetClient().projects_locations_logScopes.Get(
util.GetMessages().LoggingProjectsLocationsLogScopesGetRequest(
name=util.CreateResourceName(
util.CreateResourceName(
util.GetParentFromArgs(args, exclude_billing_account=True),
'locations',
'global',
),
'logScopes',
args.LOG_SCOPE_ID,
)
)
)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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 scopes 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 log scopes for a project.
""",
'EXAMPLES': """
To list the log scopes in a project, run:
$ {command} --project=my-project
""",
}
@base.UniverseCompatible
class List(base.ListCommand):
"""List the defined log scopes."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
util.AddParentArgs(
parser, 'log scopes to list', exclude_billing_account=True
)
parser.display_info.AddFormat(
'table(name.segment(-3):label=LOCATION, '
'name.segment(-1):label=LOG_SCOPE_ID, '
'resource_name, description, 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 log scopes.
"""
result = util.GetClient().projects_locations_logScopes.List(
util.GetMessages().LoggingProjectsLocationsLogScopesListRequest(
parent=util.CreateResourceName(
util.GetProjectResource(args.project).RelativeName(),
'locations',
'global',
),
)
)
for scope in result.logScopes:
yield scope
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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 scopes 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
DETAILED_HELP = {
'DESCRIPTION': """
Update the properties of a log scope.
""",
'EXAMPLES': """
To update the description of a log scope in a project, run:
$ {command} my-scope --description=my-new-description --project=my-project
To update the resource name of a log scope in a project. Ensure that you
provide all the resource names including the existing ones. For example,
if the log scope has the resource name my-project, and you want to update
the log scope to have the resource name another-project, run the following:
$ {command} my-scope --resource-names=projects/my-project,projects/another-project --project=my-project
""",
}
@base.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Update(base.UpdateCommand):
"""Update a log scope.
Changes one or more properties associated with a log scope.
"""
def __init__(self, *args, **kwargs):
super(Update, self).__init__(*args, **kwargs)
self._current_scope = None
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument(
'LOG_SCOPE_ID', help='The ID of the log scope to update.'
)
parser.add_argument(
'--description', help='A new description for the log scope.'
)
parser.add_argument(
'--resource-names',
help='A new set of resource names for the log scope.',
type=arg_parsers.ArgList(),
metavar='RESOURCE_NAMES',
)
def _Run(self, args):
scope_data = {}
update_mask = []
parameter_names = ['--description', '--resource-names']
if args.IsSpecified('description'):
scope_data['description'] = args.description
update_mask.append('description')
if args.IsSpecified('resource_names'):
scope_data['resourceNames'] = args.resource_names
update_mask.append('resource_names')
if not update_mask:
raise calliope_exceptions.MinimumArgumentException(
parameter_names, 'Please specify at least one property to update'
)
return util.GetClient().projects_locations_logScopes.Patch(
util.GetMessages().LoggingProjectsLocationsLogScopesPatchRequest(
name=util.CreateResourceName(
util.CreateResourceName(
util.GetProjectResource(args.project).RelativeName(),
'locations',
'global',
),
'logScopes',
args.LOG_SCOPE_ID,
),
logScope=util.GetMessages().LogScope(**scope_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 log scope.
"""
return self._Run(args)
Update.detailed_help = DETAILED_HELP