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,43 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 creating, reading, and manipulating SSL policies."""
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 SslPolicies(base.Group):
"""List, create, delete and update Compute Engine SSL policies."""
SslPolicies.category = base.LOAD_BALANCING_CATEGORY
SslPolicies.detailed_help = {
'DESCRIPTION': """
List, create, delete and update Compute Engine SSL policies.
For more information about SSL policies, see the
[SSL policies documentation](https://cloud.google.com/load-balancing/docs/ssl-policies-concepts).
See also: [SSL policies API](https://cloud.google.com/compute/docs/reference/rest/v1/sslPolicies).
""",
}

View File

@@ -0,0 +1,26 @@
# -*- 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.
"""Command group for managing Compute Engine ssl policy configurations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Config(base.Group):
"""Manage Compute Engine ssl policy configurations."""

View File

@@ -0,0 +1,38 @@
release_tracks: [ALPHA]
command_type: CONFIG_EXPORT
help_text:
brief: Export the configuration for a Compute Engine ssl policy.
description: |
*{command}* exports the configuration for a Compute Engine ssl policy.
Ssl policy configurations can be exported in
Kubernetes Resource Model (krm) or Terraform HCL formats. The
default format is `krm`.
Specifying `--all` allows you to export the configurations for all
ssl policies within the project.
Specifying `--path` allows you to export the configuration(s) to
a local directory.
examples: |
To export the configuration for a ssl policy, run:
$ {command} my-ssl-policy
To export the configuration for a ssl policy to a file, run:
$ {command} my-ssl-policy --path=/path/to/dir/
To export the configuration for a ssl policy in Terraform
HCL format, run:
$ {command} my-ssl-policy --resource-format=terraform
To export the configurations for all ssl policies within a
project, run:
$ {command} --all
arguments:
resource:
help_text: Ssl policy to export the configuration for.
spec: !REF googlecloudsdk.command_lib.compute.resources:ssl_policy

View File

@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 to create a new SSL policy."""
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.ssl_policies import ssl_policies_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.ssl_policies import flags
class Create(base.CreateCommand):
"""Create a new Compute Engine SSL policy.
*{command}* creates a new SSL policy.
An SSL policy specifies the server-side support for SSL features. An SSL
policy can be attached to a TargetHttpsProxy or a TargetSslProxy. This affects
connections between clients and the load balancer. SSL
policies do not affect the connection between the load balancers and the
backends. SSL policies are used by Application Load Balancers and proxy
Network Load Balancers.
"""
SSL_POLICY_ARG = flags.GetSslPolicyMultiScopeArgument()
@classmethod
def Args(cls, parser):
"""Set up arguments for this command."""
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
parser.display_info.AddCacheUpdater(flags.SslPoliciesCompleter)
cls.SSL_POLICY_ARG.AddArgument(parser, operation_type='create')
flags.GetDescriptionFlag().AddToParser(parser)
flags.GetProfileFlag(default='COMPATIBLE').AddToParser(parser)
flags.GetMinTlsVersionFlag(default='1.0').AddToParser(parser)
flags.GetCustomFeaturesFlag().AddToParser(parser)
def Run(self, args):
"""Issues the request to create a new SSL policy."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
helper = ssl_policies_utils.SslPolicyHelper(holder)
ssl_policy_ref = self.SSL_POLICY_ARG.ResolveAsResource(
args, holder.resources, default_scope=compute_scope.ScopeEnum.GLOBAL)
custom_features = args.custom_features if args.IsSpecified(
'custom_features') else []
ssl_policy_to_insert = helper.GetSslPolicyForInsert(
name=ssl_policy_ref.Name(),
description=args.description,
profile=args.profile,
min_tls_version=flags.ParseTlsVersion(args.min_tls_version),
custom_features=custom_features)
operation_ref = helper.Create(ssl_policy_ref, ssl_policy_to_insert)
return helper.WaitForOperation(ssl_policy_ref, operation_ref,
'Creating SSL policy')

View File

@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 to delete SSL policies."""
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.api_lib.compute.operations import poller
from googlecloudsdk.api_lib.compute.ssl_policies import ssl_policies_utils
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.ssl_policies import flags
class DeleteBatchPoller(poller.BatchPoller):
def __init__(self, compute_adapter, resource_service, target_refs=None):
super(DeleteBatchPoller, self).__init__(compute_adapter, resource_service,
target_refs)
def GetResult(self, operation_batch):
# For delete operations, once the operation status is DONE, there is
# nothing further to fetch.
return
class Delete(base.DeleteCommand):
"""Delete Compute Engine SSL policies.
*{command}* is used to delete one or more Compute Engine SSL policies.
SSL policies can only be deleted when no other resources (e.g.,
Target HTTPS proxies, Target SSL proxies) refer to them.
An SSL policy specifies the server-side support for SSL features. An SSL
policy can be attached to a TargetHttpsProxy or a TargetSslProxy. This affects
connections between clients and the load balancer. SSL
policies do not affect the connection between the load balancers and the
backends. SSL policies are used by Application Load Balancers and proxy
Network Load Balancers.
"""
SSL_POLICY_ARG = None
@classmethod
def Args(cls, parser):
parser.display_info.AddCacheUpdater(flags.SslPoliciesCompleter)
cls.SSL_POLICY_ARG = flags.GetSslPolicyMultiScopeArgument(plural=True)
cls.SSL_POLICY_ARG.AddArgument(parser, operation_type='delete')
def Run(self, args):
"""Issues the request to delete a SSL policy."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
helper = ssl_policies_utils.SslPolicyHelper(holder)
client = holder.client.apitools_client
refs = self.SSL_POLICY_ARG.ResolveAsResource(
args, holder.resources, default_scope=compute_scope.ScopeEnum.GLOBAL)
utils.PromptForDeletion(refs)
operation_refs = [helper.Delete(ref) for ref in refs]
wait_message = 'Deleting SSL {}'.format(
('policies' if (len(operation_refs) > 1) else 'policy'))
operation_poller = DeleteBatchPoller(holder.client, client.sslPolicies)
return waiter.WaitFor(operation_poller,
poller.OperationBatch(operation_refs), wait_message)

View File

@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 to describe SSL policies."""
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.ssl_policies import ssl_policies_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_policies import flags
class Describe(base.DescribeCommand):
"""Describe a Compute Engine ssl policy.
*{command}* is used to display all data associated with a Compute Engine
SSL policy in a project.
An SSL policy specifies the server-side support for SSL features. An SSL
policy can be attached to a TargetHttpsProxy or a TargetSslProxy. This affects
connections between clients and the load balancer. SSL
policies do not affect the connection between the load balancers and the
backends. SSL policies are used by Application Load Balancers and proxy
Network Load Balancers.
"""
SSL_POLICY_ARG = None
@classmethod
def Args(cls, parser):
cls.SSL_POLICY_ARG = flags.GetSslPolicyMultiScopeArgument()
cls.SSL_POLICY_ARG.AddArgument(parser, operation_type='describe')
def Run(self, args):
"""Issues the request to describe a SSL policy."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
helper = ssl_policies_utils.SslPolicyHelper(holder)
ref = self.SSL_POLICY_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client),
default_scope=compute_scope.ScopeEnum.GLOBAL)
return helper.Describe(ref)

View File

@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Export ssl policies command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute.ssl_policies import ssl_policies_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_policies import flags
from googlecloudsdk.command_lib.export import util as export_util
from googlecloudsdk.core.util import files
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Export(base.Command):
"""Export an SSL policy.
Exports an SSL policy's configuration to a file.
This configuration can be imported at a later time.
"""
SSL_POLICY_ARG = None
@classmethod
def GetApiVersion(cls):
"""Returns the API version based on the release track."""
if cls.ReleaseTrack() == base.ReleaseTrack.ALPHA:
return 'alpha'
elif cls.ReleaseTrack() == base.ReleaseTrack.BETA:
return 'beta'
return 'v1'
@classmethod
def GetSchemaPath(cls, for_help=False):
"""Returns the resource schema path."""
return export_util.GetSchemaPath(
'compute', cls.GetApiVersion(), 'SslPolicy', for_help=for_help)
@classmethod
def Args(cls, parser):
cls.SSL_POLICY_ARG = flags.GetSslPolicyMultiScopeArgument()
cls.SSL_POLICY_ARG.AddArgument(parser, operation_type='export')
export_util.AddExportFlags(parser, cls.GetSchemaPath(for_help=True))
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
helper = ssl_policies_utils.SslPolicyHelper(holder)
client = holder.client
ssl_policy_ref = self.SSL_POLICY_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(client),
default_scope=compute_scope.ScopeEnum.GLOBAL)
ssl_policy = helper.Describe(ssl_policy_ref)
if args.destination:
with files.FileWriter(args.destination) as stream:
export_util.Export(
message=ssl_policy, stream=stream, schema_path=self.GetSchemaPath())
else:
export_util.Export(
message=ssl_policy,
stream=sys.stdout,
schema_path=self.GetSchemaPath())

View File

@@ -0,0 +1,115 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Import ssl policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import exceptions as apitools_exceptions
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute.ssl_policies import ssl_policies_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import exceptions as compute_exceptions
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_policies import flags
from googlecloudsdk.command_lib.export import util as export_util
from googlecloudsdk.core import yaml_validator
from googlecloudsdk.core.console import console_io
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Import(base.UpdateCommand):
"""Import an SSL policy.
If the specified SSL policy already exists, it will be overwritten.
Otherwise, a new SSL policy will be created.
To edit an SSL policy you can export the SSL policy to a file,
edit its configuration, and then import the new configuration.
"""
SSL_POLICY_ARG = None
@classmethod
def GetApiVersion(cls):
"""Returns the API version based on the release track."""
if cls.ReleaseTrack() == base.ReleaseTrack.ALPHA:
return 'alpha'
elif cls.ReleaseTrack() == base.ReleaseTrack.BETA:
return 'beta'
return 'v1'
@classmethod
def GetSchemaPath(cls, for_help=False):
"""Returns the resource schema path."""
return export_util.GetSchemaPath(
'compute', cls.GetApiVersion(), 'SslPolicy', for_help=for_help)
@classmethod
def Args(cls, parser):
cls.SSL_POLICY_ARG = flags.GetSslPolicyMultiScopeArgument()
cls.SSL_POLICY_ARG.AddArgument(parser, operation_type='import')
export_util.AddImportFlags(parser, cls.GetSchemaPath(for_help=True))
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
helper = ssl_policies_utils.SslPolicyHelper(holder)
client = holder.client
ssl_policy_ref = self.SSL_POLICY_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client),
default_scope=compute_scope.ScopeEnum.GLOBAL)
data = console_io.ReadFromFileOrStdin(args.source or '-', binary=False)
try:
ssl_policy = export_util.Import(
message_type=client.messages.SslPolicy,
stream=data,
schema_path=self.GetSchemaPath())
except yaml_validator.ValidationError as e:
raise compute_exceptions.ValidationError(str(e))
# Get existing SSL policy.
try:
ssl_policy_old = helper.Describe(ssl_policy_ref)
except apitools_exceptions.HttpError as error:
if error.status_code != 404:
raise error
# SSL policy does not exist, create a new one.
operation_ref = helper.Create(ssl_policy_ref, ssl_policy)
return helper.WaitForOperation(ssl_policy_ref, operation_ref,
'Creating SSL policy')
# No change, do not send requests to server.
if ssl_policy_old == ssl_policy:
return
console_io.PromptContinue(
message=('SSL Policy [{0}] will be overwritten.').format(
ssl_policy_ref.Name()),
cancel_on_no=True)
# Populate id and fingerprint fields. These two fields are manually
# removed from the schema files.
ssl_policy.id = ssl_policy_old.id
ssl_policy.fingerprint = ssl_policy_old.fingerprint
operation_ref = helper.Patch(ssl_policy_ref, ssl_policy, False)
return helper.WaitForOperation(ssl_policy_ref, operation_ref,
'Updating SSL policy')

View File

@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 to list SSL policies."""
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_policies import flags
class List(base.ListCommand):
"""List SSL policies."""
@staticmethod
def Args(parser):
parser.display_info.AddFormat(flags.DEFAULT_AGGREGATED_LIST_FORMAT)
lister.AddMultiScopeListerFlags(parser, regional=True, global_=True)
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.regionSslPolicies,
global_service=client.apitools_client.sslPolicies,
aggregation_service=client.apitools_client.sslPolicies)
return lister.Invoke(request_data, list_implementation)
List.detailed_help = base_classes.GetGlobalRegionalListerHelp('SSL policies')

View File

@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 to list available features that can be specified in an SSL policy."""
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.ssl_policies import ssl_policies_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.core import properties
class ListAvailableFeatures(base.ListCommand):
"""List available features that can be specified in an SSL policy.
*{command}* lists available features that can be specified as part of the
list of custom features in an SSL policy.
An SSL policy specifies the server-side support for SSL features. An SSL
policy can be attached to a TargetHttpsProxy or a TargetSslProxy. This affects
connections between clients and the load balancer. SSL
policies do not affect the connection between the load balancers and the
backends. SSL policies are used by Application Load Balancers and proxy
Network Load Balancers.
"""
@classmethod
def Args(cls, parser):
"""Set up arguments for this command."""
parser.add_argument(
'--region',
help='If provided, only features for the given region are shown.')
parser.display_info.AddFormat('table([])')
def Run(self, args):
"""Issues the request to list available SSL policy features."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
helper = ssl_policies_utils.SslPolicyHelper(holder)
project = properties.VALUES.core.project.GetOrFail()
return helper.ListAvailableFeatures(
project, args.region if args.IsSpecified('region') else None)

View File

@@ -0,0 +1,103 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 to update SSL policies."""
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.ssl_policies import ssl_policies_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.ssl_policies import flags
class Update(base.UpdateCommand):
"""Update a Compute Engine SSL policy.
*{command}* is used to update SSL policies.
An SSL policy specifies the server-side support for SSL features. An SSL
policy can be attached to a TargetHttpsProxy or a TargetSslProxy. This affects
connections between clients and the load balancer. SSL
policies do not affect the connection between the load balancers and the
backends. SSL policies are used by Application Load Balancers and proxy
Network Load Balancers.
"""
SSL_POLICY_ARG = None
@classmethod
def Args(cls, parser):
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
cls.SSL_POLICY_ARG = flags.GetSslPolicyMultiScopeArgument()
cls.SSL_POLICY_ARG.AddArgument(parser, operation_type='patch')
flags.GetProfileFlag().AddToParser(parser)
flags.GetMinTlsVersionFlag().AddToParser(parser)
flags.GetCustomFeaturesFlag().AddToParser(parser)
def Run(self, args):
"""Issues the request to update a SSL policy."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
helper = ssl_policies_utils.SslPolicyHelper(holder)
ssl_policy_ref = self.SSL_POLICY_ARG.ResolveAsResource(
args, holder.resources, default_scope=compute_scope.ScopeEnum.GLOBAL)
include_custom_features, custom_features = Update._GetCustomFeatures(args)
existing_ssl_policy = helper.Describe(ssl_policy_ref)
patch_ssl_policy = helper.GetSslPolicyForPatch(
fingerprint=existing_ssl_policy.fingerprint,
profile=args.profile,
min_tls_version=flags.ParseTlsVersion(args.min_tls_version),
custom_features=custom_features)
operation_ref = helper.Patch(
ssl_policy_ref, patch_ssl_policy, include_custom_features and
not custom_features)
return helper.WaitForOperation(ssl_policy_ref, operation_ref,
'Updating SSL policy')
@staticmethod
def _GetCustomFeatures(args):
"""Returns the custom features specified on the command line.
Args:
args: The arguments passed to this command from the command line.
Returns:
A tuple. The first element in the tuple indicates whether custom
features must be included in the request or not. The second element in
the tuple specifies the list of custom features.
"""
# Clear custom_features if profile is not CUSTOM
if args.IsSpecified('profile') and args.profile != 'CUSTOM':
# pylint: disable=g-explicit-length-test
if args.IsSpecified('custom_features') and len(args.custom_features) > 0:
# If user specifies custom_features when profile is not CUSTOM, raise
# an error right away.
raise exceptions.InvalidArgumentException(
'--custom-features', 'Custom features cannot be specified '
'when using non-CUSTOM profiles.')
# When switching to non-CUSTOM profile, always clear the custom_features
# explicitly in the patch request.
return (True, [])
elif args.IsSpecified('custom_features'):
# User specified custom features will be part of the patch request.
return (True, args.custom_features)
else:
# Custom features will not be sent as part of the patch request.
return (False, [])