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,57 @@
# -*- coding: utf-8 -*- # Lint as: python3
# Copyright 2020 Google Inc. 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 apis command group for the Apigee CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Apis(base.Group):
"""Manage Apigee API proxies."""
detailed_help = {
"EXAMPLES": """
To list all the API proxies in the active Cloud Platform project, run:
$ {command} list
To get details about a specific API proxy in a specific Apigee
organization, run:
$ {command} describe PROXY_NAME --organization=ORG_NAME
To get a JSON object containing revision-level details about an API
proxy, run:
$ {command} describe PROXY_NAME --verbose --format=json
To deploy the most recent revision of an API proxy into the ``eval''
deployment environment, run:
$ {command} deploy --api=PROXY_NAME --environment=eval
To deploy the first revision of that API proxy into the ``release''
deployment environment, run:
$ {command} deploy 1 --api=PROXY_NAME --environment=release
To undeploy whatever revision of PROXY_NAME is currently deployed in
ENVIRONMENT, run:
$ {command} undeploy --api=PROXY_NAME --environment=ENVIRONMENT
""",
}

View File

@@ -0,0 +1,111 @@
# -*- coding: utf-8 -*- # Lint as: python3
# Copyright 2020 Google Inc. 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 to deploy an Apigee API proxy to an environment."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib import apigee
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.apigee import defaults
from googlecloudsdk.command_lib.apigee import resource_args
from googlecloudsdk.core import log
class Deploy(base.DescribeCommand):
"""Deploy an API proxy to an environment."""
detailed_help = {
"DESCRIPTION":
"""\
{description}
`{command}` installs an API proxy revision in an Apigee runtime environment.
By default, the API proxy's base path must not already be in use by a deployed
proxy in the target environment. To allow Apigee to undeploy any conflicting
API proxy as part of the deployment, use the `--override` command.
Once a particular revision of an API proxy has been deployed, that revision
can no longer be modified. Any updates to the API proxy must be saved as a new
revision.
""",
"EXAMPLES":
"""\
To deploy the latest revision of the API proxy named ``demo'' to the ``test''
environment, given that the API proxy and environment's matching Cloud
Platform project has been set in gcloud settings, run:
$ {command} --environment=test --api=demo
To deploy revision 3 of that proxy, owned by an organization named ``my-org'',
run, and replace any conflicting deployment that might already exist, run:
$ {command} 3 --organization=my-org --environment=test --api=demo --override
To deploy that proxy and print the resulting deployment as a JSON object, run:
$ {command} 3 --organization=my-org --environment=test --api=demo --format=json
"""
}
@staticmethod
def Args(parser):
parser.add_argument(
"--override",
action="store_true",
help=("Force the deployment of the new revision, overriding any " +
"currently deployed revision that would conflict with it.\n\n" +
"If an existing API proxy revision is deployed, set this flag " +
"to ensure seamless deployment with zero downtime. In this " +
"case, the existing revision remains deployed until the new " +
"revision is fully deployed.\n\n" +
"If unset, `{command}` will fail unless all conflicting API " +
"proxies are first undeployed from the environment. To do " +
"this, run `{parent_command} undeploy` on the conflicting " +
"deployment."))
help_text = {
"api": ("API proxy to be deployed. To get a list of available API " +
"proxies, run `{{parent_command}} list`."),
"environment": ("Environment in which to deploy the API proxy. To " +
"get a list of available environments, run " +
"`{{grandparent_command}} environments list`."),
"organization": ("Apigee organization of the proxy and environment. " +
"If unspecified, the Cloud Platform project's "
"associated organization will be used."),
}
fallthroughs = [defaults.GCPProductOrganizationFallthrough(),
defaults.StaticFallthrough("revision", "latest")]
resource_args.AddSingleResourceArgument(
parser,
"organization.environment.api.revision",
"API proxy revision to be deployed and environment in which to deploy "
"it. Revisions can either be a positive revision number, or the "
"special value ``latest'', which will deploy the latest revision of "
"the API proxy. If revision is unspecified, the default is ``latest''.",
fallthroughs=fallthroughs,
help_texts=help_text)
def Run(self, args):
"""Run the deploy command."""
identifiers = args.CONCEPTS.revision.Parse().AsDict()
if identifiers["revisionsId"] == "latest":
latest_revision = apigee.APIsClient.Describe(identifiers)["revision"][-1]
log.status.Print("Using current latest revision `%s`"%latest_revision)
identifiers["revisionsId"] = latest_revision
result = apigee.APIsClient.Deploy(identifiers, args.override)
return result

View File

@@ -0,0 +1,111 @@
# -*- coding: utf-8 -*- # Lint as: python3
# Copyright 2020 Google Inc. 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 to describe an Apigee API proxy."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib import apigee
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.apigee import defaults
from googlecloudsdk.command_lib.apigee import resource_args
class Describe(base.DescribeCommand):
"""Describe an Apigee API proxy."""
detailed_help = {
"DESCRIPTION":
"""\
{description}
`{command}` shows metadata about an API proxy and its revisions.""",
"EXAMPLES":
"""\
To describe an API proxy called ``proxy-name'' given that its matching Cloud
Platform project has been set in gcloud settings, run:
$ {command} proxy-name
To describe an API proxy called ``other-proxy-name'' in another project whose
Apigee organization is named ``org-name'', run:
$ {command} other-proxy-name --organization=org-name
To describe an API proxy called ``proxy-name'' and include details on its
revisions, run:
$ {command} proxy-name --verbose
To describe an API proxy called ``proxy-name'' as a JSON object, run:
$ {command} proxy-name --format=json
"""
}
@classmethod
def Args(cls, parser):
parser.add_argument("--verbose", action="store_true",
help="Include proxy revision info in the description.")
if cls.ReleaseTrack() == base.ReleaseTrack.ALPHA:
parser.add_argument("--revision",
help="Include proxy revision info for a specific "
"revision ID in the description.")
resource_args.AddSingleResourceArgument(
parser,
"organization.api",
"API proxy to be described. To get a list of available API proxies, "
"run `{parent_command} list`.",
fallthroughs=[defaults.GCPProductOrganizationFallthrough()])
def Run(self, args):
"""Run the describe command."""
identifiers = args.CONCEPTS.api.Parse().AsDict()
result = apigee.APIsClient.Describe(identifiers)
# Must use vars(args) to check whether there's even a revision field in the
# parsed args namespace. It's only present for ALPHA track.
requested_revision = None
if "revision" in vars(args):
requested_revision = args.revision
# If the user didn't ask for revision data, the response from
# APIsClient.Describe() is good enough.
if requested_revision is None and not args.verbose:
return result
rev_nums = result["revision"]
if requested_revision is not None:
if requested_revision not in rev_nums:
message = "No revision %r among API %s's revisions: %s"%(
requested_revision, identifiers["apisId"], rev_nums)
raise exceptions.InvalidArgumentException("--revision", message)
# No need to check whether this revision exists within the original list;
# if there's no such revision, RevisionsClient will raise an appropriate
# error.
rev_nums = [requested_revision]
revisions = []
for revision in rev_nums:
identifiers["revisionsId"] = revision
revision_result = apigee.RevisionsClient.Describe(identifiers)
del revision_result["name"]
revisions.append(revision_result)
del result["revision"]
result["revisions"] = revisions
return result

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- # Lint as: python3
# Copyright 2020 Google Inc. 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 to list all Apigee API proxies in the relevant organization."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib import apigee
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.apigee import defaults
from googlecloudsdk.command_lib.apigee import resource_args
class List(base.ListCommand):
"""List Apigee API proxies."""
detailed_help = {
"EXAMPLES":
"""\
To list all API proxies for the active Cloud Platform project, run:
$ {command}
To list all API proxies in an organization called ``my-org'', run:
$ {command} --organization=my-org
To list all API proxies in an organization called ``my-org'', formatted as a
JSON array, run:
$ {command} --organization=my-org --format=json
"""}
@staticmethod
def Args(parser):
resource_args.AddSingleResourceArgument(
parser, "organization",
"Apigee organization whose API proxies should be listed. If "
"unspecified, the Cloud Platform project's associated organization "
"will be used.",
positional=False, required=True,
fallthroughs=[defaults.GCPProductOrganizationFallthrough()])
parser.display_info.AddFormat("list")
def Run(self, args):
"""Run the list command."""
identifiers = args.CONCEPTS.organization.Parse().AsDict()
result = apigee.APIsClient.List(identifiers)
if "proxies" not in result:
return []
return (item["name"] for item in result["proxies"])

View File

@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*- # Lint as: python3
# Copyright 2020 Google Inc. 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 to undeploy an Apigee API proxy from an environment."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib import apigee
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.apigee import defaults
from googlecloudsdk.command_lib.apigee import resource_args
class Undeploy(base.SilentCommand):
"""Undeploy an Apigee API proxy from an environment."""
detailed_help = {
"EXAMPLES":
"""\
To undeploy an API proxy called ``my-api'' from the ``test'' environment of
the active Cloud Platform project, run:
$ {command} --environment=test --api=my-api
To undeploy revision 3 of an `my-api` from the `test` environment of the
organization named ``test-org'', run:
$ {command} 3 --organization=test-org --environment=test --api=my-api
"""}
@staticmethod
def Args(parser):
help_text = {
"api": "API proxy to be undeployed. Must currently be deployed. To "
"get a list of available deployed proxies, run "
"`{{grandparent_command}} deployments list --environment=ENV`.",
"environment": "Environment from which to undeploy the API proxy. To "
"get a list of available environments, run "
"`{{grandparent_command}} environments list`.",
"organization": "Apigee organization of the proxy and environment."
}
fallthroughs = [defaults.GCPProductOrganizationFallthrough(),
defaults.StaticFallthrough("revision", "auto")]
resource_args.AddSingleResourceArgument(
parser, "organization.environment.api.revision",
"API proxy revision to be undeployed and environment from which it "
"should be removed.\n\n"
"Revisions can either be a positive revision number, or the special "
"value ``auto'', which will undeploy whatever revision is currently "
"deployed. If revision is unspecified, the default is ``auto''.",
fallthroughs=fallthroughs, help_texts=help_text)
def Run(self, args):
"""Run the undeploy command."""
identifiers = args.CONCEPTS.revision.Parse().AsDict()
if identifiers["revisionsId"] == "auto":
del identifiers["revisionsId"]
defaults.FallBackToDeployedProxyRevision(identifiers)
return apigee.APIsClient.Undeploy(identifiers)