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

View File

@@ -0,0 +1,35 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: |
Add IAM policy binding for a Cloud Deploy delivery pipeline.
description: |
Adds a policy binding to the IAM policy of a Cloud Deploy delivery
pipeline. 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.operator'
for the user 'test-user@gmail.com' on 'my-pipeline' with the region
'us-central1', run:
$ {command} my-pipeline \
--region='us-central1' \
--member='user:test-user@gmail.com' \
--role='roles/clouddeploy.operator'
request:
api_version: v1
collection: clouddeploy.projects.locations.deliveryPipelines
arguments:
resource:
help_text: The delivery pipeline for which to add the IAM policy binding.
spec: !REF googlecloudsdk.command_lib.deploy.resources:delivery_pipeline
is_positional: true
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: options_requestedPolicyVersion

View File

@@ -0,0 +1,36 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Delete a delivery pipeline.
description: Delete a delivery pipeline.
examples: |
The following command will delete delivery pipeline 'test-pipeline', in region 'us-central1',
but only if the delivery pipeline doesn't have any sub-resources (targets, releases or rollouts):
$ {command} test-pipeline --region=us-central1
The following command will delete delivery pipeline 'test-pipeline', in region 'us-central1'
and its sub-resources (targets, releases or rollouts):
$ {command} test-pipeline --region=us-central1 --force
request:
collection: clouddeploy.projects.locations.deliveryPipelines
api_version: v1
async:
collection: clouddeploy.projects.locations.operations
arguments:
resource:
help_text: The Cloud Deploy delivery pipeline to delete.
spec: !REF googlecloudsdk.command_lib.deploy.resources:delivery_pipeline
is_positional: true
params:
- arg_name: force
api_field: force
action: store_true
help_text: If true, the delivery pipeline with sub-resources will be deleted
and its sub-resources will also be deleted.
input:
confirmation_prompt: Once a delivery pipeline is deleted, it cannot be recovered.

View File

@@ -0,0 +1,113 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 delivery pipeline resource."""
from apitools.base.py import exceptions as apitools_exceptions
from googlecloudsdk.api_lib.clouddeploy import delivery_pipeline
from googlecloudsdk.api_lib.util import exceptions as gcloud_exception
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.deploy import describe
from googlecloudsdk.command_lib.deploy import exceptions as deploy_exceptions
from googlecloudsdk.command_lib.deploy import resource_args
from googlecloudsdk.command_lib.deploy import target_util
from googlecloudsdk.core import log
_DETAILED_HELP = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
""" \
To describe a delivery pipeline called 'test-pipeline' in region 'us-central1', run:
$ {command} test-pipeline --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.AddDeliveryPipelineResourceArg(parser, positional=True)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Show details about a delivery pipeline.
The output contains the following sections:
Delivery Pipeline:
- detail of the delivery pipeline to be described.
Targets:
- target name.
- active release in the target.
- timestamp of the last successful deployment.
- list of the rollouts that require approval.
"""
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."""
pipeline_ref = args.CONCEPTS.delivery_pipeline.Parse()
# Check if the pipeline exists.
pipeline = delivery_pipeline.DeliveryPipelinesClient().Get(
pipeline_ref.RelativeName()
)
output = {'Delivery Pipeline': pipeline}
region = pipeline_ref.AsDict()['locationsId']
targets = []
# output the deployment status of the targets in the pipeline.
for stage in pipeline.serialPipeline.stages:
target_ref = target_util.TargetReference(
stage.targetId,
pipeline_ref.AsDict()['projectsId'], region)
try:
target_obj = target_util.GetTarget(target_ref)
except apitools_exceptions.HttpError as error:
log.debug('Failed to get target {}: {}'.format(stage.targetId, error))
log.status.Print('Unable to get target {}'.format(stage.targetId))
continue
detail = {'Target': target_ref.RelativeName()}
current_rollout = target_util.GetCurrentRollout(target_ref, pipeline_ref)
detail = describe.SetCurrentReleaseAndRollout(current_rollout, detail)
if target_obj.requireApproval:
detail = describe.ListPendingApprovals(target_ref, pipeline_ref, detail)
targets.append(detail)
output['Targets'] = targets
return output

View File

@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 Gcloud Deploy delivery pipeline resource."""
import textwrap
from googlecloudsdk.api_lib.clouddeploy import delivery_pipeline
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 delivery pipeline 'test-pipeline', in region 'us-central1', run:
$ {command} test-pipeline --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 delivery pipeline.
The exported yaml definition can be applied by 'deploy apply' command.
"""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
resource_args.AddDeliveryPipelineResourceArg(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: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
"""
pipeline_ref = args.CONCEPTS.delivery_pipeline.Parse()
pipeline = delivery_pipeline.DeliveryPipelinesClient().Get(
pipeline_ref.RelativeName()
)
manifest = manifest_util.ProtoToManifest(
pipeline, pipeline_ref, manifest_util.ResourceKind.DELIVERY_PIPELINE)
export_util.Export(manifest, args)

View File

@@ -0,0 +1,30 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Get the IAM policy for a Cloud Deploy delivery pipeline.
description: |
*{command}* displays the IAM policy associated with a Cloud Deploy
delivery pipeline. 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 delivery pipeline ``my-pipeline'', run:
$ {command} my-pipeline --region=us-central1
request:
api_version: v1
collection: clouddeploy.projects.locations.deliveryPipelines
arguments:
resource:
help_text: The delivery pipeline for which to display the IAM policy.
spec: !REF googlecloudsdk.command_lib.deploy.resources:delivery_pipeline
is_positional: true
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]
help_text:
brief: List Cloud Deploy delivery pipelines.
description: |
List your Cloud Deploy delivery pipelines.
examples: |
To list the delivery pipelines in region 'us-central1', run:
$ {command} --region=us-central1
request:
collection: clouddeploy.projects.locations.deliveryPipelines
api_version: v1
response:
id_field: name
arguments:
resource:
help_text: The location for which you want to list the delivery pipelines.
spec: !REF googlecloudsdk.command_lib.deploy.resources:location

View File

@@ -0,0 +1,34 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: |
Remove an IAM policy binding for a Cloud Deploy delivery pipeline.
description: |
Removes a policy binding to the IAM policy of a Cloud Deploy delivery
pipeline. 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/clouddeploy.operator' for the user
'test-user@gmail.com' on 'my-pipeline' with the region 'us-central1', run:
$ {command} my-pipeline \
--region='us-central1' \
--member='user:test-user@gmail.com' \
--role='roles/clouddeploy.operator'
request:
api_version: v1
collection: clouddeploy.projects.locations.deliveryPipelines
arguments:
resource:
help_text: The delivery pipeline for which to remove the IAM policy binding.
spec: !REF googlecloudsdk.command_lib.deploy.resources:delivery_pipeline
is_positional: true
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: options_requestedPolicyVersion

View File

@@ -0,0 +1,36 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: |
Set the IAM policy for a Cloud Deploy delivery pipeline.
description: |
Set the IAM policy associated with a Cloud Deploy delivery pipeline.
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 delivery pipeline with identifier
``my-pipeline''
$ {command} my-pipeline 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.deliveryPipelines
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.deploy.resources:delivery_pipeline
is_positional: true
help_text: |
The delivery pipeline for which to set the IAM policy..
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: options_requestedPolicyVersion