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,33 @@
# -*- 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.
"""Cloud Storage management hubs commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.Deprecate(is_removed=False, warning='This command group is deprecated. '
'Use `gcloud alpha storage intelligence-configs` command group '
'instead.')
# TODO: b/369949089 - Remove default universe flag after checking the
# availability of management hub in different universes.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class ManagementHub(base.Group):
"""Manage Cloud Storage Management Hub."""

View File

@@ -0,0 +1,53 @@
# -*- 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.
"""Implementation of describe command for describing management hub."""
from googlecloudsdk.api_lib.storage import management_hub_api
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import flags
# TODO: b/369949089 - Remove default universe flag after checking the
# availability of management hub in different universes.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Describe(base.DescribeCommand):
"""Describes Management Hub."""
detailed_help = {
'DESCRIPTION': """
Describe management hub for the organization, sub-folder
or project.
""",
'EXAMPLES': """
The following command describes management hub for the sub-folder with
id `123456`. \n
${command} --sub-folder=123456
""",
}
@classmethod
def Args(cls, parser):
flags.add_management_hub_level_flags(parser)
def Run(self, args):
client = management_hub_api.ManagementHubApi()
if args.sub_folder:
return client.get_sub_folder_management_hub(args.sub_folder)
elif args.project:
return client.get_project_management_hub(args.project)
elif args.organization:
return client.get_organization_management_hub(args.organization)

View File

@@ -0,0 +1,61 @@
# -*- 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.
"""Implementation of disable command for disabling management hub."""
from googlecloudsdk.api_lib.storage import management_hub_api
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import flags
from googlecloudsdk.core import log
# TODO: b/369949089 - Remove default universe flag after checking the
# availability of management hub in different universes.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Disable(base.Command):
"""Disables Management Hub."""
detailed_help = {
'DESCRIPTION': """
Disable management hub for the organization, sub-folder or project.
""",
'EXAMPLES': """
The following command disables management hub for the project. \n
${command} --project=my-project
""",
}
@classmethod
def Args(cls, parser):
flags.add_management_hub_level_flags(parser)
def Run(self, args):
client = management_hub_api.ManagementHubApi()
if args.sub_folder:
management_hub = client.disable_sub_folder_management_hub(args.sub_folder)
elif args.project:
management_hub = client.disable_project_management_hub(args.project)
else:
management_hub = client.disable_organization_management_hub(
args.organization
)
log.status.Print(
'Successfully disabled management hub plan for {}.\n'.format(
management_hub.name
)
)
return management_hub

View File

@@ -0,0 +1,99 @@
# -*- 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.
"""Implementation of enable command for enabling management hub."""
from googlecloudsdk.api_lib.storage import management_hub_api
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import flags
from googlecloudsdk.core import log
# TODO: b/369949089 - Remove default universe flag after checking the
# availability of management hub in different universes.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Enable(base.Command):
"""Enables Management Hub."""
detailed_help = {
'DESCRIPTION': """
Enable management hub plan for the organization, sub-folder or project
along with filters.
""",
'EXAMPLES': """
To remove buckets from the management hub plan, Use the following
command with ``--exclude-bucket-ids'' and ``--exclude-bucket-regexes'' flags
to specify list of bucket ids and bucket id regexes.,\n
${command} --organization=my-org --exclude-bucket-ids="my-bucket" --exclude-bucket-regexes="my-bucket-.*"
To apply location based filters in the management hub plan, Use
``--include-locations'' or ``--exclude-locations'' flags to specify allowed
list of locations or excluded list of locations. The following
command updates management hub plan of sub-folder `123456` with the
specified list of included locations.,\n
${command} --sub-folder=123456 --include-locations="us-east1","us-west1"
""",
}
@classmethod
def Args(cls, parser):
parser.SetSortArgs(False)
flags.add_management_hub_level_flags(parser)
flags.add_management_hub_filter_flags(parser)
def Run(self, args):
if args.project:
management_hub = (
management_hub_api.ManagementHubApi().update_project_management_hub(
args.project,
inherit_from_parent=None,
include_locations=args.include_locations,
exclude_locations=args.exclude_locations,
include_bucket_ids=args.include_bucket_ids,
exclude_bucket_ids=args.exclude_bucket_ids,
include_bucket_id_regexes=args.include_bucket_id_regexes,
exclude_bucket_id_regexes=args.exclude_bucket_id_regexes,
)
)
elif args.sub_folder:
management_hub = management_hub_api.ManagementHubApi().update_sub_folder_management_hub(
args.sub_folder,
inherit_from_parent=None,
include_locations=args.include_locations,
exclude_locations=args.exclude_locations,
include_bucket_ids=args.include_bucket_ids,
exclude_bucket_ids=args.exclude_bucket_ids,
include_bucket_id_regexes=args.include_bucket_id_regexes,
exclude_bucket_id_regexes=args.exclude_bucket_id_regexes,
)
else:
management_hub = management_hub_api.ManagementHubApi().update_organization_management_hub(
args.organization,
inherit_from_parent=None,
include_locations=args.include_locations,
exclude_locations=args.exclude_locations,
include_bucket_ids=args.include_bucket_ids,
exclude_bucket_ids=args.exclude_bucket_ids,
include_bucket_id_regexes=args.include_bucket_id_regexes,
exclude_bucket_id_regexes=args.exclude_bucket_id_regexes,
)
log.status.Print(
'Successfully enabled management hub plan for {}.\n'.format(
management_hub.name
)
)
return management_hub

View File

@@ -0,0 +1,131 @@
# -*- 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.
"""Implementation of update command for updating management hub."""
from googlecloudsdk.api_lib.storage import management_hub_api
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import flags
from googlecloudsdk.core import log
# TODO: b/369949089 - Remove default universe flag after checking the
# availability of management hub in different universes.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Update(base.Command):
"""Updates Management Hub."""
detailed_help = {
'DESCRIPTION': """
Update management hub plan for the organization, sub-folder
or project.
""",
'EXAMPLES': """
To limit buckets in the management hub plan, Use the following
command with ``--include-bucket-ids'' and ``--include-bucket-regexes'' flags
to specify list of bucket ids and bucket id regexes.,\n
${command} --organization=my-org --include-bucket-ids=my-bucket --include-bucket-regexes=my-bucket-.*
To apply location based filters in the management hub plan, Use
``--include-locations'' or ``--exclude-locations'' flags to specify allowed
list of locations or excluded list of locations. The following
command updates management hub plan of sub-folder `123456` with the
specified list of excluded locations.,\n
${command} --sub-folder=123456 --exclude-locations=us-east1,us-west1
The following command updates management hub for the given project by
inheriting existing management hub plan from the hierarchical parent
resource.,\n
${command} --project=my-project --inherit-from-parent
To clear included locations from the project management hub, Use the
following command.,\n
${command} --project=my-project --include-locations=
To clear excluded bucket ids from the project management hub and to
replace existing excluded bucket ids regexes, Use the following
command.,\n
${command} --project=my-project --exclude-bucket-id-regexes="test1*","test2*" --exclude-bucket-ids=""
Alternatively, use the following command to do same operation since
the absense of cloud storage bucket filter flags will be considered
as empty list,\n
${command} --project=my-project --exclude-bucket-id-regexes="test1*","test2*"
""",
}
@classmethod
def Args(cls, parser):
parser.SetSortArgs(False)
flags.add_management_hub_level_flags(parser)
update_group = parser.add_group(
category='UPDATE', mutex=True, required=True
)
update_group.add_argument(
'--inherit-from-parent',
action='store_true',
help='Specifies management hub config to be inherited from parent.',
)
filters = update_group.add_group(category='FILTER')
flags.add_management_hub_filter_flags(filters)
def Run(self, args):
if args.project:
management_hub = (
management_hub_api.ManagementHubApi().update_project_management_hub(
args.project,
inherit_from_parent=args.inherit_from_parent,
include_locations=args.include_locations,
exclude_locations=args.exclude_locations,
include_bucket_ids=args.include_bucket_ids,
exclude_bucket_ids=args.exclude_bucket_ids,
include_bucket_id_regexes=args.include_bucket_id_regexes,
exclude_bucket_id_regexes=args.exclude_bucket_id_regexes,
)
)
elif args.sub_folder:
management_hub = (
management_hub_api.ManagementHubApi().update_sub_folder_management_hub(
args.sub_folder,
inherit_from_parent=args.inherit_from_parent,
include_locations=args.include_locations,
exclude_locations=args.exclude_locations,
include_bucket_ids=args.include_bucket_ids,
exclude_bucket_ids=args.exclude_bucket_ids,
include_bucket_id_regexes=args.include_bucket_id_regexes,
exclude_bucket_id_regexes=args.exclude_bucket_id_regexes,
)
)
else:
management_hub = (
management_hub_api.ManagementHubApi().update_organization_management_hub(
args.organization,
inherit_from_parent=args.inherit_from_parent,
include_locations=args.include_locations,
exclude_locations=args.exclude_locations,
include_bucket_ids=args.include_bucket_ids,
exclude_bucket_ids=args.exclude_bucket_ids,
include_bucket_id_regexes=args.include_bucket_id_regexes,
exclude_bucket_id_regexes=args.exclude_bucket_id_regexes,
)
)
log.status.Print(
'Successfully updated management hub plan for {}.\n'.format(
management_hub.name
)
)
return management_hub