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,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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.
"""Command group for groups."""
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.BETA, base.ReleaseTrack.GA)
class Groups(base.Group):
"""Manage Network Connectivity Center groups."""

View File

@@ -0,0 +1,47 @@
- release_tracks: [BETA]
help_text:
brief: Add an IAM policy binding to the IAM policy of a group resource.
description: |
Add an IAM policy binding to the IAM policy of a group resource. One binding consists of
a member, a role, and an optional condition.
examples: |
To grant a user the ``roles/networkconnectivity.groupUser'' role on the group called ``my-group'' in the hub called ``my-hub''', run the following command:
$ {command} my-group --member="user:username@gmail.com" --role="roles/networkconnectivity.groupUser" --hub="my-hub"
request:
collection: networkconnectivity.projects.locations.global.hubs.groups
api_version: v1beta
arguments:
resource:
help_text: The group that you want to update.
spec: !REF googlecloudsdk.command_lib.network_connectivity.resources:group
iam:
set_iam_policy_request_path: googleIamV1SetIamPolicyRequest
message_type_overrides:
policy: GoogleIamV1Policy
set_iam_policy_request: NetworkconnectivityProjectsLocationsGlobalHubsGroupsSetIamPolicyRequest
- release_tracks: [GA]
help_text:
brief: Add an IAM policy binding to the IAM policy of a group resource.
description: |
Add an IAM policy binding to the IAM policy of a group resource. One binding consists of
a member, a role, and an optional condition.
examples: |
To grant a user the ``roles/networkconnectivity.groupUser'' role on the group called ``my-group'' in the hub called ``my-hub''', run the following command:
$ {command} my-group --member="user:username@gmail.com" --role="roles/networkconnectivity.groupUser" --hub="my-hub"
request:
collection: networkconnectivity.projects.locations.global.hubs.groups
api_version: v1
arguments:
resource:
help_text: The group that you want to update.
spec: !REF googlecloudsdk.command_lib.network_connectivity.resources:group

View File

@@ -0,0 +1,23 @@
- release_tracks: [BETA, GA]
help_text:
brief: Describe a group.
description: |
Retrieve and display details about a group.
examples: |
To display details about a group named ``my-group'', run:
$ {command} my-group
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.network_connectivity.resources:group
help_text: |
Name of the group to describe.
request: &request
BETA:
api_version: v1beta
GA:
api_version: v1
collection: networkconnectivity.projects.locations.global.hubs.groups

View File

@@ -0,0 +1,23 @@
- release_tracks: [BETA, GA]
help_text:
brief: Get the IAM policy for a group resource.
description: |
Get the IAM policy of a group. If formatted as JSON, the output
can be edited and used as a policy file for *set-iam-policy*.
examples: |
To get the IAM policy for a group named ``my-group'' in the hub named ``my-hub'', run:
$ {command} my-group --hub="my-hub"
request: &request
collection: networkconnectivity.projects.locations.global.hubs.groups
BETA:
api_version: v1beta
GA:
api_version: v1
arguments:
resource:
help_text: The group for which you want the IAM policy.
spec: !REF googlecloudsdk.command_lib.network_connectivity.resources:group

View File

@@ -0,0 +1,30 @@
- release_tracks: [BETA, GA]
help_text:
brief: List groups.
description: Retrieve and display a list of all groups in the specified hub.
examples: |
To list all groups across all hubs, run:
$ {command} --hub=-
To list all groups in hub `my-hub`, run:
$ {command} --hub=my-hub
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.network_connectivity.resources:hubDefaultAll
help_text: Parent hub of the groups to display.
request: &request
BETA:
api_version: v1beta
GA:
api_version: v1
collection: networkconnectivity.projects.locations.global.hubs.groups
output:
# Columns: NAME, HUB, DESCRIPTION
format: table(name.basename():sort=2, name.segment(5):label=HUB:sort=1, description)

View File

@@ -0,0 +1,47 @@
- release_tracks: [BETA]
help_text:
brief: Remove an IAM policy binding from the IAM policy of a group resource.
description: |
Remove an IAM policy binding from the IAM policy of a group resource.
examples: |
To remove the ``roles/networkconnectivity.groupUser'' role from a user of the group ``my-group'' in the hub ``my-hub'',
run:
$ {command} my-group --member="user:username@gmail.com" --role="roles/networkconnectivity.groupUser" --hub="my-hub"
request:
collection: networkconnectivity.projects.locations.global.hubs.groups
api_version: v1beta
arguments:
resource:
help_text: The group that you want to update.
spec: !REF googlecloudsdk.command_lib.network_connectivity.resources:group
iam:
set_iam_policy_request_path: googleIamV1SetIamPolicyRequest
message_type_overrides:
policy: GoogleIamV1Policy
set_iam_policy_request: NetworkconnectivityProjectsLocationsGlobalHubsGroupsSetIamPolicyRequest
- release_tracks: [GA]
help_text:
brief: Remove an IAM policy binding from the IAM policy of a group resource.
description: |
Remove an IAM policy binding from the IAM policy of a group resource.
examples: |
To remove the ``roles/networkconnectivity.groupUser'' role from a user of the group ``my-group'' in the hub ``my-hub'',
run:
$ {command} my-group --member="user:username@gmail.com" --role="roles/networkconnectivity.groupUser" --hub="my-hub"
request:
collection: networkconnectivity.projects.locations.global.hubs.groups
api_version: v1
arguments:
resource:
help_text: The group that you want to update.
spec: !REF googlecloudsdk.command_lib.network_connectivity.resources:group

View File

@@ -0,0 +1,49 @@
- release_tracks: [BETA]
help_text:
brief: Set the IAM policy of a group resource.
description: |
Replace the existing IAM policy of a group resource with a policy
encoded in a JSON or YAML file.
examples: |
To replace the IAM policy of a group resource with the policy defined in a
file called ``policy.json'', run:
$ {command} my-group policy.json --hub="my-hub"
request:
collection: networkconnectivity.projects.locations.global.hubs.groups
api_version: v1beta
arguments:
resource:
help_text: The hub for which to set the IAM policy.
spec: !REF googlecloudsdk.command_lib.network_connectivity.resources:group
iam:
set_iam_policy_request_path: googleIamV1SetIamPolicyRequest
message_type_overrides:
policy: GoogleIamV1Policy
set_iam_policy_request: NetworkconnectivityProjectsLocationsGlobalHubsGroupsSetIamPolicyRequest
- release_tracks: [GA]
help_text:
brief: Set the IAM policy of a group resource.
description: |
Replace the existing IAM policy of a group resource with a policy
encoded in a JSON or YAML file.
examples: |
To replace the IAM policy of a group resource with the policy defined in a
file called ``policy.json'', run:
$ {command} my-group policy.json --hub="my-hub"
request:
collection: networkconnectivity.projects.locations.global.hubs.groups
api_version: v1
arguments:
resource:
help_text: The hub for which to set the IAM policy.
spec: !REF googlecloudsdk.command_lib.network_connectivity.resources:group

View File

@@ -0,0 +1,192 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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.
"""Command for updating groups."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.network_connectivity import networkconnectivity_api
from googlecloudsdk.api_lib.network_connectivity import networkconnectivity_util
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.network_connectivity import flags
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.command_lib.util.args import repeated
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class Update(base.Command):
"""Update a group.
Update the details of a group.
"""
@staticmethod
def Args(parser):
flags.AddGroupResourceArg(parser, 'to update')
flags.AddDescriptionFlag(parser, 'New description of the group.')
flags.AddAsyncFlag(parser)
labels_util.AddUpdateLabelsFlags(parser)
repeated.AddPrimitiveArgs(
parser,
'group',
'auto-accept-projects',
'auto-accept projects',
additional_help="""This controls the list of project ids or
project numbers for which auto-accept is enabled for the group.""",
include_set=False,
)
def UpdateGroupBeta(self, client, group_ref, args):
update_mask = []
description = args.description
if description is not None:
update_mask.append('description')
labels = None
labels_diff = labels_util.Diff.FromUpdateArgs(args)
original_group = client.Get(group_ref)
if labels_diff.MayHaveUpdates():
labels_update = labels_diff.Apply(
client.messages.GoogleCloudNetworkconnectivityV1betaGroup.LabelsValue,
original_group.labels,
)
if labels_update.needs_update:
labels = labels_update.labels
update_mask.append('labels')
# TODO: b/349140768 - Add e2e test for this command.
def _get_current_auto_accept_projects():
if original_group.autoAccept is None:
return []
return original_group.autoAccept.autoAcceptProjects
auto_accept_projects = repeated.ParsePrimitiveArgs(
args, 'auto_accept_projects', _get_current_auto_accept_projects
)
auto_accept = None
if auto_accept_projects is not None:
auto_accept = (
client.messages.GoogleCloudNetworkconnectivityV1betaAutoAccept(
autoAcceptProjects=auto_accept_projects
)
)
update_mask.append('auto_accept.auto_accept_projects')
# Construct a group message with only the updated fields
group = client.messages.GoogleCloudNetworkconnectivityV1betaGroup(
description=description, labels=labels, autoAccept=auto_accept
)
return client.UpdateGroupBeta(group_ref, group, update_mask)
def UpdateGroupGA(self, client, group_ref, args):
update_mask = []
description = args.description
if description is not None:
update_mask.append('description')
labels = None
labels_diff = labels_util.Diff.FromUpdateArgs(args)
original_group = client.Get(group_ref)
if labels_diff.MayHaveUpdates():
labels_update = labels_diff.Apply(
client.messages.Group.LabelsValue, original_group.labels
)
if labels_update.needs_update:
labels = labels_update.labels
update_mask.append('labels')
# TODO(b/349140768): Add e2e test for this command.
def _get_current_auto_accept_projects():
if original_group.autoAccept is None:
return []
return original_group.autoAccept.autoAcceptProjects
auto_accept_projects = repeated.ParsePrimitiveArgs(
args, 'auto_accept_projects', _get_current_auto_accept_projects
)
auto_accept = None
if auto_accept_projects is not None:
auto_accept = client.messages.AutoAccept(
autoAcceptProjects=auto_accept_projects
)
update_mask.append('auto_accept.auto_accept_projects')
# Construct a group message with only the updated fields
group = client.messages.Group(
description=description, labels=labels, autoAccept=auto_accept
)
return client.UpdateGroup(group_ref, group, update_mask)
def Run(self, args):
client = networkconnectivity_api.GroupsClient(
release_track=self.ReleaseTrack()
)
group_ref = args.CONCEPTS.group.Parse()
if self.ReleaseTrack() == base.ReleaseTrack.BETA:
op_ref = self.UpdateGroupBeta(client, group_ref, args)
else:
op_ref = self.UpdateGroupGA(client, group_ref, args)
log.status.Print('Update request issued for: [{}]'.format(group_ref.Name()))
if op_ref.done:
log.UpdatedResource(group_ref.Name(), kind='group')
return op_ref
if args.async_:
log.status.Print('Check operation [{}] for status.'.format(op_ref.name))
return op_ref
op_resource = resources.REGISTRY.ParseRelativeName(
op_ref.name,
collection='networkconnectivity.projects.locations.operations',
api_version=networkconnectivity_util.VERSION_MAP[self.ReleaseTrack()],
)
poller = waiter.CloudOperationPoller(
client.group_service, client.operation_service
)
res = waiter.WaitFor(
poller,
op_resource,
'Waiting for operation [{}] to complete'.format(op_ref.name),
)
log.UpdatedResource(group_ref.Name(), kind='group')
return res
Update.detailed_help = {
'EXAMPLES': """\
To update the description of a group named ``my-group'', in the hub ``my-hub'', run:
$ {command} my-group --hub=my-hub --description="new group description"
To add the project ``my-project'' to the auto-accept list of a group named ``my-group'' in the hub ``my-hub'', run:
$ {command} my-group --hub=my-hub --add-auto-accept-projects=my-project
""",
'API REFERENCE': """ \
This command uses the networkconnectivity/v1 API. The full documentation
for this API can be found at:
https://cloud.google.com/network-connectivity/docs/reference/networkconnectivity/rest
""",
}