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,28 @@
# -*- 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 Deploy Policy command group for Google Cloud Deploy."""
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
@base.DefaultUniverseOnly
class DeployPolicies(base.Group):
"""Create and manage Deploy Policy resources for Google Cloud Deploy."""
category = base.CI_CD_CATEGORY

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: |
Add IAM policy binding for a Cloud Deploy Policy.
description: |
Adds a policy binding to the IAM policy of a Cloud Deploy Policy.
One binding consists of a member and a role.
See https://cloud.google.com/iam/docs/managing-policies for details of
the policy file format and contents.
examples: |
To add an IAM policy binding for the role of `roles/clouddeploy.policyAdmin`
for the user `test-user@gmail.com` on `holiday-policy` with the region
`us-central1`, run:
$ {command} holiday-policy \
--region='us-central1' \
--member='user:test-user@gmail.com' \
--role='roles/clouddeploy.policyAdmin'
request:
api_version: v1
collection: clouddeploy.projects.locations.deployPolicies
arguments:
resource:
help_text: The deploy policy for which to add the IAM policy binding.
spec: !REF googlecloudsdk.command_lib.deploy.resources:deploy_policy
is_positional: true
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: options_requestedPolicyVersion

View File

@@ -0,0 +1,21 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Delete a deploy policy.
description: Delete a deploy policy for a specified region.
examples: |
The following command will delete deploy policy `test-policy`, in region `us-central1`:
$ {command} test-policy --region=us-central1
request:
collection: clouddeploy.projects.locations.deployPolicies
api_version: v1
async:
collection: clouddeploy.projects.locations.operations
arguments:
resource:
help_text: The name of the deploy policy to delete.
spec: !REF googlecloudsdk.command_lib.deploy.resources:deploy_policy
is_positional: true

View File

@@ -0,0 +1,105 @@
# -*- 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.
"""Describes a Gcloud Deploy Policy resource."""
from apitools.base.py import encoding
from googlecloudsdk.api_lib.util import exceptions as gcloud_exception
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.deploy import deploy_policy_util
from googlecloudsdk.command_lib.deploy import exceptions as deploy_exceptions
from googlecloudsdk.command_lib.deploy import manifest_util
from googlecloudsdk.command_lib.deploy import resource_args
_DETAILED_HELP = {
'DESCRIPTION': '{description}',
'EXAMPLES': """ \
To describe a deploy policy called 'test-policy' in region 'us-central1', run:
$ {command} test-policy --region=us-central1
""",
}
def _CommonArgs(parser):
"""Register flags for this command.
Args:
parser: An argparse.ArgumentParser-like object. It is mocked out in order to
capture some information, but behaves like an ArgumentParser.
"""
resource_args.AddDeployPolicyResourceArg(parser, positional=True)
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Show details about a deploy policy."""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
_CommonArgs(parser)
@gcloud_exception.CatchHTTPErrorRaiseHTTPException(
deploy_exceptions.HTTP_ERROR_FORMAT
)
def Run(self, args):
"""This is what gets called when the user runs this command."""
policy_ref = args.CONCEPTS.deploy_policy.Parse()
# Check if the policy exists.
policy_obj = deploy_policy_util.GetDeployPolicy(policy_ref)
manifest = encoding.MessageToDict(policy_obj)
manifest_util.ApplyTransforms(
manifest,
_TRANSFORMS,
manifest_util.ResourceKind.DEPLOY_POLICY,
policy_ref.Name(),
policy_ref.projectsId,
policy_ref.locationsId,
)
return manifest
# We can't use manifest_util._EXPORT_TRANSFORMS because it has several
# transforms we don't want for `describe`. Specifically:
# * it adds `apiVersion`/`kind`
# * it moves a bunch of fields into `metadata`, and turns the `name` into an id
# * it removes fields like `createTime`/`updateTime`
_TRANSFORMS = [
manifest_util.TransformConfig(
kinds=[manifest_util.ResourceKind.DEPLOY_POLICY],
# Using the always-present `name` field to make sure this transform is
# always applied.
fields=['name'],
move=manifest_util.AddApiVersionAndKind,
),
manifest_util.TransformConfig(
kinds=[manifest_util.ResourceKind.DEPLOY_POLICY],
fields=['rules[].rolloutRestriction.timeWindows.oneTimeWindows[]'],
replace=manifest_util.ConvertPolicyOneTimeWindowToYamlFormat,
),
manifest_util.TransformConfig(
kinds=[manifest_util.ResourceKind.DEPLOY_POLICY],
fields=[
'rules[].rolloutRestriction.timeWindows.weeklyWindows[].startTime',
'rules[].rolloutRestriction.timeWindows.weeklyWindows[].endTime',
],
replace=manifest_util.ConvertTimeProtoToString,
),
]

View File

@@ -0,0 +1,79 @@
# -*- 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.
"""Exports a Cloud Deploy deploy policy resource."""
import textwrap
from googlecloudsdk.api_lib.clouddeploy import deploy_policy
from googlecloudsdk.api_lib.util import exceptions as gcloud_exception
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.deploy import exceptions as deploy_exceptions
from googlecloudsdk.command_lib.deploy import export_util
from googlecloudsdk.command_lib.deploy import manifest_util
from googlecloudsdk.command_lib.deploy import resource_args
from googlecloudsdk.command_lib.export import util as core_export_util
_DETAILED_HELP = {
'DESCRIPTION': '{description}',
'EXAMPLES': textwrap.dedent("""\
To return the .yaml definition of the deploy policy `test-policy`, in region `us-central1`, run:
$ {command} test-policy --region=us-central1
"""),
}
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
@base.DefaultUniverseOnly
class Export(base.ExportCommand):
"""Returns the .yaml definition of the specified deploy policy.
The exported yaml definition can be applied by `deploy apply` command.
"""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
resource_args.AddDeployPolicyResourceArg(parser, positional=True)
core_export_util.AddExportFlags(parser)
@gcloud_exception.CatchHTTPErrorRaiseHTTPException(
deploy_exceptions.HTTP_ERROR_FORMAT
)
def Run(self, args):
"""Entry point of the export command.
Args:
args: argparser.Namespace, an object that contains the values for the
arguments specified in the .Args() method.
"""
deploy_policy_type_ref = args.CONCEPTS.deploy_policy.Parse()
resource = deploy_policy.DeployPoliciesClient().Get(
deploy_policy_type_ref.RelativeName()
)
manifest = manifest_util.ProtoToManifest(
resource,
deploy_policy_type_ref,
manifest_util.ResourceKind.DEPLOY_POLICY,
)
export_util.Export(manifest, args)

View File

@@ -0,0 +1,25 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Get the IAM policy for a Cloud Deploy Policy.
description: |
*{command}* displays the IAM policy associated with a Cloud Deploy
Policy. If formatted as JSON, the output can be edited
and used as a policy file for *set-iam-policy*. The output includes
an "etag" field identifying the version emitted and allowing detection
of concurrent policy updates; see $ {parent_command} set-iam-policy
for additional details.
examples: |
To print the IAM policy for a deploy policy `my-holiday-policy` in region `us-central1`, run:
$ {command} my-holiday-policy --region=us-central1
request:
api_version: v1
collection: clouddeploy.projects.locations.deployPolicies
arguments:
resource:
help_text: The deploy policy for which to display the IAM policy.
spec: !REF googlecloudsdk.command_lib.deploy.resources:deploy_policy
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: options_requestedPolicyVersion

View File

@@ -0,0 +1,22 @@
- release_tracks: [ALPHA, BETA, GA]
hidden: true
help_text:
brief: List the deploy policies.
description: List the deploy policies for a specified region.
examples: |
To list the deploy policies in region `us-central1`, run:
$ {command} --region=us-central1
request:
collection: clouddeploy.projects.locations.deployPolicies
api_version: v1
response:
id_field: name
arguments:
resource:
help_text: The region for which to list the deploy policies.
spec: !REF googlecloudsdk.command_lib.deploy.resources:location
is_positional: false

View File

@@ -0,0 +1,29 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: |
Remove an IAM policy binding for a Cloud Deploy Policy.
description: |
Removes a policy binding to the IAM policy of a Cloud Deploy Policy.
One binding consists of a member and a role.
See https://cloud.google.com/iam/docs/managing-policies for details of
the policy file format and contents.
examples: |
To remove an IAM policy binding for the role of `roles/roles/clouddeploy.policyAdmin`
for the user `test-user@gmail.com` on `holiday-policy` with the region `us-central1`, run:
$ {command} holiday-policy \
--region='us-central1' \
--member='user:test-user@gmail.com' \
--role='roles/roles/clouddeploy.policyAdmin'
request:
api_version: v1
collection: clouddeploy.projects.locations.deployPolicies
arguments:
resource:
help_text: The deploy policy for which to remove the IAM policy binding.
spec: !REF googlecloudsdk.command_lib.deploy.resources:deploy_policy
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: options_requestedPolicyVersion

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: |
Set the IAM policy for a Cloud Deploy Policy.
description: |
Set the IAM policy associated with a Cloud Deploy Policy.
See https://cloud.google.com/iam/docs/managing-policies for details of
the policy file format and contents.
examples: |
The following command will read an IAM policy defined in a JSON file
`policy.json` and set it for a deploy policy with identifier
`my-holiday-policy` in region `us-central1`:
$ {command} my-holiday-policy policy.json --region=us-central1
See https://cloud.google.com/iam/docs/managing-policies for details of the
policy file format and contents.
request:
api_version: v1
collection: clouddeploy.projects.locations.deployPolicies
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.deploy.resources:deploy_policy
is_positional: true
help_text: |
The deploy policy for which to set the IAM policy.
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: options_requestedPolicyVersion