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,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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.
"""Commands for reading and manipulating SSL certificates."""
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.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class SslCertificates(base.Group):
"""List, create, and delete Compute Engine SSL certificate resources.
List, create, and delete Compute Engine SSL certificate resources that you can
use to encrypt traffic between clients and a load balancer. An SSL
certificate resource contains both a private key and the SSL certificate
itself. You refer to the SSL certificate resource in the target SSL proxy or
the target HTTPS proxy.
The relevant load balancer types are Proxy Network Load Balancers and
Application Load Balancers. For more information, see:
[SSL certificates
documentation](https://cloud.google.com/load-balancing/docs/ssl-certificates)
"""
SslCertificates.category = base.LOAD_BALANCING_CATEGORY
SslCertificates.detailed_help = {
'DESCRIPTION': """
Read and manipulate SSL certificates that encrypt
traffic between clients and a load balancer. The relevant
load balancer types are Application Load Balancers and proxy Network Load Balancers.
For more information about SSL certificates, see the
[SSL certificates documentation](https://cloud.google.com/load-balancing/docs/ssl-certificates).
See also: [SSL certificates API](https://cloud.google.com/compute/docs/reference/rest/v1/sslCertificates)
and [regional SSL certificates API](https://cloud.google.com/compute/docs/reference/rest/v1/regionSslCertificates).
""",
}

View File

@@ -0,0 +1,177 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 creating SSL certificates."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import exceptions as compute_exceptions
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.ssl_certificates import flags
from googlecloudsdk.command_lib.compute.ssl_certificates import ssl_certificates_utils
from googlecloudsdk.core.util import files
def _Args(parser):
"""Add the SSL certificates command line flags to the parser."""
parser.add_argument(
'--description',
help='An optional, textual description for the SSL certificate.')
parser.display_info.AddCacheUpdater(flags.SslCertificatesCompleterBeta)
managed_or_not = parser.add_group(
mutex=True,
required=True,
help='Flags for managed or self-managed certificate. ')
managed_or_not.add_argument(
'--domains',
metavar='DOMAIN',
type=arg_parsers.ArgList(min_length=1),
default=[],
help="""\
List of domains to create a managed certificate for.
""")
not_managed = managed_or_not.add_group('Flags for self-managed certificate')
not_managed.add_argument(
'--certificate',
metavar='LOCAL_FILE_PATH',
required=True,
help="""\
Path to a local certificate file to create a self-managed
certificate. The certificate must be in PEM format. The certificate
chain must be no greater than 5 certs long. The chain must include at
least one intermediate cert.
""")
not_managed.add_argument(
'--private-key',
metavar='LOCAL_FILE_PATH',
required=True,
help="""\
Path to a local private key file. The private key must be in PEM
format and must use RSA or ECDSA encryption.
""")
def _Run(args, holder, ssl_certificate_ref):
"""Make a SslCertificates.Insert request."""
client = holder.client
if args.domains:
if ssl_certificates_utils.IsRegionalSslCertificatesRef(ssl_certificate_ref):
raise compute_exceptions.ArgumentError(
'--domains flag is not supported for regional certificates')
request = client.messages.ComputeSslCertificatesInsertRequest(
sslCertificate=client.messages.SslCertificate(
type=client.messages.SslCertificate.TypeValueValuesEnum.MANAGED,
name=ssl_certificate_ref.Name(),
managed=client.messages.SslCertificateManagedSslCertificate(
domains=args.domains),
description=args.description),
project=ssl_certificate_ref.project)
collection = client.apitools_client.sslCertificates
else:
certificate = files.ReadFileContents(args.certificate)
private_key = files.ReadFileContents(args.private_key)
if ssl_certificates_utils.IsRegionalSslCertificatesRef(ssl_certificate_ref):
request = client.messages.ComputeRegionSslCertificatesInsertRequest(
sslCertificate=client.messages.SslCertificate(
name=ssl_certificate_ref.Name(),
certificate=certificate,
privateKey=private_key,
description=args.description),
region=ssl_certificate_ref.region,
project=ssl_certificate_ref.project)
collection = client.apitools_client.regionSslCertificates
else:
request = client.messages.ComputeSslCertificatesInsertRequest(
sslCertificate=client.messages.SslCertificate(
name=ssl_certificate_ref.Name(),
certificate=certificate,
privateKey=private_key,
description=args.description),
project=ssl_certificate_ref.project)
collection = client.apitools_client.sslCertificates
return client.MakeRequests([(collection, 'Insert', request)])
@base.UnicodeIsSupported
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Create(base.CreateCommand):
"""Create a Compute Engine SSL certificate resource.
*{command}* is used to create SSL certificate resources. An SSL certificate
resource consists of the certificate itself and a private key. The private key
is encrypted before it is stored.
You can create either a managed or a self-managed SslCertificate resource. A
managed SslCertificate is provisioned and renewed for you, when you specify
the `--domains` flag. A self-managed certificate is created by passing the
certificate obtained from Certificate Authority through `--certificate` and
`--private-key` flags.
"""
SSL_CERTIFICATE_ARG = None
@classmethod
def Args(cls, parser):
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
cls.SSL_CERTIFICATE_ARG = flags.SslCertificateArgument()
cls.SSL_CERTIFICATE_ARG.AddArgument(parser, operation_type='create')
_Args(parser)
def Run(self, args):
"""Issues the request necessary for adding the SSL certificate."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
ssl_certificate_ref = self.SSL_CERTIFICATE_ARG.ResolveAsResource(
args, holder.resources, default_scope=compute_scope.ScopeEnum.GLOBAL)
return _Run(args, holder, ssl_certificate_ref)
Create.detailed_help = {
'brief':
'Create a Compute Engine SSL certificate',
'DESCRIPTION':
"""\
*{command}* creates SSL certificate resources, which you can use in a
target HTTPS or target SSL proxy. An SSL certificate resource consists
of a certificate and private key. The private key is encrypted before it
is stored.
You can create either a managed or a self-managed SslCertificate
resource. A managed SslCertificate is provisioned and renewed for you. A
self-managed certificate is created by passing the
certificate obtained from Certificate Authority through `--certificate`
and `--private-key` flags.
""",
'EXAMPLES':
"""\
To create a self-managed certificate resource 'my-cert' from a
certificate placed under path
'foo/cert' and a private key placed under path 'foo/pk', run:
$ {command} my-cert --certificate=foo/cert --private-key=foo/pk
""",
}

View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 deleting SSL certificates."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.ssl_certificates import flags
from googlecloudsdk.command_lib.compute.ssl_certificates import ssl_certificates_utils
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Delete Compute Engine SSL certificates.
*{command}* deletes one or more Compute Engine SSL certificate resources.
SSL certificate resources can only be deleted when no other resources (for
example, target HTTPS proxies) refer to them.
"""
SSL_CERTIFICATE_ARG = None
@staticmethod
def Args(parser):
Delete.SSL_CERTIFICATE_ARG = flags.SslCertificateArgument(plural=True)
Delete.SSL_CERTIFICATE_ARG.AddArgument(parser, operation_type='delete')
parser.display_info.AddCacheUpdater(flags.SslCertificatesCompleterBeta)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
ssl_certificate_refs = Delete.SSL_CERTIFICATE_ARG.ResolveAsResource(
args,
holder.resources,
default_scope=compute_scope.ScopeEnum.GLOBAL,
scope_lister=compute_flags.GetDefaultScopeLister(client))
utils.PromptForDeletion(ssl_certificate_refs)
requests = []
for ssl_certificate_ref in ssl_certificate_refs:
if ssl_certificates_utils.IsRegionalSslCertificatesRef(
ssl_certificate_ref):
requests.append(
(client.apitools_client.regionSslCertificates, 'Delete',
client.messages.ComputeRegionSslCertificatesDeleteRequest(
**ssl_certificate_ref.AsDict())))
else:
requests.append((client.apitools_client.sslCertificates, 'Delete',
client.messages.ComputeSslCertificatesDeleteRequest(
**ssl_certificate_ref.AsDict())))
return client.MakeRequests(requests)
Delete.detailed_help = {
'brief':
'Delete Compute Engine SSL certificates',
'DESCRIPTION':
"""\
*{command}* deletes one or more Compute Engine SSL certificate
resources. SSL certificates can only be deleted when no other resources
(for example, target HTTPS proxies) refer to them.
""",
'EXAMPLES':
"""\
To delete a certificate resource 'my-cert', run:
$ {command} my-cert
To delete certificate resources 'my-cert1', 'my-cert2' and 'my-cert3',
run:
$ {command} my-cert1 my-cert2 my-cert3
""",
}

View File

@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 describing SSL certificate resources."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.ssl_certificates import flags
from googlecloudsdk.command_lib.compute.ssl_certificates import ssl_certificates_utils
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.UnicodeIsSupported
class Describe(base.DescribeCommand):
"""Describe a Compute Engine SSL certificate.
*{command}* displays all data (except private keys) associated with
Compute Engine SSL certificate resources in a project.
"""
SSL_CERTIFICATE_ARG = None
@staticmethod
def Args(parser):
Describe.SSL_CERTIFICATE_ARG = flags.SslCertificateArgument(
global_help_text='(Default) If set, the SSL certificate is global.')
Describe.SSL_CERTIFICATE_ARG.AddArgument(parser, operation_type='describe')
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
ssl_certificate_ref = self.SSL_CERTIFICATE_ARG.ResolveAsResource(
args,
holder.resources,
default_scope=compute_scope.ScopeEnum.GLOBAL,
scope_lister=compute_flags.GetDefaultScopeLister(client))
if ssl_certificates_utils.IsRegionalSslCertificatesRef(ssl_certificate_ref):
request = client.messages.ComputeRegionSslCertificatesGetRequest(
**ssl_certificate_ref.AsDict())
collection = client.apitools_client.regionSslCertificates
else:
request = client.messages.ComputeSslCertificatesGetRequest(
**ssl_certificate_ref.AsDict())
collection = client.apitools_client.sslCertificates
return client.MakeRequests([(collection, 'Get', request)])[0]
Describe.detailed_help = {
'brief':
'Describe a Compute Engine SSL certificate',
'DESCRIPTION':
"""\
*{command}* displays all data (except private keys) associated with
Compute Engine SSL certificate resources in a project.
""",
'EXAMPLES':
"""\
To display a description of a certificate 'my-cert', run:
$ {command} my-cert
""",
}

View File

@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 listing SSL certificate resources."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import lister
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.ssl_certificates import flags
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA,
base.ReleaseTrack.ALPHA)
class List(base.ListCommand):
"""List Compute Engine SSL certificates."""
@staticmethod
def Args(parser):
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
lister.AddMultiScopeListerFlags(parser, regional=True, global_=True)
parser.display_info.AddCacheUpdater(flags.SslCertificatesCompleterBeta)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
request_data = lister.ParseMultiScopeFlags(args, holder.resources)
list_implementation = lister.MultiScopeLister(
client,
regional_service=client.apitools_client.regionSslCertificates,
global_service=client.apitools_client.sslCertificates,
aggregation_service=client.apitools_client.sslCertificates)
return lister.Invoke(request_data, list_implementation)
List.detailed_help = base_classes.GetMultiScopeListerHelp(
'SSL certificates',
scopes=[
base_classes.ScopeType.global_scope,
base_classes.ScopeType.regional_scope
])